简体   繁体   English

让 Jenkins 了解自定义 NuGet 包源

[英]Make Jenkins aware of custom NuGet Package Source

I've got a little issue regarding Jenkins and NuGet package restore.关于 Jenkins 和 NuGet 包还原,我遇到了一些小问题。

What I'm trying to do is build solutions on jenkins (which works perfectly fine).我正在尝试做的是在 jenkins 上构建解决方案(效果很好)。 I have enabled package restore for the solution, which generates the .nuget-folder containing NuGet.exe, NuGet.Config and NuGet.targets.我为解决方案启用了包还原,它会生成包含 NuGet.exe、NuGet.Config 和 NuGet.targets 的 .nuget 文件夹。

On Jenkins, I am pulblishing some projects as NuGet-packages in a private package source on our server.在 Jenkins 上,我将一些项目作为 NuGet 包发布在我们服务器上的私有包源中。 I am using those packages in other projects, which should be build on jenkins themselves.我在其他项目中使用这些包,这些包应该建立在 jenkins 本身上。

VS knows about the private package source, it's configured in the global NuGet.Config-file (the one under AppData) and it is not disabled (by default). VS 知道私有包源,它在全局 NuGet.Config 文件(AppData 下的那个)中配置,并且没有被禁用(默认情况下)。

Now, when I try to build a solution which needs a package from the private package source, the build fails, because jenkins doesn't know about it, and is therefore commiting an empty -source<\/code> -parameter when restoring packages which is not beeing replaced as jenkins doesn't know about the custom source.现在,当我尝试构建一个需要来自私有包源的包的解决方案时,构建失败,因为 jenkins 不知道它,因此在恢复未被替换的包时提交了一个空的-source<\/code> -parameter因为詹金斯不知道自定义来源。

What I've tried so far<\/strong>到目前为止我尝试过的<\/strong>

  1. I already know that adding the private source to the solutions NuGet.Config- or NuGet.Targets-file's Package-Source<\/code> would solve the problem, but that would mean, i would have to do so for every solution I want to build using Jenkins.我已经知道将私有源添加到解决方案 NuGet.Config- 或 NuGet.Targets-file 的Package-Source<\/code>可以解决问题,但这意味着,对于我想使用 Jenkins 构建的每个解决方案,我都必须这样做。

    <\/li>

  2. I have also played around a bit with the config-files in AppData and ProgramData by adding the source in to the package-source tags in the files and even making it the active-source, but that didn't help either我还通过将源添加到文件中的 package-source 标记甚至使其成为活动源,来使用 AppData 和 ProgramData 中的配置文件,但这也无济于事

    <\/li>

  3. of cource, commiting the packages would be a workaround, but thats not the desired outcome, as we'd like to ignore the packages in scm.当然,提交包是一种解决方法,但这不是预期的结果,因为我们想忽略 scm 中的包。

    <\/li><\/ol>

    Basically, i'd like to know if there is a way to make Jenkins constantly aware of the private package source, or to manipulate the NuGet-installations on the developers maschines, so that they generate a NuGet.targets<\/code> -file which contains the private package-source.基本上,我想知道是否有办法让 Jenkins 不断了解私有包源,或者操纵开发人员机器上的 NuGet 安装,以便他们生成包含私有包的NuGet.targets<\/code>文件包源。 An other possible fix would be a parameter for msbuild, which I'm not aware of.另一个可能的修复方法是 msbuild 的参数,我不知道。

    Any help is greatly appreciated!任何帮助是极大的赞赏!

    "

To sum up (and extend) my comments: 总结(并扩展)我的意见:

Nuget package restore via msbuild is deprecated in current versions of Nuget (2.7 and higher) 在当前版本的Nuget(2.7及更高版本)中不推荐通过msbuild进行Nuget包恢复

We use a batch step in Jenkins 我们在Jenkins中使用批处理步骤

nuget.exe restore SOLUTIONTOBUILD.sln -source http://nugetserver...

and avoid thereby the problem that the Jenkins service runs in a different account and searches for the .config in a different place. 并避免Jenkins服务在不同帐户中运行并在不同位置搜索.config的问题。

On the developer machines, the packages are restored by the Nuget-VS-Addin (and not by msbuild), so don't forget to undo the changes that the old Nuget-VS-Addin may have applied to your project-files. 在开发人员计算机上,这些包由Nuget-VS-Addin(而不是msbuild)恢复,因此不要忘记撤消旧的Nuget-VS-Addin可能已应用于项目文件的更改。

More Information can be found in the Nuget-Docs 更多信息可以在Nuget-Docs中找到

Another solution to this problem is to add your custom NuGet.config and executable to a directory on the Jenkins server, and add a build step to run nuget using the custom config. 此问题的另一个解决方案是将自定义NuGet.config和可执行文件添加到Jenkins服务器上的目录中,并添加构建步骤以使用自定义配置运行nuget。

C:\nuget\nuget.exe update "%WORKSPACE%\Project.sln" -ConfigFile C:\nuget\NuGet.config

A NuGet.config adding a custom package source would look something like this: 添加自定义包源的NuGet.config看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="My Custom Package Source" value="http://localhost/guestAuth/app/nuget/v1/FeedService.svc/" />
  </packageSources>
  <activePackageSource>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </activePackageSource>
</configuration>

The standalone nuget.exe can be downloaded here 独立的nuget.exe可以在这里下载

This approach makes it easier to add custom feeds to all your jenkins jobs by changing the same config file. 通过更改相同的配置文件,此方法可以更轻松地向所有jenkins作业添加自定义订阅源。

[Windows] Be sure that the Jenkins service account has permission to see nuget package location. [Windows]确保Jenkins服务帐户有权查看nuget包位置。 In my case, I was using a local admin account that didn't have the domain perms necessary to navigate the network location of our NuGet folder. 在我的情况下,我使用的本地管理员帐户没有必要的域perms来导航NuGet文件夹的网络位置。 Also, be sure the packages aren't nested too deeply. 另外,请确保包装没有嵌套太深。

NuGet Config files used by jenkins were as follows, fixing here worked in my case , hope it helps jenkins 使用的 NuGet 配置文件如下,在我的情况下修复这里工作,希望它有帮助

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM