简体   繁体   English

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

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

I have a solution that contains projects targeting .NET Framework 4.6.1 and a single project targeting .NET Core 2.0.我有一个解决方案,其中包含面向 .NET Framework 4.6.1 的项目和一个面向 .NET Core 2.0 的项目。 This .Net Core project has references to projects targeting .NET Framework 4.6.1.此 .Net Core 项目引用了面向 .NET Framework 4.6.1 的项目。

Locally, using Visual Studio 2017 Community, I can build this solution without any issue.在本地,使用 Visual Studio 2017 社区,我可以毫无问题地构建此解决方案。

I am trying to configure a TeamCity build using the following steps :我正在尝试使用以下步骤配置 TeamCity 构建:
1 - Clean packages folder 1 - 清理包文件夹
2 - Get packages : runner type = NuGet Installer and Restore mode = Restore 2 - 获取包:运行程序类型 = NuGet 安装程序和恢复模式 = 恢复
3 - Restore : dotnet restore MyDonetCoreProject.csproj 3 - 恢复:dotnet restore MyDonetCoreProject.csproj
4 - Build solution : runner type = Visual Studio (sln) with VS 2017 4 - 构建解决方案:运行器类型 = Visual Studio (sln) with VS 2017

I get a compilation error when compiling my .NET Core project :编译我的 .NET Core 项目时出现编译错误:

C:\\Program Files\\dotnet\\sdk\\2.1.301\\Sdks\\Microsoft.NET.Sdk\\targets\\Microsoft.PackageDependencyResolution.targets(198, 5): Package Microsoft.AspNetCore, version 2.0.3 was not found. C:\\Program Files\\dotnet\\sdk\\2.1.301\\Sdks\\Microsoft.NET.Sdk\\targets\\Microsoft.PackageDependencyResolution.targets(198, 5):未找到包 Microsoft.AspNetCore,版本 2.0.3。 It might have been deleted since NuGet restore.它可能在 NuGet 还原后已被删除。 Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.否则,NuGet 还原可能仅部分完成,这可能是由于最大路径长度限制。

I checked the path C:\\Users\\MyUser\\.nuget\\packages\\microsoft.aspnetcore on my TeamCity server and I have a folder 2.0.3 .我检查了我的 TeamCity 服务器上的路径C:\\Users\\MyUser\\.nuget\\packages\\microsoft.aspnetcore并且我有一个文件夹2.0.3

I don't have any reference in my solution to this package.我在这个包的解决方案中没有任何参考。 What is looking to this package and where is it looking ?这个包在看什么,它在哪里看?

Why do not you use .NetCore CLI command to build your .NetCore app or library.为什么不使用 .NetCore CLI 命令来构建 .NetCore 应用程序或库。 but at the same time, you should have both .NetCore 2.0 and .NET Framework 4.6.1 on build Agent.但同时,您应该在构建代理上同时拥有 .NetCore 2.0 和 .NET Framework 4.6.1。 I am not familiar with TeamCity CI, you could try this,我对 TeamCity CI 不熟悉,你可以试试这个,

instead of step << 4 - Build solution : runner type = Visual Studio (sln) with VS 2017 >>而不是步骤 << 4 - 构建解决方案:运行器类型 = Visual Studio (sln) with VS 2017 >>

dotnet build [.csproj of .NetCore] dotnet build [.NetCore 的.csproj]

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

You could consider using .net standard (as target) instead of having tagets to specific framework version if applicable.如果适用,您可以考虑使用 .net 标准(作为目标)而不是使用特定框架版本的目标。

I managed to fixed this issue using the following build process :我设法使用以下构建过程解决了这个问题:

1- Restore nugets : use restore mode "Restore (requires NuGet 2.7+) and specify all your packages sources in the field "Packages sources" (even if you have a NuGet.config file in your solution) and set "Update mode" to "Update via solution file" 1- 还原 nugets :使用还原模式“还原(需要 NuGet 2.7+)并在“包源”字段中指定所有包源(即使您的解决方案中有 NuGet.config 文件)并将“更新模式”设置为“通过解决方案文件更新”

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

I cannot remember why I had to remove the cleaning step but this works for me.我不记得为什么我必须删除清洁步骤,但这对我有用。

In my case the reason of the problem was the old version of NuGet set in TeamCity.在我的情况下,问题的原因是 TeamCity 中设置的旧版本 NuGet。 I used version 3.4.3 which used MSBuild 14.0 which does not support new csproj files.我使用了 3.4.3 版本,它使用了不支持新 csproj 文件的 MSBuild 14.0。 Here is the log from my build agent:这是我的构建代理的日志:

[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'.

Changing NuGet version to 4.7.1 solved the problem.将 NuGet 版本更改为 4.7.1 解决了该问题。 This topic helped me: https://github.com/dotnet/sdk/issues/2347这个话题对我有帮助: https : //github.com/dotnet/sdk/issues/2347

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Cake 构建脚本在 Azure Devops 中使用混合 .NET 核心和框架解决方案失败 - Cake build script fails in Azure Devops with mixed .NET core and framework solution 在同一解决方案文件中同时包含 .NET Framework 和 .NET Core 项目的 Azure DevOps 中构建 .sln - Building .sln in Azure DevOps that has both .NET Framework and .NET Core projects in the same solution file .Net Framework和.Net Core在同一解决方案中 - .Net Framework and .Net Core in same solution 带有 TeamCity 和 SonarQube 的依赖检查器,用于 .Net Framework 和 .Net Core - Dependency Checker with TeamCity and SonarQube for .Net Framework and .Net Core 我的整个解决方案是否必须是 .NET Framework 而不是 .NET Core,因为我使用需要 .NET Framework 的 NuGet 包? - Does my whole solution have to be .NET Framework rather than .NET Core just because I use a NuGet package that needs the .NET Framework? .Net Core项目中的.Net Framework Nuget软件包 - .Net Framework Nuget Package in .Net Core Project 在.net核心和.net框架中使用.net标准包 - Using a .net standard package in .net core and .net framework 在.net core 2解决方案中引用.net 4.7框架程序集 - Referencing .net 4.7 framework assemblies in .net core 2 solution 无法命令行构建混合解决方案(.NET Framework与.NET标准) - Unable to Command-Line Build a Mixed Solution (.NET Framework with .NET Standard) .NET Core == .NET Framework 5 吗? - Is .NET Core == .NET Framework 5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM