简体   繁体   English

使用Nant构建.NET 4项目

[英]Building .NET 4 projects with Nant

我如何才能构建面向.NET 4.0 Framework的项目?

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. 我下载了vs2010和.net 4运行时。 The production version seems to be v4.30319 ie (C:\\WINDOWS\\Microsoft.NET\\Framework\\v4.0.30319) 生产版本似乎是v4.30319即(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二进制文件......

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. 更新2010-06-14:以上用nant-0.85回答,我升级到nant-0.90并且必须将vendor="Microsoft"添加到添加到nants config的framework属性中。 Also, it looks like nant0.9 finds the .net libraries differently, as I had to add something like this to my nant build.xml ... 此外,看起来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" />

如果要使用nant构建面向.NET 4.0的项目,则必须修改NAnt.exe.config并添加net-4.0目标框架并将<supportedRuntime ... />行添加到<startup >部分。

This is pretty similar to these questions/problems: 这非常类似于这些问题/问题:

<msbuild> task or msbuild.exe with NAnt? <msbuild>任务或msntild.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>

NAnt 0.86 and later runs out of the box. NAnt 0.86及更高版本开箱即用。 As of writing this, I am using 0.91. 写这篇文章时,我使用的是0.91。

When downloading from the net, remember to " unblock " the zip file (reset security zone) before unpacking. 从网上下载时,请记得在解压缩之前“ 解锁 ”zip文件(重置安全区域)。

I used all of the answers above and still ran into some weird build errors: "error MSB6006: "AL.exe" exited with code 128". 我使用了上面的所有答案,仍然遇到了一些奇怪的构建错误:“错误MSB6006:”AL.exe“退出代码128”。 Error not helpful at all. 错误没有任何帮助。 I did some googling and came up with few answers. 我做了一些谷歌搜索,并得出了一些答案。 Here are the links: msdn help and asp.net forums 以下是链接: msdn helpasp.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! 最后,我决定在第二个链接( asp.net论坛 )和... 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. 由于资源名称,我不知道构建失败了什么,仍然在努力,但我的直接目标是让构建工作。

Hope this helps someone else out there. 希望这有助于其他人。

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 : 只是把信息放在那里,以便我可以再次找到它,构建C ++项目而不修改PATH环境变量并创建LIB / LIBPATH / INCLUDE变量或从vsvars32运行nant,在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\10.0\Setup\VC\ProductDir"
        hive="LocalMachine"
        failonerror="true" />
    <readregistry
        property="vs10dbghelp"
        key="SOFTWARE\Microsoft\VisualStudio\10.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正在花时间......

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. 我有一台64位机器,但.net安装为32位。 The sdkInstallRoot is not able to find the correct path. sdkInstallRoot无法找到正确的路径。 I checked in my registry editor to find the correct path and replaced the entry in nant.exe.config. 我检查了我的注册表编辑器以找到正确的路径并替换了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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM