我正在设置 Jenkins CI 服务器。我得到了正确运行的第一步:
nuget restore -NonInteractive -ConfigFile Nuget.config -Verbosity Detailed -NoCache
这工作正常,但是当我想用以下内容编译应用程序时:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe
和${WorkSpace}\src\Weather.App.csproj
它抛出此错误:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(178,5): error : The package HockeySDK.Core with version 4.1.6 could not be found in C:\WINDOWS\system32\config\systemprofile\.nuget\packages\. Run a NuGet package restore to download the package. [C:\Program Files (x86)\Jenkins\workspace\MyApp\Weather\Weather.App.csproj]
如果我在 VS2017 本地项目中运行相同的命令,一切都会顺利进行。但是 Jenkins 服务器(在我的同一台机器上)没有正确构建它。
有什么想法吗?谢谢
最佳答案
这就是技巧。
将 nuget.exe 放在构建服务器上的某个位置。
确保 nuget.exe 位于 PATH 环境变量中。
重新启动 Jenkins,以便它获取更新的 PATH 环境变量
将 NuGet 升级到最新版本
nuget.exe update --self
在 Jenkins 作业中,针对 MSBUILD 调用重建将无法成功恢复 nuget 包
在 MSBUILD Clean 之后、MSBUILD Rebuild 之前添加 Windows 批处理步骤,如下所示:
nuget restore <your_solution_file>.sln
解决方案文件的路径是相对于工作区的。
这将按照您的预期创建包目录。
关于Jenkins 找不到 nuget 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43276107/