Storing nuget packages in an alternate location on the build server

When developing locally, I have Nuget packages installed in the default folder (\ packages in the solution folder).

I want to have a different folder on my build server, which acts as a path to the repository, where I can also download packages, effectively providing me with a local cache of packages that will be stored in assemblies, without requiring all packages to be loaded every time to build.

On the CI server, I drop the nuget.config file into the solution directory, which indicates the location of the new package folder:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <!-- Specify repository path -->
    <add key="repositorypath" value="x:\nugetPackages" />
  </config>
  <activePackageSource>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </activePackageSource>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
</configuration>

x:\nugetPackages \, , , DLL . , hintPath - "..\packages\lib\lib.dll", , .

msbuild - . , msbuild script, :

, : error CS0246: The type or namespace name 'HttpRequestMessage' could not be found (are you missing a using directive or an assembly reference?)

, MSBuild script :

  • nuget "cache" (, x:\nugetPackages).
  • (..\packages).
  • .

, , - ? , XSLT hintPath . , ?

+4
2

NuGet %localappdata%\NuGet\Cache, nuget.config.

NuGet , , . (activepackagesource "" )

+2

, nuget.

  • : / ( )
  • :

, , . - , , hintpaths Visual Studio. -, . ( mklink, hintpaths)

:

c:\packages\ --> our shared package repository
c:\mySolutions\solution1
c:\mySolutions\solution1\packages --> symlink to c:\packages
c:\mySolutions\solution2
c:\mySolutions\solution2\packages --> symlink to c:\packages    

:

cd c:\mySolutions\solution1
mklink /D packages c:\packages

, Nuget. ( : , , 200 .) , nuget restore .

+5

Source: https://habr.com/ru/post/1547473/


All Articles