2

I have a solution in Visual Studio 2015 with about 40 projects in it. Some of these projects have some NuGet packages referenced.

Due to a combination of our branching strategy (where each project folder is branched individually) and our security requirements (that the NuGet binaries are actually checked into TFS) I would like the NuGet packages for each Project to be installed into each Project's folder, not in the solution's folder. Space usage is not a concern here.

I've looked at: https://docs.nuget.org/consume/nuget-config-file https://docs.nuget.org/Release-Notes/NuGet-2.1#Specify-packages-Folder-Location

And they've helped my understanding of how the config files work... but I can't seem to get it to do what I want.

I've tried this in my config file:

<configuration>
  <config>
    <add key="repositoryPath" value="$(ProjectDir)\Nuget\" />
  </config>
</configuration>

But it creates a folder in the solution folder actually called '$(ProjectDir)'.

And I can't hardcode the path to the project folders (i.e. 'C:\myteam\teampackages' in the NuGet docs) as pretty much everyone in the team have different paths to their local workspaces!

How can I do this?

GoldieLocks
  • 845
  • 7
  • 22

2 Answers2

0

The Nuget docs mentions specifying package folder location is to have many different solutions share the same package. This is an opposite scenario as your. Repository path setting only allows you to install the NuGet packages in the specified folder (like C:\teampackages ) or for relative path (like ../Nuget).

To make installing package in different repositoryPath, you can try:

<configuration>
    <config>
        <add key="repositoryPath" value="../Nuget" />
    </config>
</configuration>

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

Community
  • 1
  • 1
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • This is completely the opposite of what I'm asking for isn't it? – GoldieLocks Nov 26 '15 at 13:56
  • Yes, relative path is only relative to the solution folder. Repository path setting only allows you to install the NuGet packages in the specified folder (like C:\teampackages ) or for relative path (like ../Nuget). – Cece Dong - MSFT Nov 27 '15 at 05:29
0

Firstly, you should not check in NuGet packages into TFS Version Control. As one of the advantages of using NuGet is that you can use it to avoid checking in binaries to your version control system.

Instead, you need to restore NuGet packages during TFS build process and the required packages will be downloaded. In VS2015, you need to follow steps in this blog: https://docs.nuget.org/consume/package-restore/team-build).

Some key steps are (assume you're working with XAML build):

  1. Add following items to the solution. (Content of the nuget.config and .tfignore file can be found here)

enter image description here

  1. Add one build.proj file under the root path of the solution folder. (Content of the build.proj file can be found here)

  2. Create one folder named tools under the root path of the solution folder. Create NuGet sub-folder under tools folder, download and save nuget.exe under tools\NuGet path.

  3. Check in nuget.config, .tfignore, build.proj and tools\NuGet\nuget.exe into TFS version control.

  4. Modify the build definition to choose to build the build.proj file. enter image description here

Then you will have NuGet packages restored successfully during the TFS build process.

Community
  • 1
  • 1
Vicky - MSFT
  • 4,970
  • 1
  • 14
  • 22