10
votes

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?

4
Try calling dotnet restore from Command Line stephkarask

4 Answers

12
votes

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

enter image description here

3
votes

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'.
1
votes

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?

0
votes

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