【问题标题】:Azure Pipelines NugetCommand Task failing with error - Package Microsoft.EntityFrameworkCore.SqlServer 5.0.2 is not compatible with net50Azure Pipelines NugetCommand 任务失败并出现错误 - 包 Microsoft.EntityFrameworkCore.SqlServer 5.0.2 与 net50 不兼容
【发布时间】:2021-04-22 21:41:20
【问题描述】:

我有一个 .NET 5.0 WebApi 解决方案,我正在尝试使用 yml 文件创建构建管道。我正在使用我们的代理池,它有一个具有以下功能的 Windows 代理。

操作系统:Windows_NT -> 操作系统架构:X64 -> 在代理中也安装了 .NET 5 SDK

这是我的 yml 文件。

steps:
- task: UseDotNet@2
  inputs:
    packageType: sdk
    version: 5.x

- task: NuGetToolInstaller@1
  displayName: 'NuGet Installer'
  inputs:
    versionSpec: 5.x

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

但这会在“NuGetCommand”任务中引发大量错误,例如

##[error]The nuget command failed with exit code(1) and error(NU1202: Package Microsoft.EntityFrameworkCore.SqlServer 5.0.2 is not compatible with net50 (.NETFramework,Version=v5.0). Package Microsoft.EntityFrameworkCore.SqlServer 5.0.2 supports: netstandard2.1 (.NETStandard,Version=v2.1)
NU1202: Package Npgsql.EntityFrameworkCore.PostgreSQL 5.0.2 is not compatible with net50 (.NETFramework,Version=v5.0). Package Npgsql.EntityFrameworkCore.PostgreSQL 5.0.2 supports: netstandard2.1 (.NETStandard,Version=v2.1)
NU1202: Package Oracle.ManagedDataAccess.Core 3.21.1 is not compatible with net50 (.NETFramework,Version=v5.0). Package Oracle.ManagedDataAccess.Core 3.21.1 supports: netstandard2.1 (.NETStandard,Version=v2.1)

任何帮助将不胜感激。

【问题讨论】:

    标签: yaml azure-pipelines .net-5


    【解决方案1】:

    请按照以下步骤操作:

    1)尝试在nuget restore任务下使用noCache: true

    steps:
    - task: NuGetCommand@2
      displayName: 'NuGet restore'
      inputs:
        noCache: true
    

    2) 相反,您可以使用dotnet restore taskno cache:true 来恢复您的项目。

    此外,如果这不起作用,请与我们共享整个 csproj 文件以解决问题。

    【讨论】:

    • NoCache 不起作用。 Dotnet 还原任务有效,但执行时间较长。如果我使用“我们的代理池”使用 dotnet restore,则应该在 5 分钟内完成的构建现在需要大约 19 分钟。虽然它与“windows-latest”池一起工作得更快,但是我们的 SonarQube 任务将无法工作(令牌错误)。这是主项目的项目文件内容。 <Project Sdk="Microsoft.NET.Sdk.Web"><PropertyGroup> <TargetFramework>net5.0</TargetFramework></PropertyGroup><ItemGroup> <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.17.0" />
    • 请检查您的项目是否选择了正确的分支,第二,不确定为什么最新的nuget.exe不起作用,或者您可以在NuGetToolInstaller下声明nuget.exe的具体版本任务,使用5.9.1 或另一个5.7.1。您也可以添加system.debug :true 以查看详细的还原日志。
    • 另外,由于错误和你的csproj文件,没有引用Npgsql.EntityFrameworkCore.PostgreSQL,请确保所有项目都在同一个分支下。 Besdies,确保您检查了 nuget.org 并且没有使用其他 nuget.config 文件。
    • 由于评论文本限制,我在发布时要删除 Npgsql 引用。我没有任何其他配置文件。让我检查一下 system.debug: true。
    • 我终于使用了我们的代理池,使用了 DotNetCoreCLI@2 任务。现在它构建成功了,但花了大约 20 分钟。然后我从 Dotnet Build 任务(projects 属性)中删除了 */.csproj 并给出了该任务。它执行得更快。它仍然构建了所有项目。我们真的需要给projects: '**/*.csproj'吗?
    猜你喜欢
    • 1970-01-01
    • 2020-02-23
    • 2019-07-09
    • 2016-11-09
    • 2019-10-25
    • 1970-01-01
    • 2021-08-27
    • 2019-09-05
    • 2019-03-12
    相关资源
    最近更新 更多