简体   繁体   中英

Jenkins downloads nuget packages from nuget.org even though I have removed the feed from NuGet.config

I have a internally hosted nexus for nuget packages. I have added the nexus repo url in nuget.config. Also I have removed the nuget.org feed, so it doesn't download packages from internet. I have hosted jenkins in the same machine. But when performing build in jenkins, the nuget packages are getting downloaded from the internet instead of nexus repo. Does jenkins refer any separate nuget.config file? Or is there any command to remove the nuget.org feed, so that I can execute it in jenkins!

As described by NuGet's docs on Common NuGet configurations , NuGet accumulates settings from multiple nuget.config files. You didn't explain how you "removed the nuget.org feed", but there's only one way I can think of that makes it reliable and reproducible. As mentioned in both the docs page I already linked, and also the nuget.config reference page , there's a <clear /> element allowed inside the <packageSources> element which tells NuGet to ignore any source defined in any accumulated nuget.config file.

If you removed the nuget.org feed using Visual Studio, unfortunately VS's NuGet settings is far too simplistic to understand and handle the multi-file inherited settings. When adding or removing sources in VS, it typically edits your user-profile nuget.config , meaning it affects all solutions on the current machine, and current user profile. This means when you use the repo on a different machine, or even a different user-profile on the same machine, the NuGet settings you thought you applied to the solution are no longer there. You need to use nuget.exe, the dotnet cli, or just hand edit a nuget.config xml file.

NuGet will, on any machine it runs on and does not find a nuget.config file at the default user-profile location, create a nuget.config with nuget.org pre-configured. Therefore, if your repo does not explicitly clear inherited sources, when nuget runs for the first time on a new user-profile, it will create a nuget.config that includes nuget.org . Hence if your solution doesn't have its own nuget.config that uses <clear /> , then it will inherit nuget.org on any machine you didn't remove nuget.org from the user profile nuget.config.

So, assuming the only setting needed is the company nuget feed, you should check in a nuget.config in your repo root with contents roughly similar to:

<configuration>
  <packageSources>
    <clear />
    <add key="company-feed" value="https://wheverver/index.json" />
  </packageSources>
</configuration>

Run dotnet build with the —source ( or -s ) option. This will allow you to specify the NuGet source. Seedotnet build docs for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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