2

I am trying to build an app from command line using msbuild. I first run msbuild -t:restore and specify the directory (say foo) to which packages are restored. After this, I want to run msbuild and inform it that the packages are in directory foo.

Does msbuild have an option using which I can specify the directory that contains the dependencies required for build?

I am using msbuild version 16.6

Ojasvi Monga
  • 4,437
  • 2
  • 18
  • 35
  • First you say: "I first run msbuild -t:restore and specify the directory (say foo)", then you say later "After this, I want to run msbuild and inform it that the packages are in directory foo.". I do not understand. Can you concretize your workflow (command sequence or equivalent)? – Teneko Aug 01 '20 at 17:01
  • I am using msbuild -t:restore to fetch all the dependencies required to build my project. Once this is done, I want to run the actual build and get the artifact. – Ojasvi Monga Aug 01 '20 at 17:15
  • Does this answer your question? [Is it possible to change the location of packages for NuGet?](https://stackoverflow.com/questions/4092759/is-it-possible-to-change-the-location-of-packages-for-nuget) You may specifiy the nuget.config path with `/p:RestoreConfigFile=` but beware that inheritance of nuget.config files may only work with original file name `nuget.config`. – Teneko Aug 01 '20 at 17:50
  • No because a) I want to do this using command line, not the config file b) i want to use msbuild, not nuget c) I want the command to specify where the location from which the packages should be picked up while building. The current behavior I'm getting is: I see the packages being installed, but when the project is being built, it says the packages are not present and gives me missing dependency errors – Ojasvi Monga Aug 01 '20 at 17:56
  • And what's about `-p:RestorePackagesPath=`?? You can find this and more settings here: https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target. – Teneko Aug 01 '20 at 18:02
  • As I said, I'm doing my build in 2 steps. The property you mention is used in the first step. My question is about the second step – Ojasvi Monga Aug 01 '20 at 18:04
  • By the way you are using NuGet automatically when using `msbuild`. MSBuild uses SDK specific props and targets and thats include files like https://github.com/NuGet/NuGet.Client/blob/c05f9afa9c2fcee7fbe10754521b3f6424bee128/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets ^^ – Teneko Aug 01 '20 at 18:05
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/219058/discussion-between-teroneko-and-joe). – Teneko Aug 01 '20 at 18:11

1 Answers1

1

In both your commandline that performs the /t:restore and your build command, you need to specify -p:RestorePackagesPath=<yourcustomfolder>

In addition, in your build command, you should add /p:RestorePackages=false

See https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target

Neil Hall
  • 11
  • 3