MSBuild 调用错误版本的 csc.exe

发布于 2024-09-15 00:47:54 字数 272 浏览 3 评论 0 原文

我正在使用 team city 调用 nant 脚本,目前这个 nant 脚本非常简单,仅在解决方案中的单个项目上调用 msbuild 任务。

构建失败,看起来正在调用 msbuild 3.5,但它错误地从 .net 2.0 文件夹中调用 csc.exe。由于我们使用 .net 3.5 语言功能,因此编译失败。

查看 csproj 文件,ToolsVersion 和 TargetFrameworkVersion 均设置为使用 3.5。是什么导致 msbuild 选择错误版本的 csc.exe?

I am using team city to call a nant script, currently this nant script is very simplistic and only calls an msbuild task on a single project in the solution.

The build is failing, it looks like msbuild 3.5 is being called, but it is incorrectly calling the csc.exe from the .net 2.0 folder. Since we are using .net 3.5 language features the compilation fails.

Looking at the csproj file, both the ToolsVersion and TargetFrameworkVersion are both set to use 3.5. What would be causing msbuild to pick the wrong version of csc.exe?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花开雨落又逢春i 2024-09-22 00:48:02

您的路径中是否直接有 2.0 版本的 csc?

从 Visual Studio 2008 命令提示符运行 msbuild 时会发生什么?

Do you have the 2.0 version of csc directly in your path, perhaps?

What happens when you run msbuild from a Visual Studio 2008 Command Prompt?

许一世地老天荒 2024-09-22 00:48:02

您可以通过声明直接指出要在 nant 脚本中使用哪个 msbuild:

<!-- Initial path to use MSBuild from .NET Framework 3.5 -->
<property name="MSBuildApp" value="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" />

然后通过 msbuild 执行构建:

<exec failonerror="true" program="${MSBuildApp}" verbose="true">
        <arg value="${SlnDir}\${SlnFile}" />
        <arg value="/t:Rebuild" />
        <arg value="/p:Configuration=${SlnConfig}" />
    </exec>

或者您可以在运行 NANT 脚本时指向正确的 .NET 框架版本:

nant CreateYouProjectTask -t:net-3.5 -buildfile:BuildYourProject 。建造

You can directly point which msbuild you want to use in nant script by declaring:

<!-- Initial path to use MSBuild from .NET Framework 3.5 -->
<property name="MSBuildApp" value="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" />

And then execute build via msbuild:

<exec failonerror="true" program="${MSBuildApp}" verbose="true">
        <arg value="${SlnDir}\${SlnFile}" />
        <arg value="/t:Rebuild" />
        <arg value="/p:Configuration=${SlnConfig}" />
    </exec>

Or you can point to proper .NET framework version when running NANT script:

nant CreateYouProjectTask -t:net-3.5 -buildfile:BuildYourProject.build

风铃鹿 2024-09-22 00:48:01

MSBuild 使用任务、目标和工具的工具集来构建应用程序。通常,MSBuild 工具集包括 microsoft.common.tasks 文件、microsoft.common.targets 文件以及 csc.exe 和 vbc.exe 等编译器。为了确保 MSBuild 调用正确的 C# 编译器 (csc.exe),请在项目文件中 Project 元素的 ToolsVersion 属性中指定工具集。
以下示例指定应使用 MSBuild 4.0 工具集生成项目。

有关 ToolsVersion 属性的更多信息可以在此处找到:
http://msdn.microsoft.com/en-us/library/78f4aasd.aspx

MSBuild uses a Toolset of tasks, targets, and tools to build an application. Typically, a MSBuild Toolset includes a microsoft.common.tasks file, a microsoft.common.targets file, and compilers such as csc.exe and vbc.exe. To ensure MSBuild invokes the correct C# compiler (csc.exe), specify the Toolset in the ToolsVersion attribute on the Project element in the project file.
The following example specifies that the project should be built by using the MSBuild 4.0 Toolset.

<Project ToolsVersion="4.0" ... </Project>

More information pertaining to the ToolsVersion attribute can be found here:
http://msdn.microsoft.com/en-us/library/78f4aasd.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文