I have a private NuGet repository created with BaGet.
My software is hosted in Google Cloud where there is also the Git repository with my code.
I have some Cloud build triggers that run the build in the cloud and automatically deploy the applications.
I have created some NuGet package with my projects and now I need to change the reference from code (project reference) to NuGet package reference in my private repository.
Locally all works, but now I need to do the same in my Google Cloud build trigger and I don't know where I can specify the reference to my private repository.
My build script is a yaml file but inside I don't have a reference to the standard NuGet repository and I don't know how I can specify an additional NuGet package repository for some libraries.
NuGet reads configuration from nuget.config files. In fact, it reads from multiple config files. So you can commit a nuget.config to your source code repository, and therefore anyone else who clones your repo (even a CI agent) doesn't need to be configured, it "Just Works".
The part of the config that's relevant to your question is the <packageSources> section, so a minimal config with only package sources defined is:
<configuration>
<packageSources>
<!-- make sure other nuget.config files don't add unexpected sources -->
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="private" value="https://my-server/index.json" />
</packageSources>
</configuration>
Related
For a current project, we had to resort to C# for parts of the programming. After the leftpad-occurences in npm, I'd like to create a mirrored package repository for securing builds.
Since managing dependencies by hand is a hassle, is there an automated way to mirror a NuGet-Package including all dependencies on my local / shared drive?
You can setup a private nuget feed and host the packages there.
For example in azure devops we have Azure artifacts:
https://learn.microsoft.com/en-us/azure/devops/artifacts/start-using-azure-artifacts?view=azure-devops#get-started-with-azure-artifacts
In that case the nuget feed is a private feed and you can configure it to access the public nuget feed. any consumed packages will then also be kept on the private azure artifacts feed, meaning you always have the original package.
The nuget.org upstream source allows you to merge the contents of nuget.org into your feed such that the NuGet client can install packages from both locations without making multiple search queries. Enabling upstream sources also automatically enables saving of packages you use from the upstream source.
https://learn.microsoft.com/en-us/azure/devops/artifacts/nuget/upstream-sources?view=azure-devops
Also see:
https://learn.microsoft.com/en-us/azure/devops/artifacts/concepts/upstream-sources?view=azure-devops
I've also seen people using MyGet:
https://www.myget.org/
And another option is to just use a local folder as a nuget source.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- NuGet packages are now stored globally, see: https://stackoverflow.com/a/35809007/4122889 -->
<!-- see: https://stackoverflow.com/a/53451805/4122889 -->
<config>
<add key="globalPackagesFolder" value=".\Packages" />
<add key="repositoryPath" value=".\Packages" />
</config>
<!-- Setup for local packages, not in a nuget source -->
<packageSources>
<add key="My_Azure_Feed" value="https://pkgs.dev.azure.com/org/proj/_packaging/My_Azure_Feed/nuget/v3/index.json" />
<!--<add key="LocalPackages" value="./LocalPackages" />-->
</packageSources>
<activePackageSource>
<!-- this tells that all of them are active -->
<!--<add key="All" value="(Aggregate source)" />-->
</activePackageSource>
</configuration>
We are using Visual Studio 2019 and we have a solution that has a references to some NuGet packages either from nuget.org or from our private server we are managing the solution with packages.config management, the problem is there is one ASP.NET project in that solution that does not install any of the required packages(in our case it misses the NewtonSoft.json), and installs all the other ones correctly, even though we have packages restore enabled, and there are other ASP.Net projects in the solution that install the Newtonsoft package correctly, but each time you read the last version of the solution from zero (in the case you delete the local solution and re-read it) from the TFS, you need to install the Newtonsoft.json manually for that project specifically.
PS: it's a problem that can be solved in 5 min every time but I know something is wrong and I have been trying to understand what is it, I don't want to solve it localy, but I need a solution the resolve it on the TFS level, so please help me if you can or if you know any other questions here that can help, please guide me through (if I didn't see it already).
My NuGet.Config document:
<?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="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
<add key="MxNuget" value="our server path" />
</packageSources>
<activePackageSource>
<add key="All"
value="(Aggregate source)" />
</activePackageSource>
<packageRestore>
<add key="enabled" value="true" />
<add key="automatic" value="true" />
</packageRestore>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
the error we are getting is the following:
The name 'Newtonsoft' does not exist in the current context.
The problem I was having was because the TFS was not restoring all the packages needed because when he sees the Folder 'Packages' in the solution he just check if the package is inside, and when he is done, the version that he found and the one on the local machine may be different and that was causing the problem, so I wanted to delete my packages folder on the TFS but I couldn't find it. For that I installed a package in my solution which adds .tfignore to the .nuget folder in the solution directory, and that last file tells the TFS to ignore the packages file on the server and restor them always.
Questions that were useful:
1 - Tfs Can't restore Nuget packages.
2- NuGet Packages are missing
3- External: Missing Nuget Packages on TFS Build Server
I resolved the problem by following the steps:
installed the package DisableSourceControlIntegration to the project that was missing the Newtonsoft.json NuGet.
Unified all the versions of NewtonSoft.json on the projects to which my ASP.Net project has a reference. (I think that was the main problem because I had them unified before but I updated the whole group with their config files).
In the visual studio, open Tools --> Nuget package manager --> package manager setting and make sure that the Packages.config is selected as the format of managing the NuGet packages.
deleted all the packages cash.
Re-compiled the solution.
Pushed to the TFS.
I'm using VSCode with the official C# extension to develop a .NET Core console app on Ubuntu. I'd like to use a private nuget package in this console app. Usually one would add a local feed for nuget packages like described here with nuget init c:\packages \\myserver\packages. I've tried to find some settings in the C# extension which would allow me to configure a local feed for nuget packages but did not find any. Is it possible to do the same with the VSCode + C# extension builtin support?
Alternatively, you can create a file named "NuGet.Config" in the directory where the solution is located and do its contents as follows;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="KetumMyGet" value="https://www.myget.org/F/ketum/api/v3/index.json" />
<add key="KetumMyBaget" value="http://localhost:5000/v3/index.json" />
<add key="TestSource" value="c:\packages" />
</packageSources>
</configuration>
See more here
We use the lprun feature of LINQPAD to run our build scripts; However as we are in a corporate environment we block access to the NuGet.org package source:
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
And instead use a corporate proxy e.g. a custom package source:
<add key="MyProxy" value="https://proxy.server/custom-nuget-repo" />
When developing locally these sources are specified in:
C:\Users\Me\AppData\Roaming\Nuget.config
However LINQPAD is ignoring this file, how can I provide custom package sources when using the lprun to restore NuGet packages referenced?
From newer LinqPad versions this is built in to the LinqPad NuGet manager. Go to QueryProperties (F4) -> 'Add Nuget' -> 'Settings' and new package sources can be added just as easily as in VS.
Adding a new answer here since Google led me to this question first when trying to find the answer.
lprun and LINQPad both use the file %AppData%\LINQPad\NuGetSources.xml for NuGet Package sources, so this is the file you need to edit.
In case this file doesn't exist, here is an example:
<?xml version="1.0" encoding="utf-8"?>
<NuGetSources>
<Source Name="(default)" />
<Source Name="My Packages" URI="https://www.myget.org/F/your-username-here/" UserName="Example" Password="base64encodedstring" Enabled="false" />
</NuGetSources>
I am new at creating custom nuget package. I used NuGet Package Explorer and added new Class Library dll to my local nuget repository. Now I can install it to my new projects.
But Sometimes I need install my custom package and change current project web.config file. Add new key or section. Is this possible?
You can modify the web.config through a web.config.transform file or by using an XML document transform (XDT).
For a .transform you create a web.config.transform file and put in the Content directory of your NuGet package. The web.config.transform file contains the same as a web.config file and it will be applied to the web.config file when you install the NuGet package.
XDTs are more powerful and can do more complicated modifications to the web.config file, such as inserting or removing existing elements. You create a web.config.install.xdt and optionally a web.config.uninstall.xdt file in the Content directory of the NuGet package. These transforms are then run when the NuGet package is installed or uninstalled. An example, taken from the NuGet documentation, is shown below.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<modules>
<add name="MyNuModule" type="Sample.MyNuModule" xdt:Transform="Insert" />
</modules>
</system.webServer>
</configuration>
The full XDT syntax is documented on the MDSN website