簡體   English   中英

創建依賴於 netstandard 包的 netcore 3.0 項目的 NuGet 包

[英]Create a NuGet package of a netcore 3.0 project which is dependent upon netstandard packages

我的解決方案包括許多針對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添加它可以在本地完美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 管道中工作,或者我把時間搞砸了?

該問題可能是由過時版本的 NuGet 代理引起的。 在使用 NuGetCommand 還原任務之前,您可以嘗試使用NuGet 安裝工具任務並將代理設置為 v5.x。

- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 5.x'
  inputs:
    versionSpec: 5.x
    checkLatest: true

另一種可能的解決方法是使用 dotnet restore 而不是 nuget restore。

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

您可以參考此線程以獲取更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM