C# 创建netcore 3.0项目的NuGet包,该项目依赖于netstandard包

C# 创建netcore 3.0项目的NuGet包,该项目依赖于netstandard包,c#,.net-core,azure-devops,nuget,.net-standard,C#,.net Core,Azure Devops,Nuget,.net Standard,我的解决方案包括许多针对netcore 3.0的项目,其中一些项目参考了其他针对netstandard 2.0的nuget软件包 我想创建一个引用其他项目的项目的nuget包。在我的Azure DevOps管道中,我有以下任务来构建nupkg文件 - task: NuGetCommand@2 displayName: 'Create NuGet Package' inputs: command: 'pack' packagesToPack: 'Core.Hosting/C

我的解决方案包括许多针对
netcore 3.0
的项目,其中一些项目参考了其他针对
netstandard 2.0
的nuget软件包

我想创建一个引用其他项目的项目的nuget包。在我的Azure DevOps管道中,我有以下任务来构建
nupkg
文件

- task: NuGetCommand@2
  displayName: 'Create NuGet Package'
  inputs:
    command: 'pack'
    packagesToPack: 'Core.Hosting/Core.Hosting.nuspec'
    versioningScheme: 'off'
    includeReferencedProjects: true
    includeSymbols: true
接下来是一项任务,用于推送Azure Devops中的工件:

- task: NuGetCommand@2
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'reference-to-feed-is-removed'
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/develop'), eq('true', variables['PUSH_TO_NUGET']))
我的nuspec文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<package >
  <metadata>
    <id>Core Hosting</id>
    <version>1.0.0-prerelease-5.0.0</version>
    <title>Core Hosting</title>
    <authors>Core Team</authors>
    <owners>My Company a/s</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <projectUrl>project-url-removed/projectUrl>
    <description>Core backend components to interact with various services in Azure.</description>
    <copyright>Copyright 2020</copyright>
    <dependencies>
      <group targetFramework=".NETCoreApp3.0">
        <dependency id="AspNetCore.Firebase.Authentication" version="2.0.1"/>
        <dependency id="Autofac" version="4.9.4"/>
        <dependency id="Autofac.Extensions.DependencyInjection" version="5.0.1"/>
        <dependency id="Autofac.Mef" version="4.1.0"/>
        <dependency id="LinqKit.Core" version="1.1.17"/>
        <dependency id="Microsoft.ApplicationInsights.AspNetCore" version="2.12.0"/>
        <dependency id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.12.0"/>
        <dependency id="Microsoft.AspNetCore.Authentication.JwtBearer" version="3.0.0"/>
        <dependency id="Microsoft.EntityFrameworkCore" version="3.1.1"/>
        <dependency id="Microsoft.EntityFrameworkCore.Cosmos" version="3.1.1"/>
        <dependency id="Microsoft.EntityFrameworkCore.Relational" version="3.1.1"/>
        <dependency id="Microsoft.Extensions.DependencyModel" version="3.1.1"/>
        <dependency id="Microsoft.Extensions.Options" version="3.1.1"/>
        <dependency id="Swashbuckle.AspNetCore" version="5.0.0"/>
        <dependency id="System.ComponentModel.Composition" version="4.6.0"/>
        <dependency id="System.Composition.AttributedModel" version="1.3.0"/>
        <dependency id="Microsoft.ApplicationInsights" version="2.12.0"/>
        <dependency id="Microsoft.AspNetCore.Mvc.Core" version="2.2.5"/>
        <dependency id="Microsoft.Azure.KeyVault" version="3.0.4"/>
        <dependency id="Microsoft.Azure.Services.AppAuthentication" version="1.3.1"/>
        <dependency id="System.Configuration.ConfigurationManager" version="4.6.0"/>
        <dependency id="FirebaseAdmin" version="1.9.1"/>
        <dependency id="Microsoft.OpenApi" version="1.1.4"/>
        <dependency id="Swashbuckle.AspNetCore.SwaggerGen" version="5.0.0"/>
        <dependency id="Microsoft.Extensions.Configuration.Abstractions" version="3.1.1"/>
        <dependency id="SendGrid" version="9.12.0"/>
        <dependency id="MassTransit.Azure.ServiceBus.Core" version="6.0.0-develop.2244"/>
        <dependency id="Microsoft.Azure.WebJobs" version="3.0.14"/>
        <dependency id="System.ComponentModel.Composition" version="4.6.0"/>
      </group>
    </dependencies>
  </metadata>
</package>
在我的管道中运行NuGet restore任务时,我遇到了一些错误,抱怨兼容性问题,例如:

Package AspNetCore.Firebase.Authentication 2.0.1 is not compatible with netcoreapp3.0 (.NETCoreApp,Version=v3.0). Package AspNetCore.Firebase.Authentication 2.0.1 supports: netstandard2.0
所有错误都是相同的,依赖程序包X与netcoreapp3.0不兼容,因为它以netstandard2.0为目标

我觉得很奇怪,在VisualStudio中构建和恢复包时,它可以在本地工作,但在管道中运行时却不能。我还认为面向
netstandard2.0
的库将与
netcoreapp3.0
应用程序兼容


有没有办法让它在我的Azure Devops管道中运行,或者我把事情搞砸了?

这个问题可能是由过时版本的NuGet agent造成的。在使用NuGetCommand还原任务之前,可以尝试使用task并将代理设置为v5.x

- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 5.x'
  inputs:
    versionSpec: 5.x
    checkLatest: true
另一个可能的修复方法是使用dotnet还原而不是nuget还原

- task: DotNetCoreCLI@2
  inputs:
    command: restore
    projects: '**/*.csproj'
    feedsToUse: 'select'
    vstsFeed: 'azure feed'

有关更多详细信息,请参阅。

此处的快速查看:还表明标准2.0与核心3.0不兼容。你有没有试过让它成为标准2.1?制定什么标准2.1?我们从nuget.org(Netstandard2.0)获取了依赖项的dusins。为什么它在本地编译和工作,而不是在管道运行的虚拟ubuntu机器上?一篇文章指出:理论上,你根本不需要更改你的库。NETCore3.0支持.NET标准2.1,并且通过扩展,它支持.NET标准2.0。参考:至于为什么它在本地运行而不是在管道中运行,我们公司也面临同样的难题。然而,在我们的案例中,通常在直接从cmd中的MSBuild构建解决方案时(实际上是Azure管道),而不是从Visual studio构建解决方案时,我们会发现管道显示的错误,因此我们至少可以在本地复制它们。MSBuild和VisualStudioBuild应该几乎相同,只是在VisualStudio上有一些小的开销,但很明显这已经足够不同了。你是对的。它帮助我在管道中安装NugetToolInstaller。谢谢
- task: DotNetCoreCLI@2
  inputs:
    command: restore
    projects: '**/*.csproj'
    feedsToUse: 'select'
    vstsFeed: 'azure feed'