I've got a little issue regarding Jenkins and NuGet package restore.
What I'm trying to do is build solutions on jenkins (which works perfectly fine). I have enabled package restore for the solution, which generates the .nuget-folder containing NuGet.exe, NuGet.Config and NuGet.targets.
On Jenkins, I am pulblishing some projects as NuGet-packages in a private package source on our server. I am using those packages in other projects, which should be build on jenkins themselves.
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).
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-parameter when restoring packages which is not beeing replaced as jenkins doesn't know about the custom source.
What I've tried so far
I already know that adding the private source to the solutions NuGet.Config- or NuGet.Targets-file's Package-Source would solve the problem, but that would mean, i would have to do so for every solution I want to build using Jenkins.
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
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.
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-file which contains the private package-source. An other possible fix would be a parameter for msbuild, which I'm not aware of.
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)
We use a batch step in 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.
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.
More Information can be found in the 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.
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:
<?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
This approach makes it easier to add custom feeds to all your jenkins jobs by changing the same config file.
NuGet Config files used by jenkins were as follows, fixing here worked in my case , hope it helps
[Windows] Be sure that the Jenkins service account has permission to see nuget package location. 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. Also, be sure the packages aren't nested too deeply.
Related
I have read and gone trough the following:
https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore#enabling-and-disabling-package-restore
https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore-troubleshooting
Why is there no packages folder in .my NET Core solution's containing folder?
'nuget' is not recognized but other nuget commands working
https://www.skylinetechnologies.com/Blog/Skyline-Blog/July_2016/Relocate_NuGet_Package_Restore_Folder
But i still have issues with the Folder Packages which contains the Packages for my solution, when i check in my code, for my on my side everything works fine, when someone else gets the checked in solution, he has to change the path that is set in the ProjectNameFile.csproj because the path there contains
../../../../NuGetPackages/....
but should be (and only works if changed to)
../Packages
But than when this persons checks in and i get this version, my packages folder is gone ... We have been using TFS on other projects here but this is a first for me ...
I tried all what the links i posted are suggestion but with no luck.
Tools > options > NuGet Package Manager looks like this:
I have a NuGet.Config file on the same level as my projectname.sln file which has following content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<!-- I tried each line below seperately and together -->
<add key="globalPackagesFolder" value=".\packages" />
<add key="repositoryPath" value="C:\Development\projectname\Packages" />
</config>
</configuration>
So what i did now is i created a Packages folder on the projectname.sln level and when i build my solution, this works but hey, i can't do that each (X) time and i am sure there is a way of achieving this but don't know how.
Thank you in advance for any feedback.
How to properly configure NuGet Packages for collaboration with DevOps (TFS)
I suppose you are using the packages.config as nuget package management, because you said " he has to change the path that is set in the ProjectNameFile.csproj because the path there contains ../../../../NuGetPackages/....".
So, if you are using packages.config, you should use relative paths for the repositoryPath in your nuget.config file when you build the project with Azure DevOps.
As we know, when we build the project in the Azure DevOps, Azure DevOps always copy the project to the path like D:\a\1\s\xx, which is different with the path in your local. And NuGet always use the relative paths (..\packages or ../../../../NuGetPackages/...)in the ProjectNameFile.csproj like:
<Reference Include="packagename, Version=3.0.0.0, xxx">
<Private>True</Private>
<HintPath>..\packages\xxx\lib\net45\xxx.dll</HintPath>
</Reference>
In this case, when we build the project, nuget will still restore the nuget packages to absolute path C:\Development\projectname\Packages, but since the location of the project has changed to the D:\a\1\s\xx, so the relative paths for the HintPath in the .csproj file should also be changed accordingly, otherwise nuget can't find the corresponding dll file.
So, we should set the repositoryPath as relative paths in the nuget.config file, like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value=".\packages" />
</config>
</configuration>
With this setting, the path of the packages folder are based on the file nuget.config. As long as you have not modified the location of the nuget.config file, the HintPath does not need to be modified.
Note:
globalPackagesFolder is uesed for another nuget management type packagereference.
If you are working with someone else to develop a project, you need to unify the location of the nuget package, rather than continually modifying the HintPath manually. Otherwise it will cause confusion in your development.
Hope this helps.
We have a private NuGet server and my issue is the TFS 2017 builds don't recognize the internal package's NuGet server, obviously, without specifying the URL. I've tried putting it in Nuget.config and it worked, but with some issues.
What I would like to do, however, is somehow add this to the global list of feeds. I do not have NuGet installed on the server, though NuGet restore is happening as a build Task, so it exists under c:_work_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.21\ etc, and do not see anything that would let me change the set of feeds.
BTW, when I added a package source to nuget.config, it seemed to ONLY download from that source and ignored all the defaults, such as nuget.org, etc.
How can I add an internal nuget server so that all my builds natively can access it? Thanks.
Generally you just need to add the feeds (also add the nuget.org source) to NuGet.config file, then check in the file.
(If you used the third private NuGet server, then you can have a try with the Package Management in VSTS and TFS)
e.g.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- remove any machine-wide sources with <clear/> -->
<clear />
<!-- add a VSTS feed -->
<add key="MyGreatFeed" value="https://fabrikam.pkgs.visualstudio.com/DefaultCollection/_packaging/MyGreatFeed/nuget/v3/index.json" />
<!-- also get packages from the NuGet Gallery -->
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
For this issue : "it seemed to ONLY download from that source and ignored all the defaults, such as nuget.org, etc."
Make sure you have correctly set the NuGet.config file and the nuget.org source is not excluded.
To Restore NuGet packages in Build you can follow the steps mentioned in below article:
Restore Package Management NuGet packages in Team Build
If you've checked in a NuGet.config, select Feeds in my NuGet.config and select the file from your repo.
If you're using a single VSTS/TFS feed, select the Feed(s) I select here option and select your feed from the dropdown.
A bit outdated, but I also looked at a solution in our local TFS on how to integrate other local nuget feeds.
Navitage to settings and select "Services"
you should now see a list of Endpoints
Click on "+ Add New Service Endpoint" and select "NuGet" from the dropdown
a dialog opens where you can enter the information of your local NuGet server
After saving the endpoint you should now be able to select your NuGet-Endpoint in your build, when you add a NuGet-Restore buildstep (in Version 2.*) and..
in the buildstep select "Feeds in my NuGet.config" under "Feeds to use*"
a dropdown should now be shown to select "Credentials for feeds outside this account/collection". In this dropdown you can select your NuGet-Endpoint.
I have a TFS server without internet access. I configure my own nuget package feeds in TFS and I try to restore packages of my solution only from this feed. But when I start Nuget restore build step, nuget try to connect to nuget.org and the connection failed. I don't understand how prevent this attempt of unnecessary connection ?
You can control your NuGet sources in the Nuget.Config file. Create a file "Nuget.config" in the same folder as your solution file. Within the config file, you can clear all source and define your own. As an example, you can set your packageSource as follows
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="ThirdParty Nuget Repository" value="http://localNuget/artifactory/api/nuget/ThirdParty" />
</packageSources>
</configuration>
The <clear/> element will clear your existing Nuget sources and the <add> element will set up a new local Nuget Source for you.
More on Nuget config file can be read at
https://learn.microsoft.com/en-us/nuget/schema/nuget-config-file
I find the problem. In fact, I think NugetRestore task try to connect to nuget.org to get the last version of nuget.exe.
I skirt the problem with use version 0.* of NugetRestore task and specif the version of nuget to use.
ASP.NET 4.5 MVC application
Builds/runs just fine locally
Packages folder NOT checked into source control
Source control looks like this:
MyProject
-.nuget
-.tfignore
-MyProject.Web
-MyProject.Utilities
-MyProject
-MyProject.sln
Inside of the .nuget folder, there is only one file: NuGet.config, which has this inside:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
I can delete the packages folder locally, run it, and it correctly downloads everything again.
When I kick off a build from Visual Studio which should build the solution and deploy it to Azure Cloud Service, the build fails saying:
The type or namespace name 'WindowsAzure' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
The "new" way to do this is to run
nuget.exe restore "MySolution.sln"
I put my (versioned) nuget.exe files on my build server like this:
c:\MyProgFiles\NuGet\2.8.6\nuget.exe
c:\MyProgFiles\NuGet\3.3.0\nuget.exe
Then before I build, I call
"c:\MyProgFiles\NuGet\2.8.6\nuget.exe" restore "c:\MyFullPath\MySolution.sln"
You can also read this about "how to clean up old nuget stuff"
http://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore
(using CI macros when possible to create the file names)
I also put these lines before the "nuget restore" to help with debugging.
"c:\MyProgFiles\NuGet\2.8.6\nuget.exe" sources list
"c:\MyProgFiles\NuGet\2.8.6\nuget.exe" locals all -list
BTW: If you have a package source where the packages might get deleted, then add this to your build scripts (before the "restore" mentioned above)
"c:\MyProgFiles\NuGet\2.8.6\nuget.exe" locals all -clear
This will clear your local cache and force a fresh download.
Again, the value here is ONLY if you use a source where packages get deleted.
I'm using NuGet Package Restore. I want to specify custom sources during a TFS build server process.
The NuGet.targets file in the hidden '.nuget' folder says that you can either specify sources repositories, or that it will fall back to the NuGet.config in %APPDATA%\NuGet\NuGet.config.
There is however a NuGet.config in the hidden '.nuget' folder as well. I assumed that if you did not specify sources repositories in NuGet.targets that it would fall back to the NuGet.config in the hidden '.nuget' folder. This doesn't seem to be the case.
Any ideas?
With the current version of NuGet it's possible to specify custom repositories in the solution's NuGet.config file and enable package restore during a build.
Having this NuGet.config file allowed us to automatically restore packages from internal repository under a TFS build without any other actions in the build definition:
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="Internal" value="http://MyInternalRepository/nuget" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
</configuration>
Note: TFS2013's default Build Process Templates already implements NuGet Package Restore workflow without any special configuration as stated here: http://docs.nuget.org/docs/reference/package-restore-with-team-build
If you enable package restore, you'll find a NuGet.targets MSBuild file in the $(SolutionDir)\.nuget folder.
You can set the package sources by modifying the <PackageSources>""</PackageSources> element.
Example:
<!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
<PackageSources>"http://packages.nuget.org/api/v2/;http://myget.org/F/myfeed/"</PackageSources>
According to pranavkm, one of the NuGet devs, at the time of this writing NuGet Package Restore will not use the NuGet.config in the hidden '.nuget' folder for sources. It's only used at the moment for a solution specific setting (to ignore source control bindings). He says it is on the radar for the NuGet team to leverage all aspects of NuGet.config but that it keeps getting bumped in priority.
Another option is to add sources to a machine-wide (not user-specific) nuget config on the build server.
https://stackoverflow.com/a/27569020/374837
in tfs build 2017 when you use the NuGet Restore task version 1.* you can select the NuGet.Config file to use during the build.
See image below NuGet Restore Task