我们的主要产品组合中有超过20个解决方案(超过880个项目),我们拥有一套复杂的构建脚本,它们运行良好,但我们正在尝试在msbuild管道内自动恢复nuget程序包。目前,这是通过手动调用nuget来恢复包完成的。
根据https://learn.microsoft.com/en-us/nuget/schema/msbuild-targets,我应该能够运行此命令并运行还原:
然而,当我添加
如果我省略
根据https://learn.microsoft.com/en-us/nuget/schema/msbuild-targets,我应该能够运行此命令并运行还原:
# works
& $script:msBuildPath $solutionName /t:build /v:q /clp:ErrorsOnly /nologo /p:...
# doesn't works
& $script:msBuildPath $solutionName /t:restore,build /v:q /clp:ErrorsOnly /nologo /p:...
然而,当我添加
restore
到上面的代码时,它会抛出一个错误。MSB4057: The target "restore" does not exist in the project
我应该从哪里开始研究以理解为什么它找不到这个目标? 我们主要使用的是VS 2015和.NET 4.6.2,因此目前无法使用任何特定于VS2017的选项。
如果我省略
/v:q
和/clp:ErrorsOnly
标志,我会得到这个(稍微经过处理的解决方案/项目名称和路径)。PS Z:\git\company> build c
building Common\Common.sln
Build started 11/15/2017 11:08:54 AM.
1>Project "Z:\git\company\Common\Common.sln" on node 1 (restore;build target(s)).
1>ValidateSolutionConfiguration:
Building solution configuration "DEBUG|Any CPU".
1>Z:\git\company\Common\Common.sln.metaproj : error MSB4057: The target "restore" does not exist in the project. [Z:\git\company\Common\Common.sln]
1>Done Building Project "Z:\git\company\Common\Common.sln" (restore;build target(s)) -- FAILED.
Build FAILED.
"Z:\git\company\Common\Common.sln" (restore;build target) (1) ->
Z:\git\company\Common\Common.sln.metaproj : error MSB4057: The target "restore" does not exist in the project. [Z:\git\company\Common\Common.sln]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.03
runBuildPackage : ... failed
At Z:\git\company\psincludes\buildFunctions.ps1:11 char:5
+ runBuildPackage "Common\Common.sln"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,runBuildPackage
msbuild failed
At Z:\git\company\psincludes\buildInternals.ps1:63 char:21
+ throw "msbuild failed";
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (msbuild failed:String) [], RuntimeException
+ FullyQualifiedErrorId : msbuild failed
我知道这其中有些是我们内部工具的问题,只是我觉得没有必要遮掩这一点。
根据“互联网”的说法,这应该只是构建过程中的“免费”部分,我不确定我们在这里的csproj文件中缺少了什么。
nuget restore
吗?如果你觉得这很明显,我很抱歉,但我还是有点困惑,所以想确保我没问题。再次感谢! - jcolebrandmsbuild -t:build -restore
命令,参见 Restoring and building with one MSBuild command。 - Dave Andersonmsbuild -restore -p:RestorePackagesConfig=true
。 (如前面评论中链接的文档页面中所述。)如果需要,这些参数可以添加到名为“Directory.Build.rsp”的文件中-请参见:https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-response-files - Otto G