Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Project specific Nuget.config with .net core/code

Normally, we get our Nuget.config from users\[loggedinuser\AppData\Roaming\Nuget but we have a case where a specific project where we need a use a different project specific config file. Where do I place the config file in this case?

I am using .net core SDK 1.0.4 and .net code.

The build script does this:

cd src\SFMC.Adapter.Service
dotnet restore
dotnet build

Can I pass an argument into dotnet restore to indicate the location of the config?

like image 235
Jon Raynor Avatar asked Dec 01 '22 11:12

Jon Raynor


2 Answers

Assuming your project structure looks like:

Project/
└── src
    ├── SFMC.Adapter.Client
    ├── SFMC.Adapter.Service
    │   ├── Program.cs
    │   └── Project.csproj
    └── SFMC.Adapter.Service.Test

You can add a Nuget file anywhere within the project tree. Where you place it will affect which projects see it by default. dotnet restore will search for all Nuget.config files up the directory tree to add any sources it finds.

If you place it next to Service.cs, it will only be picked up by SFMC.Adapter.Service. If you place it under src it will be picked up and used by SFMC.Adapter.Service, SFMC.Adapater.Service.Test and SFMC.Adapter.Client.

See NuGet configuration docs for more details.

like image 146
omajid Avatar answered Dec 06 '22 17:12

omajid


I know it is a rather old post, but I was struggling with it as well and had a hard time finding the correct documentation. I eventually found that you can execute the command below to add a new nuget config to the location where you are. dotnet new nugetconfig

This will use the dotnet cli to use the nugetconfig template (that appeared to be installed by default) to generate a correct file

like image 34
Vincent Avatar answered Dec 06 '22 16:12

Vincent