如何为 TeamCity NuGet 安装程序设置 MSBuild 版本?

How to set the MSBuild verision for TeamCity NuGet Installer?

我正在尝试使用 NuGet Installer TeamCity 构建步骤恢复 .NET Core 解决方案的 NuGet 包。 'MSBuild auto-detection' 选择 MSBuild v4.0 而不是 .NET Core 项目所需的 v15.0:

[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

这导致在包恢复后运行的 'MSBuild' TeamCity 步骤中出现编译错误:

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

对于 'MSBuild' TeamCity 步骤,我手动选择 MSBuildTools 版本,如 SO answer 中所述:

但我没能找到 'NuGet Installer' 步骤的类似设置。我错过了什么吗?

2 件事,

可能是因为它是 运行 它来自文件夹 Starting NuGet.exe 4.1.0.2450 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.4.1.0\tools\NuGet.exe,以及不在您期望的源代码目录中。

您的项目中有 packages.config 文件吗?

如果您仅使用 .NET Core / .NET Standard 项目 ("SDK-based" csproj),则无需使用 nuget.exe 进行恢复,但可以创建调用 Restore 目标:

msbuild /t:Restore the.sln

这也适用于 non-core/standard 项目(经典 csproj),如果它们使用 PackageReference 包管理格式:

我设法克服了这个指定 -MSBuildPath command line parameter:

正如@PeterLai 所说,nuget 版本是正确的地方。

所以,因为我在这里遇到了同样的问题,所以我更新了 Teamcity/Administration/Integrations/Tools 中的 Nuget。

我从 3.4.3 移动到 4.6.2,然后重新构建。

现在它找到了我的 visual studio 2017 msbuild,版本 15!

之前:

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.0\bin'.

之后:

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 Studio17\BuildTools\MSBuild.0\bin'.