nuget - 无法让 Pipeline 将自定义 NuGet 服务器与 Azure DevOps

我的解决方案使用来自官方 NuGet 服务器和私有(private) NuGet 服务器的包。我正在尝试配置我的构建管道以从两个位置恢复包,但不断出现 NuGet 恢复构建错误,看起来它正在尝试从公共(public) NuGet 服务器恢复我的私有(private)包,因此失败是可以理解的。

我不知道我还应该做什么。似乎 Azure DevOps 中没有可以为 NuGet 还原步骤进行的设置,因为看起来现在所有这些都在 YAML 文件中配置。任何关于我可能做错了什么或我还可以尝试什么的建议都将不胜感激。

我的解决方案中的 NuGet.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <!-- Allow NuGet to download missing packages -->
    <add key="enabled" value="True" />
    <!-- Automatically check for missing packages during build in Visual Studio -->
    <add key="automatic" value="True" />
  </packageRestore>
  <packageSources>
    <add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
    <add key="Private" value="http://privatenuget.net:8080/nuget" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
</configuration>

Pipelines 使用的我的 YAML 文件:

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

pool:
  vmImage: 'VS2017-Win2016'

variables:
  solution: 'MyProject.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@0

- task: NuGetCommand@2
  inputs:
    nugetConfigPath: 'MyProject\NuGet.config'
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

我在构建的 NuGetCommand 步骤上遇到的错误:

The nuget command failed with exit code(1) and error(Errors in packages.config projects
    NU1000: Unable to find version '1.1.5' of package 'MyPackage'.
      https://api.nuget.org/v3/index.json: Package 'MyPackage' is not found on source 'https://api.nuget.org/v3/index.json'.)
Packages failed to restore

最佳答案

您的 YML 文件不正确,您必须添加 feedsToUse: config

- task: NuGetCommand@2
  displayName: 'Nuget Restore'
  inputs:
    restoreSolution: '$(solution)'
    feedsToUse: config
    nugetConfigPath: nuget.config

关于nuget - 无法让 Pipeline 将自定义 NuGet 服务器与 Azure DevOps 构建一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53052678/

相关文章:

git - 如何通过 GitHub 的 API 进行 cherry-pick

reactjs - 保存时 React 和 Visual Studio Code 有问题

react-native - React native如何改变WebView的背景色?

laravel - 如何在 Laravel 迁移中的特定列之后订购多个新列

python - 如何修复-没有这样的表 : main. auth_user__old

matlab - 根据给定矩阵的对角线和反对角线创建新矩阵

html-table - 表中 1.5 的 Colspan

apache-kafka - 如何批量处理最大大小的 KStream 或回退到时间窗口?

python - Pandas - 从索引中提取月份和年份

google-colaboratory - 在 Google Colab notebook 上安装