在 Teamcity 上构建混合解决方案(.NET Framework 和 .NET Core)时找不到包

Package not found while building a mixed solution (.NET Framework and .NET Core) on Teamcity

我有一个解决方案,其中包含针对 .NET Framework 4.6.1 的项目和一个针对 .NET Core 2.0 的项目。 此 .Net Core 项目引用了针对 .NET Framework 4.6.1 的项目。

在本地,使用 Visual Studio 2017 社区,我可以毫无问题地构建此解决方案。

我正在尝试使用以下步骤配置 TeamCity 构建:
1 - 清理包文件夹
2 - 获取包:runner type = NuGet Installer 和 Restore mode = Restore
3 - 恢复:dotnet 恢复 MyDonetCoreProject.csproj
4 - 构建解决方案:runner type = Visual Studio (sln) with VS 2017

我在编译 .NET Core 项目时遇到编译错误:

C:\Program Files\dotnet\sdk.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198, 5): Package Microsoft.AspNetCore, version 2.0.3 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.

我检查了我的 TeamCity 服务器上的路径 C:\Users\MyUser\.nuget\packages\microsoft.aspnetcore,我有一个文件夹 2.0.3

我的解决方案中没有对这个包的任何引用。什么在寻找这个包裹,它在寻找什么?

您为什么不使用 .NetCore CLI 命令来构建您的 .NetCore 应用程序或库。但与此同时,您应该在构建代理上同时拥有 .NetCore 2.0 和 .NET Framework 4.6.1。 我不熟悉 TeamCity CI,你可以试试这个,

而不是步骤 << 4 - 构建解决方案:runner type = Visual Studio (sln) with VS 2017 >>

dotnet build [.NetCore 的.csproj]

https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build?tabs=netcore2x

如果适用,您可以考虑使用 .net 标准(作为目标)而不是针对特定框架版本的目标。

我使用以下构建过程设法解决了这个问题:

1- Restore nugets : use restore mode "Restore (requires NuGet 2.7+) and specify all your packages sources in the field "Packages sources"(即使您的解决方案中有 NuGet.config 文件)并将 "Update mode" 设置为"Update via solution file"

2- 构建解决方案: 将 "Runner type" 设置为“.NET CLI (dotnet)”,并将 "command" 设置为 "build"

我不记得为什么我必须删除清洁步骤,但这对我有用。

就我而言,问题的原因是 TeamCity 中设置的旧版本 NuGet。我使用的版本 3.4.3 使用了不支持新的 csproj 文件的 MSBuild 14.0。这是我的构建代理的日志:

[Step 6/14] restore: Restoring NuGet packages for xxx.sln (7s)
[restore] NuGet command: C:\BuildAgent\plugins\nuget-agent\bin\JetBrains.TeamCity.NuGetRunner.exe C:\BuildAgent\tools\NuGet.CommandLine.3.4.3\tools\NuGet.exe restore C:\BuildAgent\work\ccbe07449ac24705\e2.sln -Source https://www.nuget.org/api/v2/ -Source http://xxx/guestAuth/app/nuget/v1/FeedService.svc/
[restore] Starting: C:\BuildAgent\temp\agentTmp\custom_script4470451835266630981.cmd
[restore] in directory: C:\BuildAgent\work\ccbe07449ac24705
[restore] JetBrains TeamCity NuGet Runner 2018.1.4015.0
[restore] Registered additional extensions from paths: C:\BuildAgent\plugins\nuget-agent\bin\plugins-3.3
[restore] Starting NuGet.exe 3.4.3.855 from C:\BuildAgent\tools\NuGet.CommandLine.3.4.3\tools\NuGet.exe
[restore] MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild.0\bin'.

将 NuGet 版本更改为 4.7.1 解决了问题。这个主题对我有帮助:https://github.com/dotnet/sdk/issues/2347