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

10

我正在尝试使用NuGet Installer TeamCity构建步骤来恢复.NET Core解决方案的NuGet包。'MSBuild自动检测'选择了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 步骤中,我像在这个 SO 答案 中描述的那样手动选择了 MSBuildTools 版本: enter image description here

但是我没有找到类似的设置适用于 'NuGet Installer' 步骤。我有什么遗漏吗?


尝试从命令行步骤调用 dotnet restore - hkarask
4个回答

15

我成功地通过指定-MSBuildPath命令行参数来解决了这个问题:

输入图片描述


4
对于那些喜欢复制和粘贴的人,可以使用“-MSBuildPath”参数并填入“%MSBuildTools15.0_x64_Path%”。 - ojintoad

4

正如@PeterLai所说,NuGet版本是正确的查找位置。

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

我从3.4.3升级到了4.6.2,然后重新构建。

enter image description here

现在它可以找到我的Visual Studio 2017 msbuild,版本为15!

之前:

NuGet命令:D:\...\NuGet.CommandLine.3.4.3\tools\NuGet.exe restore D:\...\proj.sln
...
MSBuild自动检测:使用来自'C:\Program Files(x86)\MSBuild\14.0\bin'的msbuild版本“14.0”。

之后:

NuGet命令:D:\...\NuGet.CommandLine.4.6.2\tools\NuGet.exe restore D:\...\proj.sln
...
MSBuild自动检测:使用来自'C:\Program Files(x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin'的msbuild版本“15.5.180.51428”。

1

两件事情,

可能是因为它是从文件夹Starting NuGet.exe 4.1.0.2450 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.4.1.0\tools\NuGet.exe运行的,而不是在源代码目录中如您所期望的那样。

您的项目中是否有一个packages.config文件?


没有package.config文件,那是.NET Core。如果我在本地运行nuget restore My.sln命令,它会检测到有效的MSBuild v15.0: MSBuild自动检测:使用来自'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin'的msbuild版本“15.1.1012.6693”。 - Serhii Shushliapin
你确定使用解决方案文件能行吗?我一直都用 packages.config。https://learn.microsoft.com/zh-cn/nuget/consume-packages/package-restore - user4433284

0

如果您只使用.NET Core / .NET Standard项目(“基于SDK”的csproj),则无需使用nuget.exe进行还原,而是可以创建一个调用Restore目标的msbuild调用:

msbuild /t:Restore the.sln

这也适用于非核心/标准项目(经典的csproj),如果它们使用PackageReference包管理格式: 输入图像描述

这是一个不错的选择,我已经在我的本地脚本中尝试过了。不幸的是,它只能在文件夹c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe中使用VS 2017 MSBuild才能正常工作。如果我切换到MSBuild BuildTools (c\:Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe),这是我想要在我的CI服务器上使用的,它会出现错误The target "Restore" does not exist in the project... - Serhii Shushliapin
是的,构建工具缺少一些功能 - 但即使您成功使用nuget restore,也无法使用这些功能进行构建。请参见https://github.com/Microsoft/msbuild/issues/1697。 - Martin Ullrich
有一个解决方案。对我来说可以正常工作。 - Serhii Shushliapin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接