如何为TeamCity NuGet安装程序设置MSBuild验证?

如何为TeamCity NuGet安装程序设置MSBuild验证?,msbuild,nuget,teamcity,.net-core,Msbuild,Nuget,Teamcity,.net Core,我正在尝试使用TeamCity构建步骤恢复.NET核心解决方案的NuGet包。“MSBuild自动检测”选择MSBuild v4.0,而不是.NET核心项目所需的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-detec

我正在尝试使用TeamCity构建步骤恢复.NET核心解决方案的NuGet包。“MSBuild自动检测”选择MSBuild v4.0,而不是.NET核心项目所需的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版本,如下所述:

但是我没有为“NuGet安装程序”步骤找到类似的设置。我错过了什么吗?

2件事

这可能是因为它是从C:\TeamCity\buildAgent\tools\NuGet.CommandLine.4.1.0\tools\NuGet.exe中启动NuGet.exe 4.1.0.2450的文件夹运行的,而不是像您预期的那样在源代码目录中


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

如果您仅使用.NET Core/.NET标准项目(“基于SDK的”csproj),则不需要使用
nuget.exe
进行还原,但可以创建调用
还原
目标的msbuild调用:

msbuild /t:Restore the.sln
这也适用于非核心/标准项目(经典csproj),如果它们使用
PackageReference
包管理格式:

我通过指定
-MSBuildPath
成功地克服了这个问题:


正如@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\14.0\bin'. NuGet命令:D:\…\NuGet.CommandLine.3.4.3\tools\NuGet.exe还原D:\…\proj.sln ... MSBuild自动检测:使用“C:\Program Files(x86)\MSBuild\14.0\bin”中的MSBuild版本“14.0”。 之后:

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'. NuGet命令:D:\…\NuGet.CommandLine.4.6.2\tools\NuGet.exe还原D:\…\proj.sln ...
MSBuild自动检测:使用“C:\Program Files(x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin”中的MSBuild版本“15.5.180.51428”。没有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”。
。如果确实可以使用解决方案文件,我始终使用packages.config,这是一个很好的选择,我用本地脚本进行了尝试。不幸的是,仅当我使用位于文件夹
c:\ProgramFiles(x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe
中的VS 2017 MSBuild时,它才起作用。如果我切换到要在CI服务器上使用的MSBuild BuildTools(
c\:程序文件(x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe
),它将失败,并出现错误
目标“还原”项目中不存在
…是的,构建工具缺少一些功能-但是即使您让nuget restore开始工作,您也无法使用这些功能进行构建。。看,有一个。对我来说效果很好。对于那些喜欢复制和粘贴
-MSBuildPath“%MSBuildTools15.0\u x64\u Path%”的人,请尝试从命令行步骤调用
dotnet restore