Nant脚本无法生成msbuild

时间:2011-11-02 22:50:30

标签: msbuild nant

我被要求将VB.NET解决方案从Windows Server 2003,Visual Studio 2005,32位,.NET 2.0迁移到Windows Server 2008,Visual Studio 2008,64位,.NET 4.0。我有解决方案编译并在Visual Studio中正常工作。下一步是让Nant脚本工作,这样它就像以前那样检查,编译和测试。

但是,当Nant脚本进入msbuild步骤时,它会立即失败并显示“... Microsoft.NET/Framework64/v4.0.30319/msbuild无法启动。访问被拒绝”

我尝试使用相同的输入直接运行msbuild,它已经过了这一点。我的问题是:我可以在我的nant .build中添加一些内容来让它以管理员身份运行它的任务吗?

我的.build文件:

<?xml version="1.0"?>
...
<credential domain="xxxx" username="xxxxx" password="xxxxxx" id="55" />
<property name="debug" value="true" overwrite="false" />
<property name="configuration" value="debug" overwrite="false" />
<property name="solution.file" value="solution.sln" overwrite="false" />
...
<target name="msbuild" description="Build the whole solution">
<exec program="C:/Windows/Microsoft.NET/Framework64/v4.0.30319/msbuild" workingdir="D:/BuildTest" commandline='"${solution.file}" /v:q /nologo /p:Configuration=${configuration}' />
</target>
...

2 个答案:

答案 0 :(得分:2)

或者

如果msbuild行

,你可以把“.exe”放在最后
<exec program="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe">

答案 1 :(得分:1)

我在32位机器上遇到同样的问题。对我来说,解决方法是使用nantcontrib的msbuild任务。任何人都明白为什么这样有效?

在64位计算机上,exec-method也可以正常工作。我必须指向正确的Framework文件夹中的msbuild.exe。

<target name="compile" description="Compiles the .Net solution">

    <!-- this works -->
    <msbuild project="${src.root.dir}\${src.solution}"
                     verbosity="Normal">
        <arg value="/p:Configuration=${msbuild.configuration}" />
        <arg value="/p:Platform=Any CPU" />
        <arg value="/t:Rebuild" />
        <arg value="/nologo" />
    </msbuild>

    <!-- access is denied -->
    <exec program="${msbuild.path}"
          workingdir="${src.root.dir}" 
          basedir="${src.root.dir}"
          commandline="${src.root.dir}\${src.solution}${src.solution}"
          failonerror="true" >
        <arg value="/p:Platform=Any CPU" />
        <arg value="/p:Configuration=${msbuild.configuration}" />
        <arg value="/t:Rebuild" />
        <arg value="/v:${msbuild.verbosity}" />
    </exec>
</target>