I have a .Net Standard project in a solution and I want msbuild to build it on our build server. If I do not run "nuget restore" first, I get the error "project.assets.json' not found. Run a NuGet package restore". I already have all of the necessary NuGet packages in the "packages" folder at the solution level. I would like to indicate somehow that msbuild should just use the files in the local "packages" folder instead of trying to re-download the files. How can I do this? Thank you.
2 Answers
.NET Standard projects do not use the packages
folder in the solution. This is the "old" way of referencing NuGet packages through packages.config
. The new way - PackageReference
items in the project - uses a shared global packages folder in the user's home directory. The project.assets.json
needs to be regenerated on the build machine with the resolved paths to this shared cache even if no packages need to be downloaded. In fact, a NuGet restore might not even need to hit the network if all packages are already on the machine.

- 94,744
- 25
- 252
- 217
-
Then, is there a way to indicate to Nuget Restore to use that "packages" folder at the solution level to refresh from? My NuGet repository is privately shared on VSTS, and I don't know of a good way to store credentials with the build definitions, which are on a local TFS Server, not VSTS. – Eric Nov 06 '17 at 21:23
-
@Eric - I would take a look at using maybe the RestoreFallbackFolders property which can be used to specify a folder the restore can look at when restoring NuGet packages - https://github.com/NuGet/Home/wiki/%5BSpec%5D-NuGet-settings-in-MSBuild - or look at using a NuGet.Config file, contained with your solution, which has the package sources and credentials that you need. – Matt Ward Nov 06 '17 at 23:40
-
also have a look at https://stackoverflow.com/questions/43687058/how-do-i-include-nuget-packages-in-my-solution-for-net-core-projects/43687514#43687514 - there are a few ways to include .nupkg files or the "global cache" in a git repo. But a global NuGet config on build agents can also specify feeds with credentials. And for VSTS there should be ways to let agents access feeds (don't know how exactly though) – Martin Ullrich Nov 07 '17 at 03:24
-
But TL;DR the assets file and the generated .runtimeconfig.dev.json file (when you want to run tests) need to contain build machine specific paths in either ways - whether it would be `C:\Users\builduser\.nuget\packages` or `C:\agent\_work\2\s\checkedInGlobalCache` – Martin Ullrich Nov 07 '17 at 03:25
-
1@MartinUllrich what would you say, if I say this. command line to build solution fails (netstandard project with `PackageReference`). then, I open solution in IDE, `project.assets.json` is generated. Now I do nothing and close IDE. Re-run command line - works. so, back to original question, how to avoid restore/open IDE? – T.S. Sep 26 '18 at 20:15
The best solution I have come up with still involves a NuGet restore, but I added the local packages folder as one of the NuGet repositories in nuget.config and now I don't have to reach out to any remote repositories. This is not quite what I wanted, but it is allowing me to progress.
<packageSources>
<add key="local" value=".\packages" />
</packageSources>

- 2,120
- 1
- 17
- 34