Jenkins不使用新的MSBuild还原目标还原NuGet软件包 [英] Jenkins not restoring NuGet packages with new MSBuild restore target

查看:524
本文介绍了Jenkins不使用新的MSBuild还原目标还原NuGet软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个.net完整框架WPF应用程序,该应用程序已从 .net 4.6.2迁移到4.7.1 ,并在csproj文件中更改为 PackageReference 而不是packages.config.

We have a .net full framework WPF application that we've moved from .net 4.6.2 to 4.7.1 along with changing to PackageReference in the csproj file instead of packages.config.

在开发计算机上进行构建似乎很好,可以下载并还原软件包,但是当我们使用Jenkins在 Windows Server 2012构建服务器上进行构建时,似乎无法还原nuget软件包.正确.

Building on the development machines appears to be fine and packages are downloaded and restored, but when we build on our Windows Server 2012 build server with Jenkins, the nuget packages don't seem to be restored correctly.

我们正在将 MSBuild v15.5 与最新的"msbuild/restore" 命令配合使用,以在构建时还原软件包. 注意:使用以前的方式调用"nuget restore"是可行的,但我们应该能够使用 msbuild/立即恢复.

We're using MSBuild v15.5 with the latest "msbuild /restore" command to restore packages at build time. Note: Using the previous way of calling "nuget restore" does work, but we should be able to use msbuild /restore now.

程序包还原过程似乎正在寻找正确的NuGet服务器,并且似乎在进行还原时没有错误(这是在Jenkins上编译的测试解决方案,用于隔离问题):

The package restore process appears to be looking at the correct NuGet servers and appears to go through the restore without errors (this is a test solution compiled on Jenkins to isolate the issue):

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:

But when msbuild comes to compile the code we get the following errors which looks like the NuGet hasn't been downloaded:

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包?

Any idea why the nuget packages aren't getting restored?

推荐答案

经过数小时的搜索和筛选NuGet问题帖子并过滤掉.net核心噪音后,我有了解决方法!

After many hours of searching and sifting through NuGet issue posts and filtering out the .net core noise, I have a fix!

根据某些 NuGet 和msbuild

According to some NuGet and msbuild msbuild issues raised, when restoring with NuGet (or msbuild /restore) under the local system account in Windows Server 2012, the folder NuGet uses isn't accessible or it's a different folder due to 32 bit vs 64 bit process that is running so it can't download nugets to that local cache folder.

msbuild要在编译时查看的文件夹似乎是 C:\ Windows \ system32 \ config \ systemprofile \ .nuget \ packages .

This folder that msbuild wants to look in at compile time seems to be C:\Windows\system32\config\systemprofile\.nuget\packages.

我们的解决方案是使用系统范围环境变量 NUGET_PACKAGES 将NuGet程序包缓存文件夹设置为其他可访问的文件夹,例如C:\ NugetPackageCache 例如

The solve for us was to set the NuGet package cache folder using the System wide environment variable NUGET_PACKAGES to a different, accessible folder such as C:\NugetPackageCache eg

NUGET_PACKAGES=C:\NugetPackageCache

您还可以通过将 Build Environment-> Inject环境变量设置为构建过程-> Properties Content to

You can also set this per Jenkins project by setting the Build Environment->Inject environment variables to the build process->Properties Content to:

NUGET_PACKAGES=C:/NugetPackageCache

根据此NuGet问题发布的另一种可能的解决方法是将环境变量设置为msbuild正在查找nuget的文件夹,即

Another potential solve according to this NuGet issue post is to set the environment variable to the folder that msbuild is looking for the nugets ie

NUGET_PACKAGES=C:\Windows\system32\config\systemprofile\.nuget\packages

注意:环境变量优先于NuGet.看来他们没有更新提及优先级.

Note: The environment variables take precedence with NuGet. It doesn't look like they've updated the NuGet docs just yet to mention the precedence.

注意:要注入/设置环境变量,我们使用

Note: To inject/set the environment variables we are using the EnvInject Jenkins plugin which looks like this:

这篇关于Jenkins不使用新的MSBuild还原目标还原NuGet软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆