我们有一个.net完整框架WPF应用程序,我们已经从 .net 4.6.2 to 4.7.1 移动到csproj文件而不是packages.config中更改为 PackageReference .
在开发机器上构建似乎很好并且下载和恢复了包,但是当我们构建 Windows Server 2012 build server with Jenkins 时,nuget包似乎无法正确恢复 .
我们使用 MSBuild v15.5 和最新的 "msbuild /restore" 命令在构建时恢复包 . 注意:使用以前的方式调用"nuget restore" does work,但我们应该可以使用msbuild /restore now .
包恢复过程似乎正在查看正确的NuGet服务器,并且看起来没有错误地进行恢复(这是在Jenkins上编译的测试解决方案以隔离问题):
Restore:
Restoring packages for c:\Jenkins\workspace\Test\ConsoleApp1\ConsoleApp1.csproj...
Committing restore...
Generating MSBuild file c:\Jenkins\workspace\Test\ConsoleApp1\obj\ConsoleApp1.csproj.nuget.g.props.
Generating MSBuild file c:\Jenkins\workspace\Test\ConsoleApp1\obj\ConsoleApp1.csproj.nuget.g.targets.
Writing lock file to disk. Path: c:\Jenkins\workspace\Test\ConsoleApp1\obj\project.assets.json
Restore completed in 577.05 ms for c:\Jenkins\workspace\Test\ConsoleApp1\ConsoleApp1.csproj.
NuGet Config files used:
c:\Jenkins\workspace\Test\NuGet.Config
C:\Windows\system32\config\systemprofile\AppData\Roaming\NuGet\NuGet.Config
Feeds used:
http://devbuild/NuGetHost/nuget
https://api.nuget.org/v3/index.json
Done Building Project "c:\Jenkins\workspace\Test\ConsoleApp1.sln" (Restore target(s)).
但是当msbuild编译代码时,我们得到以下错误,看起来像NuGet还没有被下载:
CSC : error CS0006: Metadata file 'C:\Windows\system32\config\systemprofile\.nuget\packages\log4net\2.0.8\lib\net45-full\log4net.dll'
could not be found [c:\Jenkins\workspace\Test\ConsoleApp1\ConsoleApp1.csproj]
知道为什么nuget包没有恢复?
1 回答
经过几个小时的搜索和筛选NuGet发布帖子并过滤掉.net核心噪音后,我有一个修复!
根据提出的一些NuGet和msbuild msbuild问题,当在Windows Server 2012中的本地系统帐户下使用NuGet(或msbuild / restore)进行恢复时,由于32位与64位正在运行的进程,NuGet文件夹使用了isn 't accessible or it' sa不同的文件夹所以它无法将nugets下载到本地缓存文件夹 .
msbuild想要在编译时查看的这个文件夹似乎是 C:\Windows\system32\config\systemprofile.nuget\packages .
解决我们的问题是使用系统范围的环境变量 NUGET_PACKAGES 将NuGet包缓存文件夹设置为另一个可访问的文件夹,例如C:\ NugetPackageCache,例如
您还可以通过将 Build Environment->Inject environment variables to the build process->Properties Content设置为:为每个Jenkins项目设置此项:
根据这个NuGet issue post的另一个潜在解决方案是将环境变量设置为msbuild正在寻找nugets的文件夹,即
注意:环境变量优先于NuGet . 它还没有NuGet docs更新NuGet docs刚刚到mention the precedence .
Note: 要注入/设置环境变量,我们使用EnvInject Jenkins插件,如下所示: