Cogworks have been working on a way to build a NuGet package that solves one particular issue.
You may have come across "all-in-one" packages that attempt to solve everything at the same time but I've found these are not as effective...
Fragmentation will allow you to include the functionality that you really need in your project so that you don't end up with a library of unnecessary things!
We're using MyGet to host the small internal packages for now. If you're using Azure DevOps Pipelines (as we do for CI/CD), you might need to use packages from your private NuGet feed to build projects; this post will guide you through the pipeline configuration for this setup.
1. In the Azure DevOps portal, add a new service connection for your private NuGet feed.
This is the only thing you need to do manually in the Azure DevOps portal UI.
- Head to your project page and select project settings in the bottom left-hand corner.
- Select service connections.
Below shows the username and password approach to set it up.
- Add a new NuGet service connection (don’t forget to copy its name...you’ll need this later).
2. Create NuGet.config file in your project code repository.
- Keep files related to continuous integration in the Deployment directory; you can place them anywhere in the solution structure that matches your needs.
- Keep the relative solution path to this file on-side, you will also need this for a later step...
3. Set up your NuGet feeds here.
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> <add key="Myget feed" value="https://www.myget.org/F/cogworks/api/v3/index.json" /> </packageSources> </configuration>
4. Update your azure-pipelines.yaml
- Here we're showing part of azure-pipelines.yaml file responsible for restoring NuGet packages. Make sure you use the correct path to NuGet.config file.
steps: - task: NuGetToolInstaller@1 - task: NuGetCommand@2 inputs: restoreSolution: '$(solution)'
steps: - task: NuGetAuthenticate@0 inputs: nuGetServiceConnections: 'MyGet feed' - task: NuGetToolInstaller@1 - task: NuGetCommand@2 inputs: restoreSolution: '$(solution)' feedsToUse: 'config' nugetConfigPath: 'Deployment/NuGet.config' externalFeedCredentials: 'MyGet feed'
That's it, now just push your changes to your repository and trigger a build!
From now on Azure DevOps should be able to restore packages from your private NuGet feed.
...That was easy, right?
Update Jan 2020: We're currently working on an additional extension for an API keys approach to this method, look out on our socials and upcoming blog content for more info!