【问题标题】:How to set the MSBuild verision for TeamCity NuGet Installer?如何为 TeamCity NuGet 安装程序设置 MSBuild 版本?
【发布时间】:2017-11-15 06:44:05
【问题描述】:

我正在尝试使用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 步骤,我手动选择 MSBuildTools 版本,如 SO answer 中所述:

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

【问题讨论】:

  • 尝试从命令行步骤调用dotnet restore

标签: msbuild nuget teamcity .net-core


【解决方案1】:

我设法通过指定 -MSBuildPath command line parameter 来克服这个问题:

【讨论】:

  • 对于喜欢复制和粘贴的人-MSBuildPath "%MSBuildTools15.0_x64_Path%"
【解决方案2】:

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

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

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

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

之前:

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 命令: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”。

【讨论】:

    【解决方案3】:

    两件事,

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

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

    【讨论】:

    • 没有 package.config 文件,就是 .NET Core。如果我在本地运行 nuget restore My.sln 命令,它会检测到有效的 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'.
    • 您确定可以使用解决方案文件,我一直使用 packages.config,docs.microsoft.com/en-us/nuget/consume-packages/package-restore
    【解决方案4】:

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

    msbuild /t:Restore the.sln
    

    这也适用于使用PackageReference 包管理格式的非核心/标准项目(经典csproj):

    【讨论】:

    • 这是一个不错的选择,我用本地脚本尝试过。不幸的是,在我使用位于文件夹 c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe 中的 VS 2017 MSBuild 时才有效。如果我切换到我想在我的 CI 服务器上使用的 MSBuild BuildTools (c\:Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe),它会失败并出现错误 The target "Restore" does not exist in the project...
    • 是的,构建工具缺少一些功能 - 但即使您让 nuget restore 正常工作,您也无法使用这些功能进行构建。请参阅 github.com/Microsoft/msbuild/issues/1697
    • 有一个workaround。对我来说很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 2016-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多