【问题标题】:Project dependency in solution file lets build fail解决方案文件中的项目依赖性导致构建失败
【发布时间】:2019-03-15 01:20:57
【问题描述】:

此存储库重现了我们面临的dotnet build 问题。

我们有一个针对 netcoreapp2.1 的 Web 应用程序。以及一个针对netstandard2.0net47 的类库。

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


    【解决方案1】:

    实际上,更多研究表明这个问题是known,并将在MSBuild 15.9 中修复。 上述线程中还提到了一个临时修复:将文件 Directory.Build.props 放在您的解决方案文件旁边,内容如下:

    <?xml version="1.0" encoding="utf-8"?>
    <Project>
      <PropertyGroup>
        <!-- Solution build dependencies are not project dependencies. https://github.com/Microsoft/msbuild/issues/3626 -->
        <AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>
      </PropertyGroup>
    </Project>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-18
      • 2018-09-18
      • 2018-02-10
      • 2020-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多