1

我有以下代码:

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 一起使用。

4

1 回答 1

0

在 Project xml 标记中将 Toolsversion 设置为 2.0。

于 2012-05-27T10:52:54.160 回答