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

Created on 31 Aug 2017  路  8Comments  路  Source: fsprojects/Paket

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.

Most helpful comment

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

All 8 comments

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

maybe try dotnet build PaketRestoreTest.sln?

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

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

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

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

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?

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.

Was this page helpful?
0 / 5 - 0 ratings