azure-pipelinesnuget-serverazure-pipelines-build-taskdotnet-restore

How to consume VSTS internal package server with VSTS build agent "Hosted Linux Preview"?


For some reason, I have to use build agent "Hosted Linux Preview", so I can only use "dotnet restore" instead of "nuget restore", and now our team has internal package server built on VSTS.

In "nuget restore" step, there's option for connecting to the server, yet "dotnet restore" doesn't.

I tried the following ways, but failed.

Try 1 add --source https://****.pkgs.visualstudio.com/_packaging/****/nuget/v3/index.json, I got error in log: error : Unable to load the service index for source https://****.pkgs.visualstudio.com/_packaging/****/nuget/v3/index.json. [/opt/vsts/work/1/s/src/References.Mapper/References.Mapper.csproj]

Try 2 add --configfile ../../.nuget/Nuget.Config, I got the same error as above

It seems that the build agent doesn't have authorization to retrieve the index.json file from VSTS, how shall I proceed?


Solution

  • After checking the link Use dotnet with Team Services feeds, now I can successfully consume the feed.

    Steps:

    1. Make sure the feed's Permission was properly assigned (go to VSTS > Build & Releases > Packages > Manage/Settings > Permissions)
    2. Add a PAT to the account (go to Personal Settings/My Profile > Security > Personal access tokens > add "VSTS-Nuget-Packaging" (or you name it), allow Packaging (read, write, and manage) > keep the credential in note
    3. Modify Nuget.Config as below
    4. Set in VSTS build step "dotnet restore", add a --configfile ../../.nuget/NuGet.Config (location) in "Arguments" (note the name is case-senstive)

    Nuget.Config sample:

    <?xml version="1.0" encoding="utf-8"?>
        <configuration>
          <packageSources>
            <add key="VSTS-Package" value="[feed url]"  />
            <add key="Nuget.org" value="https://www.nuget.org/api/v2/" />
          </packageSources>
          <activePackageSource>
            <add key="All" value="(Aggregate source)" />
          </activePackageSource>
          <packageSourceCredentials>
            <VSTS-Package>
              <add key="Username" value="[username]" />
              <add key="ClearTextPassword" value="[PAT]" />
            </VSTS-Package>
          </packageSourceCredentials>
        </configuration>