【发布时间】:2019-03-15 01:20:57
【问题描述】:
此存储库重现了我们面临的dotnet build 问题。
我们有一个针对 netcoreapp2.1 的 Web 应用程序。以及一个针对netstandard2.0 和net47 的类库。
Web 应用程序提供了一个 Web API,我们使用NSwag 来生成相应的 C# 客户端。 因此构建过程必须先构建 Web 应用程序,然后再构建类库。
但是,虽然它在 Visual Studio 中构建良好,但在命令行上却失败了:
$ dotnet build dotnetBuildIssue.sln
Microsoft (R) Build Engine version 15.8.166+gd4e8d81a88 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 42.36 ms for C:\work\tmp\dotnetBuildIssue\ClassLib\ClassLib.csproj.
Restore completed in 63.56 ms for C:\work\tmp\dotnetBuildIssue\WebApp\WebApp.csproj.
WebApp -> C:\work\tmp\dotnetBuildIssue\WebApp\bin\Debug\netcoreapp2.1\WebApp.dll
C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.app\2.1.1\build\netcoreapp2.1\Microsoft.AspNetCore.App.targets(14,5): error : This version of Microsoft.AspNetCore.App is only compatible with the netcoreapp2.1 target framework. Please target netcoreapp2.1 or choose a version of Microsoft.AspNetCore.App compatible with netstandard2.0. [C:\work\tmp\dotnetBuildIssue\WebApp\WebApp.csproj]
C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.app\2.1.1\build\netcoreapp2.1\Microsoft.AspNetCore.App.targets(14,5): error : This version of Microsoft.AspNetCore.App is only compatible with the netcoreapp2.1 target framework. Please target netcoreapp2.1 or choose a version of Microsoft.AspNetCore.App compatible with net47. [C:\work\tmp\dotnetBuildIssue\WebApp\WebApp.csproj]
Build FAILED.
在我看来,dotnet 使用类库的 TargetFramework net47 来编译 Web 应用程序,尽管我们只设置了一个项目
强制执行特定构建顺序的依赖项。
我们真正的解决方案包含超过 15 个项目,因此添加一个构建任务
VSTS Azure DevOps 构建管道中的每个项目
不是最优的。
我们本来希望不必在解决方案文件中定义依赖关系,但我们还没有在 .csproj 文件中找到一种可行的方法。
欢迎任何提示如何在没有直接参考的情况下强制执行项目的特定顺序(我们针对不同的框架)。
我已在GitHub 发布了一份复刻版。
【问题讨论】:
标签: c# .net build msbuild dependencies