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

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

问题描述

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

在开发机器上构建似乎没问题,并且包已下载并恢复,但是当我们在 Windows Server 2012 构建服务器上使用 Jenkins 构建时,nuget 包似乎没有恢复正确.

我们使用 MSBuild v15.5 和最新的 "msbuild/restore" 命令在构建时恢复包.注意:使用之前调用nuget restore"的方式确实有效,但我们应该可以使用 msbuild/restore now.

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

恢复:正在恢复 c:JenkinsworkspaceTestConsoleApp1ConsoleApp1.csproj 的包...提交还原...生成 MSBuild 文件 c:JenkinsworkspaceTestConsoleApp1objConsoleApp1.csproj.nuget.g.props.生成 MSBuild 文件 c:JenkinsworkspaceTestConsoleApp1objConsoleApp1.csproj.nuget.g.targets.将锁定文件写入磁盘.路径:c:JenkinsworkspaceTestConsoleApp1objproject.assets.jsonc:JenkinsworkspaceTestConsoleApp1ConsoleApp1.csproj 的恢复在 577.05 毫秒内完成.使用的 NuGet 配置文件:c:JenkinsworkspaceTestNuGet.ConfigC:Windowssystem32configsystemprofileAppDataRoamingNuGetNuGet.Config使用的饲料:http://devbuild/NuGetHost/nugethttps://api.nuget.org/v3/index.json完成构建项目c:JenkinsworkspaceTestConsoleApp1.sln"(恢复目标).

但是当 msbuild 来编译代码时,我们收到以下错误,看起来像 NuGet 尚未下载:

CSC:错误 CS0006:元数据文件 'C:Windowssystem32configsystemprofile.nugetpackageslog4net2.0.8lib
et45-fulllog4net.dll'找不到 [c:JenkinsworkspaceTestConsoleApp1ConsoleApp1.csproj]

知道为什么 nuget 包没有恢复吗?

解决方案

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

根据一些

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.

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.

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.

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:JenkinsworkspaceTestConsoleApp1ConsoleApp1.csproj...
  Committing restore...
  Generating MSBuild file c:JenkinsworkspaceTestConsoleApp1objConsoleApp1.csproj.nuget.g.props.
  Generating MSBuild file c:JenkinsworkspaceTestConsoleApp1objConsoleApp1.csproj.nuget.g.targets.
  Writing lock file to disk. Path: c:JenkinsworkspaceTestConsoleApp1objproject.assets.json
  Restore completed in 577.05 ms for c:JenkinsworkspaceTestConsoleApp1ConsoleApp1.csproj.

  NuGet Config files used:
      c:JenkinsworkspaceTestNuGet.Config
      C:Windowssystem32configsystemprofileAppDataRoamingNuGetNuGet.Config

  Feeds used:
      http://devbuild/NuGetHost/nuget
      https://api.nuget.org/v3/index.json
Done Building Project "c:JenkinsworkspaceTestConsoleApp1.sln" (Restore target(s)).

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:Windowssystem32configsystemprofile.nugetpackageslog4net2.0.8lib
et45-fulllog4net.dll' 
could not be found [c:JenkinsworkspaceTestConsoleApp1ConsoleApp1.csproj]

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

解决方案

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

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.

This folder that msbuild wants to look in at compile time seems to be C:Windowssystem32configsystemprofile.nugetpackages.

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

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

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:Windowssystem32configsystemprofile.nugetpackages

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天全站免登陆