簡體   English   中英

如何從另一個 package 源安裝 nuget package

[英]How to install a nuget package from another package source in azure devops pipeline?

I'm trying to run some API test on azure, I've been able to run my artifacts before, but this specific task requires a package that is not in package source: nuget.org, it is a package from the company I work因為,所以當我運行管道時,我收到以下消息:

##[error]The nuget command failed with exit code(1) and error(NU1101: Unable to find package: name of package

我在創建項目時遇到了這個問題,所以我不得不添加 package 源,我該如何在管道上做到這一點?

您可以將nuget.config 文件放在列出 package 源的解決方案級別,例如

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="your-nuget" value="https://pkgs.dev.azure.com/example/_packaging/example-nuget/nuget/v3/index.json" />
    <add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
</configuration>

請注意,這也適用於 Visual Studio(如果您通過 VS 工具菜單手動添加,您應該能夠刪除額外的 package 源)。

然后根據您的 .net 的風格,這只是在構建之前有一個步驟來恢復包的情況, DotNetCoreCLI@2 (命令:restore feedsToUse:'config')或NuGetCommand@2 (命令:restore feedsToUse:'config') .

If the package you are talking about is custom package that you have created, then you need to first push the nuget package to Azure Artifact and then you can configure Azure DevOps pipeline to restore the package from Azure Artifact.

假設您使用 azure devops 的問題標簽,您必須在 yaml 文件中設置,恢復任務如下:

- task: DotNetCoreCLI@2
  displayName: 'Restore Nuget Packages'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'select'
    vstsFeed: '<your key>'

暫無
暫無

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

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