简体   繁体   English

使用 Azure DevOps Artifact 时无法在 Build Pipeline 中执行“dotnet tool restore --interactive”

[英]Fail to execute "dotnet tool restore --interactive" in Build Pipeline when using Azure DevOps Artifact

I'm using Azure DevOps and would like to run dotnet tool restore --interactive in my Build Pipeline.我正在使用 Azure DevOps 并希望在我的构建管道中运行dotnet tool restore --interactive In my code repo, there is nuget.config as follows.在我的代码nuget.config ,有如下nuget.config The file has a private feed hosted in Azure Artifact in addition to nuget.org.除了 nuget.org 之外,该文件还有一个托管在 Azure Artifact 中的私有源。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="MyTools" value="https://mytools.pkgs.visualstudio.com/MyBot/_packaging/MyTools/nuget/v3/index.json" />
  </packageSources>
</configuration>

In the private feed in Azure Artifact, my private dotnet tools exist.在 Azure Artifact 的私有源中,存在我的私有 dotnet 工具。 To retrieve the tool I created following yml file.检索我在 yml 文件之后创建的工具。

    pool:
      vmImage: "windows-latest"
      demands:
        - msbuild
        - visualstudio
        - vstest
    variables:
      buildPlatform: "Any CPU"
      buildConfiguration: "Release"

    steps:
      - task: PowerShell@2
        inputs:
          targetType: inline
          script: "Invoke-WebRequest -Uri https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1 -OutFile ./installcredprovider.ps1 ;./installcredprovider.ps1;"
      - task: DotNetCoreCLI@2
        displayName: "Restore tools"
        inputs:
          command: custom
          custom: tool
          arguments: restore --interactive

However, as I run the yml file in the build process, following result appears.但是,当我在构建过程中运行 yml 文件时,会出现以下结果。 As the message shows, it requires sign-in, but I do not want to do device sign-in every time.如消息所示,它需要登录,但我不想每次都进行设备登录。 So Is there any good way so that I do not have to do device log-in every time?那么有没有什么好的方法可以让我不必每次都进行设备登录?

##[section]Starting: Restore tools
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.162.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
[command]C:\windows\system32\chcp.com 65001
Active code page: 65001
[command]"C:\Program Files\dotnet\dotnet.exe" tool restore --interactive

Welcome to .NET Core 3.1!
---------------------
SDK Version: 3.1.100

Telemetry
---------
The .NET Core tools collect usage data in order to help us improve your experience. The data is anonymous. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

----------------
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Find out what's new: https://aka.ms/dotnet-whats-new
Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs
Write your first app: https://aka.ms/first-net-core-app
--------------------------------------------------------------------------------------
      [CredentialProvider]DeviceFlow: https://mytools.pkgs.visualstudio.com/MyBot/_packaging/MyTools/nuget/v3/index.json
      [CredentialProvider]ATTENTION: User interaction required. 

      **********************************************************************

      To sign in, use a web browser to open the page https://microsoft.com/devicelogin to authenticate.

      **********************************************************************

C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(123,5): error :     [CredentialProvider]Device flow authentication failed. User was presented with device flow, but didn't react within 90 seconds. [C:\Users\VssAdministrator\AppData\Local\Temp\wk4fkuq1.hqu\restore.csproj]
C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(123,5): error : Unable to load the service index for source https://mytools.pkgs.visualstudio.com/MyBot/_packaging/MyTools/nuget/v3/index.json. [C:\Users\VssAdministrator\AppData\Local\Temp\wk4fkuq1.hqu\restore.csproj]
C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(123,5): error :   Response status code does not indicate success: 401 (Unauthorized). [C:\Users\VssAdministrator\AppData\Local\Temp\wk4fkuq1.hqu\restore.csproj]
  Restore completed in 775.06 ms.


Tool 'dotnet-ef' (version '3.1.1') was restored. Available commands: dotnet-ef
Package "localenv" failed to restore, due to Microsoft.DotNet.ToolPackage.ToolPackageException: The tool package could not be restored.
   at Microsoft.DotNet.Tools.Tool.Install.ProjectRestorer.Restore(FilePath project, PackageLocation packageLocation, String verbosity)
   at Microsoft.DotNet.ToolPackage.ToolPackageInstaller.InstallPackageToExternalManagedLocation(PackageLocation packageLocation, PackageId packageId, VersionRange versionRange, String targetFramework, String verbosity)
   at Microsoft.DotNet.Tools.Tool.Restore.ToolRestoreCommand.InstallPackages(ToolManifestPackage package, Nullable`1 configFile)

Restore partially failed.
##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x SDK/Runtime along with 2.2 & 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions. 
Some commonly encountered changes are: 
If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : 
##[section]Finishing: Restore tools! (Including efcore tools)

Fail to execute “dotnet tool restore --interactive” in Build Pipeline when using Azure DevOps Artifact使用 Azure DevOps Artifact 时无法在 Build Pipeline 中执行“dotnet tool restore --interactive”

You could not use the command line dotnet tool restore --interactive on the hosted agent, that because:您无法在托管代理上使用命令行dotnet tool restore --interactive ,因为:

Microsoft decided not to put the plugin artifacts-credprovider in dotnet.exe because there were concerns that shipping auth integration to Azure DevOps within the sdk would've been unfair to other feed providers.微软决定不将插件 artifacts-credprovider 放在 dotnet.exe 中,因为有人担心在 sdk 中将身份验证集成传送到 Azure DevOps 对其他提要提供者不公平。 To resolve your 401 issues you need to install the auth plugin manually.要解决 401 问题,您需要手动安装 auth 插件。

That the reason why you get the 401 (Unauthorized) error.这就是您收到 401(未经授权)错误的原因。

In addition , you mentioned that you do not want to commit the token info in the nuget.config file, as a solution for this issue, you could add a nuget Service connections with PAT:此外,您提到您不想nuget.config文件中提交令牌信息,作为此问题的解决方案,您可以使用 PAT 添加 nuget Service connections

在此处输入图片说明

Then use this externalFeedCredentials: nugettest in the dotnet restore task instead of powershell task (there is no option to accept the certification Information):然后在 dotnet restore 任务中使用这个externalFeedCredentials: nugettest而不是 powershell 任务(没有选项接受认证信息):

- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: restore
    projects: path/to/xxx.csproj
    feedsToUse: config
    nugetConfigPath: path/to/NuGet.Config
    externalFeedCredentials: nugettest

Then we could resoter the package from our private feed.然后我们可以从我们的私人提要中重新获取包。

If you get the 403 403 (Forbidden) error with above method, you can check the thread here.如果使用上述方法得到 403 403 (Forbidden) 错误,您可以此处查看线程

Hope this helps.希望这可以帮助。

You can't use the flag --interactive in a build pipeline, because this flag except to get an output from the user during the execution.您不能在构建管道中使用--interactive标志,因为此标志除了在执行期间从用户获取输出之外。

You can use the default restore option in the .Net core task:您可以使用 .Net 核心任务中的默认还原选项:

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '$(Build.SourcesDirecotry)/path/to/csproj'
    feedToUse: 'config'
    nugetConfigPath: '$(Build.SourcesDirectory)/path/to/nuget.config'

This one is because you should let agent know the nuget sources with pre-authenticated feed url prior to dotnet restore:这是因为在 dotnet restore 之前,您应该让代理知道具有预先身份验证的提要 url 的 nuget 源:

- task: NuGetCommand@2
  displayName: 'Add Nuget Feed'
  inputs:
  command: custom
  arguments: 'sources add -name <name_of_source> -source <feed_url>'

I hope this would be useful.我希望这会很有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure Devops 管道构建失败未能执行目标工件信息不完整或无效“版本”缺失 - Azure Devops pipeline build failure Failed to execute goal The artifact information is incomplete or not valid 'version' is missing Azure devops 构建管道-发布工件过程 - Azure devops build pipeline- publish artifact process Azure DevOps:如何从 Release Pipeline 中的 PowerShell 脚本构建 Azure Pipeline 检索构建工件? - Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline? 在 Azure DevOps Build Pipeline 中恢复 Libman JS 库 - Restore Libman JS Libraries in Azure DevOps Build Pipeline Azure DevOps Build Pipeline:“publish”命令正在执行“dotnet build”而不是“dotnet publish” - Azure DevOps Build Pipeline: 'publish' command is executing 'dotnet build' instead of 'dotnet publish' 当我的 linting 脚本返回错误时,如何使我的 Azure DevOps Pipeline 构建失败? - How do I get my Azure DevOps Pipeline build to fail when my linting script returns an error? 使用 Azure DevOps 构建 CI 管道 - Build CI pipeline using Azure DevOps 使用 Devops 管道恢复 Azure Sql 数据库备份 - Restore Azure Sql Database backup using Devops pipeline Azure DevOps 管道中的 AzureResourceManagerTemplateDeployment 失败 - AzureResourceManagerTemplateDeployment fail in Azure DevOps pipeline 如何使用 Azure Devops CLI 下载构建工件? - How do you download a build artifact using Azure Devops CLI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM