【问题标题】:How to use dotnet restore on Visual Studio Team Services Hosted Build Agent with VSTS Nuget feed如何在带有 VSTS Nuget 源的 Visual Studio Team Services 托管构建代理上使用 dotnet restore
【发布时间】:2016-06-29 08:11:10
【问题描述】:

我有一个 .Net Core 1.0 类库,它使用托管在 Visual Studio Team Services Nuget 源中的 Nuget 包。

我们使用 Visual Studio Team Services 来构建类库,并有一个构建定义,其中包含在项目上执行 dotnet restore 的构建步骤。该命令失败并出现以下错误:

2016-06-28T13:07:09.0634265Z ##[warning]File name doesn't indicate a full path to a executable file.
2016-06-28T13:07:09.0644179Z Executing the following command-line. (workingFolder = C:\a\1\s)
2016-06-28T13:07:09.0644179Z dotnet restore
2016-06-28T13:07:09.0654186Z Error message highlight pattern: 
2016-06-28T13:07:09.0654186Z Warning message highlight pattern: 
2016-06-28T13:07:11.6393062Z log  : Restoring packages for C:\a\1\s\src\Company.Extensions\project.json...
2016-06-28T13:07:11.7623059Z info :   GET https://Company.pkgs.visualstudio.com/DefaultCollection/_packaging/FeedName/nuget/v2/FindPackagesById()?id='Company.Model'
2016-06-28T13:07:11.8463064Z info :   GET https://api.nuget.org/v3-flatcontainer/Company.model/index.json
2016-06-28T13:07:12.0162954Z info :   Unauthorized https://Company.pkgs.visualstudio.com/DefaultCollection/_packaging/FeedName/nuget/v2/FindPackagesById()?id='Company.Model' 254ms
2016-06-28T13:07:12.0702952Z log  : Retrying 'FindPackagesByIdAsyncCore' for source 'https://Company.pkgs.visualstudio.com/DefaultCollection/_packaging/FeedName/nuget/v2/FindPackagesById()?id='Company.Model''.
2016-06-28T13:07:12.0712954Z log  : Response status code does not indicate success: 401 (Unauthorized).
2016-06-28T13:07:12.0712954Z info :   GET https://Company.pkgs.visualstudio.com/DefaultCollection/_packaging/FeedName/nuget/v2/FindPackagesById()?id='Company.Model'
2016-06-28T13:07:12.0722952Z info :   NotFound https://api.nuget.org/v3-flatcontainer/Company.model/index.json 224ms
2016-06-28T13:07:12.1426754Z info :   Unauthorized https://Company.pkgs.visualstudio.com/DefaultCollection/_packaging/FeedName/nuget/v2/FindPackagesById()?id='Company.Model' 73ms
2016-06-28T13:07:12.1436737Z log  : Retrying 'FindPackagesByIdAsyncCore' for source 'https://Company.pkgs.visualstudio.com/DefaultCollection/_packaging/FeedName/nuget/v2/FindPackagesById()?id='Company.Model''.
2016-06-28T13:07:12.1436737Z log  : Response status code does not indicate success: 401 (Unauthorized).
2016-06-28T13:07:12.1446974Z info :   GET https://Company.pkgs.visualstudio.com/DefaultCollection/_packaging/FeedName/nuget/v2/FindPackagesById()?id='Company.Model'
2016-06-28T13:07:12.2162787Z info :   Unauthorized https://Company.pkgs.visualstudio.com/DefaultCollection/_packaging/FeedName/nuget/v2/FindPackagesById()?id='Company.Model' 72ms
2016-06-28T13:07:12.2172786Z error: Failed to retrieve information from remote source 'https://Company.pkgs.visualstudio.com/DefaultCollection/_packaging/FeedName/nuget/v2/FindPackagesById()?id='Company.Model''.
2016-06-28T13:07:12.2172786Z error: Response status code does not indicate success: 401 (Unauthorized).
2016-06-28T13:07:12.2364584Z error: Failed to retrieve information from remote source 'https://Company.pkgs.visualstudio.com/DefaultCollection/_packaging/FeedName/nuget/v2/FindPackagesById()?id='Company.Model''.
2016-06-28T13:07:12.2374607Z error:   Response status code does not indicate success: 401 (Unauthorized).

显然它失败了,因为 FeedName 要求我们对其进行身份验证,这就是为什么我们在 project.json 旁边还有这个 nuget.config 文件:

<?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="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="FeedName" value="https://Company.pkgs.visualstudio.com/DefaultCollection/_packaging/FeedName/nuget/v2" />
  </packageSources>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <FeedName>
    <add key="Username" value="username" />
    <add key="ClearTextPassword" value="the_actual_clear_text_password" />
  </FeedName>
</configuration>

如果我们使用 Nuget Installer 构建步骤,这将有效,但使用 dotnet restore 则无效。

请帮忙,这是我们需要继续使用 Visual Studio Team Services 来构建我们的项目所缺少的部分。

【问题讨论】:

    标签: .net azure-devops nuget-package-restore


    【解决方案1】:

    详情可参考此链接:.NET Core

    .NET Core 当前不支持加密凭据。使用 VSTS 带有 .NET Core 应用程序的 NuGet 提要,您需要指定一个 纯文本的个人访问令牌。

    【讨论】:

    • 谢谢!按照您的链接,我发现我的 nuget.config 中缺少 &lt;packageSourceCredentials&gt; 标签。把它们放进去解决了我的问题。
    【解决方案2】:

    您现在可以使用 dotnet core 构建步骤来恢复、构建、测试和运行其他自定义 dotnet 命令。

    以下是所有可用的命令

    选择 restore 命令将使您能够选择 nuget 包源,如下所示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 2017-03-23
      • 1970-01-01
      • 1970-01-01
      • 2016-06-13
      相关资源
      最近更新 更多