Paket icon indicating copy to clipboard operation
Paket copied to clipboard

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

Open Katulus opened this issue 9 years ago • 8 comments

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.

Katulus avatar Aug 31 '17 10:08 Katulus

@enricosada @davkean is this expected? I thought build is calling restore now?

forki avatar Aug 31 '17 10:08 forki

maybe try dotnet build PaketRestoreTest.sln?

matthid avatar Aug 31 '17 11:08 matthid

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).

Katulus avatar Aug 31 '17 18:08 Katulus

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

davkean avatar Aug 31 '17 22:08 davkean

Closing because this is an external request as @davkean explained.

matthid avatar Sep 02 '17 11:09 matthid

@matthid I don't understand how this is external request. Can you explain it a little? I thought that Paket adds extra tasks to build pipeline to do the restore. If msbuild foo.csproj builds the project perfectly fine except for auto-restore that should have been added by Paket then I see this as a Paket issue, not MSBuild issue.

Katulus avatar Sep 03 '17 18:09 Katulus

We use the same pipeline as nuget and execute "restore" at the same places. So as soon as the msbuild/sdk team adds support for calling msbuild solution.sln paket would work as well. Does that make sense?

matthid avatar Sep 03 '17 18:09 matthid

Ok, now it makes sense. dotnet build calls dotnet restore automatically so packages are restored. MSBuild does not do anything like that so it has to be called explicitly. Thanks for the explanation.

Katulus avatar Sep 03 '17 18:09 Katulus