【问题标题】:Install & run custom dotnet tool on azure devops release在 azure devops 版本上安装和运行自定义 dotnet 工具
【发布时间】:2019-11-17 21:01:07
【问题描述】:

我正在尝试构建由已发布 dotnet 核心工具的新版本触发的发布管道。触发器工作正常,但我无法在我的任务中安装和运行该工具。

目前:

运行Command Line Task 会导致 401:

dotnet tool install -g --add-source=https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json MyApp
C:\Program Files\dotnet\sdk\3.0.100\NuGet.targets(123,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json. [C:\Users\VssAdministrator\AppData\Local\Temp\h0g1c35v.eny\restore.csproj]
C:\Program Files\dotnet\sdk\3.0.100\NuGet.targets(123,5): error :   Response status code does not indicate success: 401 (Unauthorized). [C:\Users\VssAdministrator\AppData\Local\Temp\h0g1c35v.eny\restore.csproj]
The tool package could not be restored.
Tool 'myapp' failed to install. This failure may have been caused by:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool

这让我相信我在这里遗漏了一些东西,使它变得比它需要的更复杂,或者以错误的方式思考这个问题。提要中的工具可以本地安装,所以我相信这是我的发布方式。

我目前正在调查Personal Access Tokens (PAT)


以前

如果我使用 .Net Core 任务custom 选项:

日志显示传递给 dotnet.exe 的格式错误的命令:

[command]"C:\Program Files\dotnet\dotnet.exe" "dotnet tool install -g --add-source=https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json MyApp"

[command]"C:\Program Files\dotnet\dotnet.exe" "tool install -g --add-source=https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json MyApp"

我尝试了不同的参数,但总是看到相同的错误消息:

Could not execute because the specified command or file was not found.
Possible reasons for this include:
   * You misspelled a built-in dotnet command.
   * You intended to execute a .NET Core program, but dotnet-dotnet tool install -g --add-source=https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json MyApp does not exist.
   * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

【问题讨论】:

  • 你应该为此提出一个新问题并接受这个答案,因为这是一个全新的\不相关的问题

标签: .net-core azure-devops


【解决方案1】:

引用了您的自定义 dotnet 命令并重复了 dotnetdotnet.exe" "dotnet tool install ...",因此该命令被误解了。

你可以使用Command Line task直接设置dotnet命令:

dotnet tool install -g --add-source=https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json MyApp

【讨论】:

  • 很好,谢谢!我现在收到 401 Unauthorized 错误,这对于私有 devops 提要更有意义。我会相应地更新我的问题。
  • 我在 Azure DevOps 中遇到了与自定义 dotnet 命令任务类似的问题,其中提供 pack something 会导致命令 dotnet.exe "pack something" 这显然是错误的。 Powershell 任务确实引入了 dotnet 的东西。
【解决方案2】:

使用 .Net Core 任务非常适合我们。

由于引用了 dotnet 命令,因此需要将 tool 设置为命令并更新为参数。如果需要,可以通过 NuGet Auth 任务提供 NuGet 凭据。

【讨论】:

    【解决方案3】:

    您需要在尝试访问 nuget 提要之前添加 nuget 身份验证任务

    【讨论】:

      【解决方案4】:

      这是我的解决方法:

      1. 我首先将我的私有 dotnet 工具 nupkg 文件也作为通用包发布到同一个 Azure Artifacts 源。

      2. 然后我可以使用Universal Package task.nupkg 文件下载到$(System.DefaultWorkingDirectory)/nupkgs/。此任务将处理对 Azure Artifacts 源的授权。

      steps:
      - task: UniversalPackages@0
        displayName: 'Download mytool.cli.universal'
        inputs:
          downloadDirectory: '$(System.DefaultWorkingDirectory)/nupkgs/'
          vstsFeed: '63d4aa2f-3ae7-4c27-8c18-aa8e3a9ff353'
          vstsFeedPackage: '916d9a27-2c07-4071-8631-377f2ac08ed7'
          vstsPackageVersion: 0.2.0
      
      1. 然后我有 DotNetCoreCLI 任务在代理中本地安装我的 nupkg。
      steps:
      - task: DotNetCoreCLI@2
        displayName: 'Install mytool as a dotnet tool'
        inputs:
          command: custom
          custom: tool
          arguments: 'install --global mytool.CLI --add-source ./nupkgs --version 0.2.0'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-16
        • 2019-10-15
        • 2021-07-20
        • 2021-10-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多