MSBuild忽略已安装的nugets(NuGet 3),失败

时间:2016-10-14 14:25:41

标签: c# .net msbuild nuget

我有一个项目,在project.json文件中列出了一个NuGet依赖项。 在VS2015中构建工作正常,在VS2015的同一台计算机上通过MSBuild也能正常工作。 (即使是从远程git仓库克隆的另一个完全不相关的目录。)

但是在另一台计算机(相同的MSBuild版本)上,它失败并出现引用错误。我读完了输出,发现MSBuild在两个实例中没有启动相同的csc.exe命令:

工作实例: C:\Program Files (x86)\MSBuild\14.0\bin\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+ /reference:C:\Users\tm\.nuget\packages\log4net\2.0.5\lib\net45-full\log4net.dll/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\ImportCommon.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /target:library /utf8output EcritureCSV.cs LectureCSV.cs Properties\AssemblyInfo.cs "C:\Users\tm\AppData\Local\Temp\.NETFramework,Version=v4.5.AssemblyAttributes.cs"

实例失败: C:\Program Files (x86)\MSBuild\14.0\bin\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\ImportCommon.dll /subsystemversion:6.00 /target:library /utf8output EcritureCSV.cs LectureCSV.cs Properties\AssemblyInfo.cs "C:\Users\maurin\AppData\Local\Temp\4\.NETFramework,Version=v4.5.AssemblyAttributes.cs"

在第二个实例中,当文件存在时,MSBuild不会将参数/reference:C:\Users\tm\.nuget\packages\log4net\2.0.5\lib\net45-full\log4net.dll传递给csc.exe,因为之前已经使用nuget restore下载了该文件。

我不知道MSBuild为什么不添加这个参数。 任何见解将不胜感激。

1 个答案:

答案 0 :(得分:0)

msbuild无法恢复nuget包。您必须运行nuget.exe restore

Visual Studio处理此问题,因此在Visual Studio计算机上构建将与msbuild一起使用,因为使用VS的构建已经恢复了它。