Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use msbuild without project.assets.json or nuget restore?

Tags:

nuget

msbuild

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.

like image 923
Eric Avatar asked Nov 06 '17 21:11

Eric


People also ask

Does MSBuild restore NuGet packages?

msbuild -t:Restore will restore nuget packages for projects with PackageReference nuget management format.

Where does project assets JSON come from?

json file is generated in the process of restoring the NuGet packages in projects that use project. json . It holds a snapshot of all the information that is generated as NuGet walks the graph of packages and includes the version, contents, and dependencies of all the packages in your project.

Does MSBuild use packages config?

MSBuild 16.5+ also has opt-in support for the packages. config format.

How do I install NuGet packages missing?

Enable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.


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.

like image 89
Martin Ullrich Avatar answered Sep 18 '22 22:09

Martin Ullrich


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>
like image 37
Eric Avatar answered Sep 20 '22 22:09

Eric