10

I'm trying to restore NuGet packages for a .NET Core solution using NuGet Installer TeamCity build step. The 'MSBuild auto-detection' chooses MSBuild v4.0 instead of v15.0 which is required for .NET Core projects:

[15:41:53][restore] Starting NuGet.exe 4.1.0.2450 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.4.1.0\tools\NuGet.exe
[15:41:53][restore] MSBuild auto-detection: using msbuild version '4.0' from 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319'.
[15:41:53][restore] Nothing to do. None of the projects in this solution specify any packages for NuGet to restore.
[15:41:53][restore] Process exited with code 0

This leads to the compilation error in the 'MSBuild' TeamCity step that runs after the package restoring:

Assets file 'C:\TeamCity\...\MyProj\obj\project.assets.json' not found.
Run a NuGet package restore to generate this file.

For the 'MSBuild' TeamCity step I choose the MSBuildTools version manually as described in this SO answer: enter image description here

But I didn't manage to find the similar setting for the 'NuGet Installer' step. Am I missing something?

Serhii Shushliapin
  • 2,528
  • 2
  • 15
  • 32

4 Answers4

14

I managed to overcome this specifying the -MSBuildPath command line parameter:

enter image description here

Serhii Shushliapin
  • 2,528
  • 2
  • 15
  • 32
4

As @PeterLai said, nuget version is the right place to look.

So, because I had the same problem here, I updated Nuget inside Teamcity / Administration / Integrations / Tools.

I moved from 3.4.3 to 4.6.2, and just rebuild.

enter image description here

Now it finds my visual studio 2017 msbuild, version 15!

BEFORE:

NuGet command: D:\...\NuGet.CommandLine.3.4.3\tools\NuGet.exe restore D:\...\proj.sln
...
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.

AFTER:

NuGet command: D:\...\NuGet.CommandLine.4.6.2\tools\NuGet.exe restore D:\...\proj.sln
...
MSBuild auto-detection: using msbuild version '15.5.180.51428' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin'.
foxontherock
  • 1,776
  • 1
  • 13
  • 16
1

2 things,

It might be because it's running it from the folder Starting NuGet.exe 4.1.0.2450 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.4.1.0\tools\NuGet.exe, and not in the source code directory as you'd expect.

Have you got a packages.config file in your project?

  • There is no package.config file, that's .NET Core. If I run the `nuget restore My.sln` command locally, it detects the valid MSBuild v15.0: `MSBuild auto-detection: using msbuild version '15.1.1012.6693' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin'.`. – Serhii Shushliapin Jun 13 '17 at 13:38
  • You sure that works with a solution file, I've always used a packages.config, https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore –  Jun 13 '17 at 13:43
0

If you are only using .NET Core / .NET Standard projects ("SDK-based" csproj), you don't need to restore with nuget.exe but can create an msbuild invocation that calls the Restore target:

msbuild /t:Restore the.sln

This also applies to non-core/standard projects (classic csproj) if they use the PackageReference package management format: enter image description here

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • That's a good option, I tried it with my local scripts. Unfortunately it works _only_ if I use VS 2017 MSBuild located in the folder `c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe`. If I switch to MSBuild **BuildTools** (`c\:Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe`) which I want to be used on my CI server, it fails with error `The target "Restore" does not exist in the project`... – Serhii Shushliapin Jun 13 '17 at 13:59
  • Yes the build tools lack a few features - but you won't be able to build with those even if you get nuget restore to work.. see https://github.com/Microsoft/msbuild/issues/1697 – Martin Ullrich Jun 13 '17 at 15:18
  • There is a [workaround](https://github.com/Microsoft/msbuild/issues/1697#issuecomment-307667694). Works fine to me. – Serhii Shushliapin Jun 13 '17 at 15:35