创建依赖于netstandard程序包的netcore 3.0项目的NuGet程序包

问题描述 投票:2回答:1

我的解决方案包含许多针对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>

我想在我的另一个netcore 3.0项目中使用此nuget程序包,通过从Nuget Package Manager添加它,可以在本地完美地工作。一切都按预期方式构建和运行,但当我尝试运行此项目的管道时除外:

trigger:
  branches:
    include:
      - "*"

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'
steps:

- task: UseDotNet@2
  displayName: 'Install dotnet 3.x SDK'
  inputs:
    packageType: sdk
    version: '3.x'
    includePreviewVersions: true
    installationPath: $(Agent.ToolsDirectory)/dotnet

- task: NuGetCommand@2
  displayName: 'Restore NuGet packages'
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'select'
    vstsFeed: 'feed-id-removed'

- script: dotnet test --filter FullyQualifiedName~UnitTests
  displayName: "Run Unit Tests"

- script: dotnet publish Example.Service.Host/Example.Service.Host.csproj --configuration Release -o 'output/publish' --runtime linux-x64 -f netcoreapp3.0
  displayName: "Build Example.Service"

- task: CopyFiles@2
  inputs:
    SourceFolder: ''
    Contents: 'Dockerfile'
    TargetFolder: 'output'

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: 'output'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: 'Example.Service/$(Build.BuildId).zip'
    replaceExistingArchive: true

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: 'Example.Service/$(Build.BuildId).zip'
    ArtifactName: 'drop'

在我的管道中运行NuGet还原任务,我在抱怨诸如此类的兼容性问题时出错:

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。

我发现我很奇怪,它在Visual Studio中构建和还原包时在本地工作,但是当我从管道中运行它时却不能。我还认为针对netstandard2.0的库将与netcoreapp3.0应用兼容

有没有一种方法可以使它在我的Azure Devops管道中工作,或者我花了很多时间?

c# .net-core azure-devops nuget .net-standard
1个回答
0
投票

该问题可能是由于NuGet代理的版本过旧引起的。您可以尝试使用NuGet Install Tool任务并将代理设置为v5.x,然后再使用NuGetCommand还原任务。

© www.soinside.com 2019 - 2024. All rights reserved.