locked
Changing nuget path location RRS feed

  • Question

  • User1396448631 posted

    I have built a .net core web app. Works fine locally. By default, nuget installs all the packages in C:\Users\..\.nuget\packages.

    Q1. How does the project know the location where the nuget packages are stored? 

    While checking in my code to the server, I would like all the packages to be in a package folder (which is in the same folder as the solution file)

    Q2. What should I do in the project for it to look for the packages in this package folder instead of C:\Users\..\.nuget\packages.

    I tried to do this in nuget.config file but that didnt work. The package folder is still empty

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <config>
        <add key="globalPackagesFolder" value="./packages" />
      </config>
    </configuration>

    Wednesday, December 11, 2019 2:58 PM

Answers

  • User-474980206 posted

    Hi Bruce,

    Here is what I did.

    I deleted all the packages inside c:\users\...\.nuget\packages folder.

    Then in the folder containing solution file, I opened Nuget.Config and added the following

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <config>
      <add key="repositoryPath" value="C:\CustomPackagesFolder" />
      </config>
    </configuration>

    I closed Visual Studio. When I open VS, it automatically downloads all the packages in the c:\users\...\.nuget\packages even before building the project.

    Even after I build the project, CustomPackagesFolder is empty.

    Am I missing anything?

    nuget is run at the project level, not solution. when nuget runs, it climbs the directory tree looking for a nuget.config files, then applies the values, from the top of the tree down. 

    start at the project folder, then its parent folder (and so on) looking for nuget.config. check the setting in each one. the one closest to the project folder wins. 

    to run the nuget download, go the the project folder and type:

    dotnet restore

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 11, 2019 7:22 PM
  • User753101303 posted

    You are using package references ? Seems fine here by creating a nuget.config file at the same level than my sln file and doing a restore :

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <config>
            <add key="globalPackagesFolder" value="c:\packages" />
        </config>
    </configuration>

    Edit: woriks with ./packages as well. This folder is at the same level than you .sln file in inside your project folder?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 11, 2019 8:31 PM

All replies

  • User753101303 posted

    Hi,

    According to https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file an existing NUGET_PACKAGES environment variable would take precedence. The nuget config file is in the solution folder? You added (or restored) packages after this change ?

    Never tried yet. You want to put back packages to your source code control?

    Wednesday, December 11, 2019 3:42 PM
  • User-474980206 posted

    nuget does not download to the global packages folder, it looks there for the package before downloading. if you want to change where the packages are downloaded for the build, its:

     <add key="repositoryPath" value=".\Packages" />
    (which is the default if no config file)
    each project can have its own nuget.config, or use a one at a shared root directory. 
    Wednesday, December 11, 2019 4:08 PM
  • User1396448631 posted

    Hi Bruce,

    Here is what I did.

    I deleted all the packages inside c:\users\...\.nuget\packages folder.

    Then in the folder containing solution file, I opened Nuget.Config and added the following

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <config>
      <add key="repositoryPath" value="C:\CustomPackagesFolder" />
      </config>
    </configuration>

    I closed Visual Studio. When I open VS, it automatically downloads all the packages in the c:\users\...\.nuget\packages even before building the project.

    Even after I build the project, CustomPackagesFolder is empty.

    Am I missing anything?

    Wednesday, December 11, 2019 5:50 PM
  • User1396448631 posted

    I do not want to use a NUGET_PACKAGES global package repo. We have been told to keep dependencies of a project within the project.

    Wednesday, December 11, 2019 5:55 PM
  • User753101303 posted

    I'm not suggesting to use this environment variable but to make 100% sure it is NOT defined (the doc tells it would take precedence over the config file which could explain maybe why no change seems to work ???).

    Else I'll have to give this a try at home...

    Wednesday, December 11, 2019 6:23 PM
  • User-474980206 posted

    Hi Bruce,

    Here is what I did.

    I deleted all the packages inside c:\users\...\.nuget\packages folder.

    Then in the folder containing solution file, I opened Nuget.Config and added the following

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <config>
      <add key="repositoryPath" value="C:\CustomPackagesFolder" />
      </config>
    </configuration>

    I closed Visual Studio. When I open VS, it automatically downloads all the packages in the c:\users\...\.nuget\packages even before building the project.

    Even after I build the project, CustomPackagesFolder is empty.

    Am I missing anything?

    nuget is run at the project level, not solution. when nuget runs, it climbs the directory tree looking for a nuget.config files, then applies the values, from the top of the tree down. 

    start at the project folder, then its parent folder (and so on) looking for nuget.config. check the setting in each one. the one closest to the project folder wins. 

    to run the nuget download, go the the project folder and type:

    dotnet restore

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 11, 2019 7:22 PM
  • User753101303 posted

    You are using package references ? Seems fine here by creating a nuget.config file at the same level than my sln file and doing a restore :

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <config>
            <add key="globalPackagesFolder" value="c:\packages" />
        </config>
    </configuration>

    Edit: woriks with ./packages as well. This folder is at the same level than you .sln file in inside your project folder?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 11, 2019 8:31 PM
  • User711641945 posted

    Hi dbqasp,

    What is your version of your Visual Studio?

    Open your .csproj file and try this:

    <PropertyGroup>
        <RestorePackagesPath>C:\CustomPackagesFolder</RestorePackagesPath>
    </PropertyGroup>

    Best Regards,

    Rena

    Thursday, December 12, 2019 6:39 AM