使用 Nant 构建 .NET 4 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1215731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Building .NET 4 projects with Nant
提问by plaureano
How do I get nant to build projects that target the .NET 4.0 Framework?
我如何才能构建面向 .NET 4.0 Framework 的项目?
回答by user206890
2010 April 15, ... Update to above correct answer from Eugene, after .net 4 and vs2010 was released.
2010 年 4 月 15 日,...在 .net 4 和 vs2010 发布后,更新到 Eugene 的上述正确答案。
I downloaded vs2010 and .net 4 runtime. The production version seems to be v4.30319 ie (C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319)
我下载了 vs2010 和 .net 4 运行时。生产版本好像是 v4.30319 ie (C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319)
After reviewing http://paigecsharp.blogspot.com/2009/08/nant-net-framework-40-configuration.html, ... I pasted in the text and changed all text from v4.0.20506 to v4.30319 an added text to NAnt.exe.config.
在查看http://paigecsharp.blogspot.com/2009/08/nant-net-framework-40-configuration.html 后,......我粘贴了文本并将所有文本从 v4.0.20506 更改为 v4.30319 并添加文本到 NAnt.exe.config。
I then updated my nant script to
然后我将我的 nant 脚本更新为
<property name="nant.settings.currentframework" value="net-4.0" />,
this so my project nant script uses the .net 4 compiler
这使我的项目 nant 脚本使用 .net 4 编译器
And this got me a nant build with .net 4 binary ....
这让我用 .net 4 二进制文件构建了一个 nant ......
Update 2010-06-14: The above was answered with nant-0.85, I upgraded to nant-0.90 and had to add vendor="Microsoft"to framework attribute that is added to nants config. Also, it looks like nant0.9 finds the .net libraries differently, as I had to add something like this to my nant build.xml ...
2010 年 6 月 14 日更新:上面的回答是 nant-0.85,我升级到 nant-0.90 并且不得不添加vendor="Microsoft"到添加到 nants 配置中的框架属性。此外,看起来 nant0.9 以不同的方式找到 .net 库,因为我不得不将这样的内容添加到我的 nant build.xml ...
<property name="framework-get-assembly-directory" value="${framework::get-assembly-directory('net-4.0')}" />
<property name="dotNetReferenceAssemblyPath" value="${framework-get-assembly-directory}\" />
and
和
<include name="${dotNetReferenceAssemblyPath}System.ComponentModel.DataAnnotations.dll" />
回答by Mitch Wheat
If you want to use nant to build projects targeting .NET 4.0 you'll have to modify NAnt.exe.configand add the net-4.0 target framework and add a <supportedRuntime ... />line to the <startup> section.
如果要使用 nant 构建面向 .NET 4.0 的项目,则必须修改NAnt.exe.config并添加 net-4.0 目标框架,并<supportedRuntime ... />在<startup> 部分添加一行。
回答by Eugene Petrenko
http://paigecsharp.blogspot.com/2009/08/nant-net-framework-40-configuration.htmlis a full code for .config file for NAnt.
http://paigecsharp.blogspot.com/2009/08/nant-net-framework-40-configuration.html是 NAnt .config 文件的完整代码。
回答by Babak Naffas
This is pretty similar to these questions/problems:
这与这些问题/问题非常相似:
<msbuild> task or msbuild.exe with NAnt?
<msbuild> 任务或 msbuild.exe 与 NAnt?
Another option would be to directly call MSBuild from an block.
另一种选择是直接从块中调用 MSBuild。
<property name="MSBuildPath" value="C:\WINDOWS\Microsoft.NET\Framework\v4.0\MSBuild.exe" />
<target name="build">
<exec program="${MSBuildPath}">
<arg line='"${SolutionFile}"' />
<arg line="/property:Configuration=${SolutionConfiguration}" />
<arg value="/target:Rebuild" />
<arg value="/verbosity:normal" />
<arg value="/nologo" />
<arg line='/logger:"C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll"'/>
</exec>
</target>
回答by Diego C.
I used all of the answers above and still ran into some weird build errors: "error MSB6006: "AL.exe" exited with code 128". Error not helpful at all. I did some googling and came up with few answers. Here are the links: msdn helpand asp.net forums
我使用了上面的所有答案,但仍然遇到了一些奇怪的构建错误:“错误 MSB6006:“AL.exe”以代码 128 退出。错误根本没有帮助。我做了一些谷歌搜索并想出了几个答案。以下是链接:msdn 帮助和asp.net 论坛
I wrestled with that error for a full day, studying the "detailed" and "diagnostic" logs, but all it did is pointing me to the assembly that failed building. No specific error. I could not even duplicate it on my local box. Finally, I decided to try the suggestion about resource files naming convention in the second link (asp.net forums) and... alleluia! my build started working. I don't know what's up with the build failing because of the resource name, still working on that, but my immediate goal was to get the build working.
我一整天都在与那个错误搏斗,研究“详细”和“诊断”日志,但它所做的只是将我指向构建失败的程序集。没有具体错误。我什至无法在本地盒子上复制它。最后,我决定尝试在第二个链接(asp.net 论坛)中关于资源文件命名约定的建议和... alleluia!我的构建开始工作。我不知道由于资源名称而导致构建失败是怎么回事,仍在努力解决这个问题,但我的直接目标是使构建正常工作。
Hope this helps someone else out there.
希望这可以帮助其他人。
回答by Jirka Hanika
回答by radkan
I had similar issue for 4.5, this solved my issue:
我对 4.5 有类似的问题,这解决了我的问题:
http://www.donnfelker.com/nant-sdkinstallroot-has-not-been-set/
http://www.donnfelker.com/nant-sdkinstallroot-has-not-been-set/
I have a 64 bit machine but .net is installed as 32 bit. The sdkInstallRoot is not able to find the correct path. I checked in my registry editor to find the correct path and replaced the entry in nant.exe.config.
我有一台 64 位机器,但 .net 安装为 32 位。sdkInstallRoot 无法找到正确的路径。我检查了我的注册表编辑器以找到正确的路径并替换了 nant.exe.config 中的条目。
I replaced:
我替换了:
<locatesdk property="sdkInstallRoot" minwinsdkver="v7.0A" minnetfxver="4.0" maxnetfxver="4.0.99999" failonerror="false" />
with this:
有了这个:
<readregistry
property="sdkInstallRoot"
key="SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools\InstallationFolder"
hive="LocalMachine"
failonerror="false" />
回答by Julien Roncaglia
Just to put the info there so i could find it again, to build C++ projects without modifying the PATH environement variable and creating LIB/LIBPATH/INCLUDE variables or running nant from vsvars32, something like that is needed in Nant config file :
只是为了将信息放在那里以便我可以再次找到它,在不修改 PATH 环境变量和创建 LIB/LIBPATH/INCLUDE 变量或从 vsvars32 运行 nant 的情况下构建 C++ 项目,在 Nant 配置文件中需要类似的东西:
<project>
<readregistry
property="WindowsSdkDir"
key="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\InstallationFolder"
hive="LocalMachine"
failonerror="true" />
<readregistry
property="installRoot"
key="SOFTWARE\Microsoft\.NETFramework\InstallRoot"
hive="LocalMachine" />
<readregistry
property="sdkInstallRoot"
key="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools\InstallationFolder"
hive="LocalMachine"
failonerror="false" />
<readregistry
property="vs10Win32Tools"
key="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-Win32Tools\InstallationFolder"
hive="LocalMachine"
failonerror="false" />
<readregistry
property="vcInstallDir"
key="SOFTWARE\Microsoft\VisualStudio.0\Setup\VC\ProductDir"
hive="LocalMachine"
failonerror="true" />
<readregistry
property="vs10dbghelp"
key="SOFTWARE\Microsoft\VisualStudio.0\Setup\Dbghelp_path"
hive="LocalMachine"
failonerror="true" />
<setenv name="PATH" value="${path::combine(vcInstallDir, 'bin')};${vs10dbghelp};${sdkInstallRoot};${vs10Win32Tools};${environment::get-variable('PATH')};" />
<setenv name="INCLUDE" value="${path::combine(WindowsSdkDir, 'include')};${path::combine(vcInstallDir, 'atlmfc/include')};${path::combine(vcInstallDir, 'include')};${environment::get-variable('INCLUDE')}" />
<setenv name="LIB" value="${path::combine(WindowsSdkDir, 'lib')};${path::combine(vcInstallDir, 'atlmfc/lib')};${path::combine(vcInstallDir, 'lib')};${environment::get-variable('LIB')}" />
<setenv name="LIBPATH" value="${path::combine(installRoot, 'v4.0.30319')};${path::combine(installRoot, 'v3.5')};${path::combine(WindowsSdkDir, 'lib')};${path::combine(vcInstallDir, 'atlmfc/lib')};${path::combine(vcInstallDir, 'lib')};${environment::get-variable('LIBPATH')}" />
</project>
The registry path are the one of VS2010 as the corresponding SDK is taking it's time...
注册表路径是 VS2010 之一,因为相应的 SDK 正在花时间......

