Is it possible to change the location of packages for NuGet?

前端 未结 15 1962
误落风尘
误落风尘 2020-11-22 17:11

I have the following convention for most of my projects:

/src
    /Solution.sln
    /SolutionFolder
        /Project1
        /Project2
        /etc..
/lib
          


        
15条回答
  •  日久生厌
    2020-11-22 17:42

    The solution proposed in release notes for 2.1 doesn't work out-of-the-box. They forgot to mention that there is code:

    internal string ResolveInstallPath()
    {
        if (!string.IsNullOrEmpty(this.OutputDirectory))
        {
            return this.OutputDirectory;
        }
        ISettings settings = this._configSettings;
    
        ...
    }
    

    which prevents it from working. To fix this you need to modify your NuGet.targets file and remove 'OutputDirectory' parameter:

        $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)"  $(RequireConsentSwitch)
    

    So now, if you add 'repositoryPath' config somewhere in NuGet.config (see the release notes for a description of valid places to put the config files), it will restore all packages into single location, but... Your .csproj still contains hints to assemblies written as relative paths...

    I still don't understand why they went hard way instead of changing PackageManager so it would add hint paths relative to PackagesDir. That's the way I do manually to have different package locations locally (on my desktop) and on build agent.

    
      True
      $(PackagesDir)\Autofac.2.6.3.862\lib\NET40\Autofac.Configuration.dll
    
    

提交回复
热议问题