question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auto restore does not work for .NET Core projects when building via MSBuild

See original GitHub issue

Description

I have .NET Core solution with netstandard2.0 project using Paket to manage dependencies. I followed instructions on https://fsprojects.github.io/Paket/paket-and-dotnet-cli.html to setup automatic restore of packages. When I build solution from Visual Studio it works fine, but when I build it from command line on CI server using msbuild solution.sln it fails with:

C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(323,5): er
ror : Assets file 'e:\Temp\PaketTest\PaketRestoreTest\TestProject\obj\project.assets.json' not found. Run a NuGet packa
ge restore to generate this file. [e:\Temp\PaketTest\PaketRestoreTest\TestProject\TestProject.csproj]

Repro steps

I attached PaketRestoreTest.zip with sample solution to reproduce this issue.

  1. Have Visual Studio 2017 Update 3 and .NET Core SDK 2.0
  2. Extract attached solution
  3. Open Visual Studio Command Prompt and run msbuild PaketRestoreTest.sln

Expected behavior

I would expect that building from command line properly restores packages and build succeeds.

Actual behavior

Build from command line fails, unless you explicitly call msbuild PaketRestoreTest.sln /t:Restore or dotnet restore before calling msbuild PaketRestoreTest.sln.

Known workarounds

Call msbuild PaketRestoreTest.sln /t:Restore or dotnet restore before calling msbuild PaketRestoreTest.sln.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
Katuluscommented, Aug 31, 2017

I’m using common build scripts using msbuild. I could do conditional branch to build some projects using dotnet build but then I rather add conditional step to call msbuild /t:Restore (as I did as the workaround anyway).

3reactions
davkeancommented, Aug 31, 2017

dotnet build will auto-restore, msbuild foo.csproj does not currently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NuGet auto package restore does not work with MSBuild
Nuget's Automatic Package Restore is a feature of the Visual Studio (starting in 2013), not MSBuild. You'll have to run nuget.exe restore if ......
Read more >
Troubleshooting NuGet Package Restore in Visual Studio
In this case, run msbuild -t:restore followed by msbuild , or use dotnet build (which restores packages automatically).
Read more >
How can I get MSBuild to restore any needed NuGet ...
3 answers. You could run this command: msbuild [sln file] -t:restore -p:RestorePackagesConfig=true , which could work on my side.
Read more >
Building solution from command line does not perform ...
We have to manually execute a NuGet restore process before building the solution. I would suggest that this is a defect, that the...
Read more >
Paket and the .NET SDK / .NET Core CLI tools (dotnet CLI ...
For example, if you open a Paket-enabled solution in Visual Studio 2017 then Visual Studio's background build will restore Paket dependencies automatically.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found