【问题标题】:Package not found while building a mixed solution (.NET Framework and .NET Core) on Teamcity在 Teamcity 上构建混合解决方案(.NET Framework 和 .NET Core)时找不到包
【发布时间】:2018-12-18 04:11:14
【问题描述】:

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

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

我正在尝试使用以下步骤配置 TeamCity 构建:
1 - 清理包文件夹
2 - 获取包:运行器类型 = NuGet 安装程序和还原模式 = 还原
3 - 恢复:dotnet restore MyDonetCoreProject.csproj
4 - 构建解决方案:运行器类型 = Visual Studio (sln) with VS 2017

编译 .NET Core 项目时出现编译错误:

C:\Program Files\dotnet\sdk\2.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198, 5):找不到包 Microsoft.AspNetCore,版本 2.0.3 .自 NuGet 还原后,它可能已被删除。否则,NuGet 还原可能仅部分完成,这可能是由于最大路径长度限制。

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

我的解决方案中没有对此包的任何参考。这个包在看什么?它在哪里看?

【问题讨论】:

  • 您是否只尝试了一步 - 使用运行器类型 Visual Studio 2017 重建解决方案?恢复应该是自动的。您不必执行两次还原。
  • 刚试过。我遇到了同样的错误。
  • 嗨@PMerlet,你解决问题了吗?
  • @rotman 我添加了一个答案来描述我当前使用的配置
  • @PMerlet 谢谢,但不幸的是它对我没有帮助 - 我在dotnet build 遇到了另一个问题,所以我不得不坚持使用 MSBuild。我将在这里发布我的解决方案。

标签: .net visual-studio .net-core teamcity


【解决方案1】:

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

而不是步骤 >

dotnet 构建 [.NetCore 的.csproj]

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

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

【讨论】:

    【解决方案2】:

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

    1- 恢复 nuget: 使用恢复模式“恢复(需要 NuGet 2.7+)并指定所有包源在“包源”字段中(即使您的解决方案中有 NuGet.config 文件)并将“更新模式”设置为“通过解决方案文件更新”

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

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

    【讨论】:

      【解决方案3】:

      在我的情况下,问题的原因是 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\14.0\bin'.
      

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

      【讨论】:

        猜你喜欢
        • 2022-07-14
        • 1970-01-01
        • 1970-01-01
        • 2016-10-24
        • 2017-08-03
        • 1970-01-01
        • 2019-06-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多