我希望有人就使用 Teamcity 构建和发布同时包含 .NET Core/standard 2.0 项目和 .NET Framework 4.6.x 项目的解决方案的最佳方式提供一些建议。
目前,我可以构建项目、运行测试,但我找不到通过 dotnet-cli 发布它的方法。我们有一个比较大的解决方案,大约有 75 个 .NET core/standard 项目和 5 个或一些框架项目。在我们的解决方案上运行 dotnet publish 会导致 .NET Framework 项目出现以下错误:
error: C:\Program Files\dotnet\sdk\2.0.3\Microsoft.Common.CurrentVersion.targets(3861,5): error MSB4062: The "Microsoft.Build.Tasks.ResolveManifestFiles" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
如果 cli 可以尝试忽略发布 .NET Framework 项目,那将是理想的,但这似乎是不可能的。我正在考虑编写一个 powershell 脚本来检查我们解决方案中所有 csproj 文件的适当 TargetFramework 值(即 netstandard2.0/netcoreapp2.0),并单独发布它们,但也许有人知道更好的方法?
最佳答案
如果有人遇到同样的问题,您需要按照@nvoigt 的建议重组您的 csproj 文件。
您可以按照帖子 Old csproj to new csproj 中描述的步骤进行操作
您可以开始清除您的 csproj 文件并从以下格式开始。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net462</TargetFramework> // if your target is 4.6.2
</PropertyGroup>
</Project>
现在您可以添加剩余的依赖项,如下所示。
...
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.4" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.KeyVault" Version="2.0.6" />
<PackageReference Include="NLog" Version="4.7.5" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.5" />
</ItemGroup>
...
您可以在帖子中找到更多详细信息。
关于.net-core - Dotnet publish with .NET core 2.0 和 .NET Framework 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47919434/