Search code examples
.netnugetnuget-packagenuget-package-restorenuget-server

Is it possible to specify nuget local server source for individual solution?


I am wondering how to specify the nuget local server for single solution i don't want to add this on the visual studio level. So when we push the code to bitbucket and wants bamboo to use that source for nuget, which we want to specify somewhere in the solution.

Nuget local source

The above link i think proposing some solution to my problem. But I have tried the NuGet.config file but it is still using the default nuget source. And i am not sure where to put that NuGet.targets file.

May be i might be wrong some where. Can please someone guide me? Is it possible or not. and what should i do. Thanks.


Solution

  • You can specify NuGet sources in the NuGet.Config file. This file is part of the solution and the configuration is also used on your build server so it does not depend on whatever settings you have in Visual Studio.

    First step is to enable NuGet package restore (which you probably already have). Right-click on the solution in Solution Explorer and select Enable NuGet Package Restore. This will add a .nuget folder in the solution and in this folder you will find the file NuGet.Config.

    NuGet solution folder

    Then you need to modify the NuGet.Config file by adding your local NuGet repository:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <add key="NuGet official package source" value="https://nuget.org/api/v2/" />
        <add key="Local package source" value="http://server/NuGet.Server/nuget/" />
      </packageSources>
      <solution>
        <add key="disableSourceControlIntegration" value="true" />
      </solution>
    </configuration>
    

    You need to adjust the value attribute of the local package source to point to your local NuGet server.