我有以下代码:
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace MyTasks
{
public class SimpleTask : Task
{
public override bool Execute()
{
return true;
}
}
}
我有以下MSBuild脚本:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<MakeDir Directories= "bin"/>
<Csc Sources="SimpleTask.cs" References="Microsoft.Build.Utilities,Microsoft.Build.Framework" TargetType="library"
OutputAssembly=".\bin\SimpleTask.dll" />
</Target>
</Project>
它失败并显示以下消息:
broersa@build01:~/task$ xbuild SimpleTask.proj
XBuild Engine Version 2.10.8.1
Mono, Version 2.10.8.1
Copyright (C) Marek Sieradzki 2005-2008, Novell 2008-2011.
Build started 5/27/2012 12:08:32 PM.
__________________________________________________
Project "/home/broersa/task/SimpleTask.proj" (default target(s)):
Target Build:
Tool /usr/bin/dmcs execution started with arguments: /out:./bin/SimpleTask.dll SimpleTask.cs /target:library /reference:Microsoft.Build.Utilities,Microsoft.Build.Framework
: error CS0006: Metadata file `Microsoft.Build.Utilities' could not be found
Task "Csc" execution -- FAILED
Done building target "Build" in project "/home/broersa/task/SimpleTask.proj".-- FAILED
Done building project "/home/broersa/task/SimpleTask.proj".-- FAILED
Build FAILED.
Errors:
/home/broersa/task/SimpleTask.proj (default targets) ->
(Build target) ->
: error CS0006: Metadata file `Microsoft.Build.Utilities' could not be found
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.4351060
Xbuild调用dmcs编译器,但Microsoft.Build.Utilites程序集引用了.net 2.0程序集。当我用gmcs(2.0)手工编译时,它可以工作。但我无法使用xbuild。
答案 0 :(得分:0)
在Project xml标记中将Toolsversion设置为2.0。