简体   繁体   中英

Why is my Azure Dev Ops Pipeline failing to restore a package?

I'm using Azure Dev Ops to work with my ASP.NET Core web application. I'm setting up a pipeline but I'm getting errors. The errors are coming from a package restore issue since my application uses the KendoUI library I have to create a service connection for the private NuGet packages that are required. Having done that, the build still fails and I was wondering what is going wrong?

Error Message

[error]The nuget command failed with exit code(1) and error(NU1102: Unable to find package Telerik.UI.for.AspNet.Core with version (>=

2019.2.619) - Found 1 version(s) in NuGetOrg [ Nearest version: 2016.3.914 ] Errors in d:\a\1\s\MyCompany\MyProject.UI.csproj NU1102: Unable to find package Telerik.UI.for.AspNet.Core with version (>= 2019.2.619) - Found 1 version(s) in NuGetOrg [ Nearest version: 2016.3.914 ])

[error]Packages failed to restore

I spoke with Telerik support who said the above code is because there is a failure in authentication and that causes the system to look for an older version which is causing this compatibility issue. I was asked to check my authentication which I have, yet this error persists.

I followed the documentation from Telerik on how to achieve this which you can find here: https://www.telerik.com/blogs/azure-devops-and-telerik-nuget-packages

Ok, to start off, my project has a nuget.config file located in its root directory. The contents of the file are:

nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <packageSources>
    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
    <add key="Telerik" value="https://nuget.telerik.com/nuget" />
  </packageSources>
  <packageSourceCredentials>
    <Telerik>
      <add key="Username" value="me@mybusiness.com" />
      <add key="ClearTextPassword" value="MyFunkYPassword19!" />
    </Telerik>
  </packageSourceCredentials>
</configuration>

Within Azure Dev Ops, I have created a service connection in the manner described in their documentation which has the name username and password as the above code

服务连接

In my pipeline, I have added the Nuget package which is set to restore using my service connection above.

# Build and test ASP.NET Core projects targeting the full .NET Framework.

# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'config'
    nugetConfigPath: 'MyProject/nuget.config'
    externalFeedCredentials: 'Telerik NuGet'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

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

The settings for the above pipeline step are as follows:

流水线步骤设置

Does anyone have any ideas what's going on, is my setup incorrect?

I managed to get this working by accident. It was the order of the steps that was causing the problem. The output of the build showed that no matter what I did the pipeline was looking at a tempNuget.config file and not the one I had specified. Since there are two NuGet steps in the job I moved the Telerik up by one level and this ensured the system used the correct nuget.config file instead of looking at a temp one it was creating.

Here are the altered steps that caused it to start working, please note the Telerik step has been moved up by one step.

# Build and test ASP.NET Core projects targeting the full .NET Framework.

# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:

- task: NuGetToolInstaller@1
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'config'
    nugetConfigPath: 'MyProject/nuget.config'
    externalFeedCredentials: 'Telerik NuGet'
- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'           
- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM