How to get TFS2015 Build (Build.vnext) and NuGet package restore to use custom package sources

后端 未结 8 1581
迷失自我
迷失自我 2020-11-30 07:52

I\'m trying to get our TFS2015 Build (TFSBuild vnext) going along with VS Team Services.

Thus far most blogs and documentation has been helpful, except for when try

相关标签:
8条回答
  • 2020-11-30 08:01

    I've scrounged the web with little success, but after fiddling the following will help:

    OK It seems that the package sources configured for NuGet.config is stored per user account, e.g.

    c:\Users\<<username>>\AppData\Roaming\NuGet\NuGet.config

    My issue was harder to resolve, because the build agent was running as a Windows Service under the Local System account. So to get NuGet configuration to for the build, I had to use the following path instead:

    • 64-bit Windows C:\Windows\SysWOW64\config\systemprofile\AppData\Roaming\NuGet\NuGet.Config
    • 32-bit Windows C:\Windows\System32\config\systemprofile\AppData\Roaming\NuGet\NuGet.Config

    You may need to have elevated permissions in order to create the NuGet subfolder and NuGet.Config file.

    Note: I have no solution for using the Local Service account. The above only works for the Local System (or an actual user) account.

    0 讨论(0)
  • 2020-11-30 08:05

    There is a new VSTS Task called "NuGet Installer" this allows you to check in your NuGet.config file and specify the different package sources. Run this task before you run MSBuild.

    If you are using the VSTS NuGet Feed you will need to add the build service account to the feed to enable downloading of packages https://www.visualstudio.com/get-started/package/use/common-identities

    0 讨论(0)
  • 2020-11-30 08:06

    If you are having trouble getting this to work on UWP ONLY, then ensure that you have the CASE of the package name spelt correctly. If the case is wrong, then (for UWP only) our build server fails the build.

    for instance, if you have a package called Com.Company.Components and update the package using "install-package com.company.components" (note the case of the initial letter) then the UWP build on the build server may fail to find the package in your local store.

    0 讨论(0)
  • 2020-11-30 08:09

    One solution (works for me) is change account for tfs 2015 build agent service (on my build machine VSO Agent tsf.Agent-PC) to tfsagent, for example, and add Nuget.config to the C:\Users\tfsagent\AppData\Roaming\Nuget. That's all!

    0 讨论(0)
  • 2020-11-30 08:10

    Add a NuGet.config to your project that specifies an alternate package location. The rules for resolution are well-defined and explained in the official documentation.

    0 讨论(0)
  • 2020-11-30 08:17
    1. Specify your custom NuGet feed URL’s in the solution’s nuget.config file. Do not store any usernames & passwords in this file.

      <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
      <add key="MyCompany" value="https://nuget.mycompany.com:443/nuget" />
      
    2. Create username & password variables in your build definition in VSTS. Variables can be encrypted and will not be displayed in any of the build log outputs. Here I'll create MyCompanyNugetUser and MyCompanyNugetPwd variables.

    3. In our build steps, we add a Powershell script as the first action, this will read the username & password variables and update the user level nuget.config file on the build machine. Below is the code snippet from my inline Powershell script:

      Arguments:

      $(MyCompanyNugetUser) $(MyCompanyNugetPwd)
      

      Script:

      param($user, $pwd)
      
      $nugetFile = "$ENV:AGENT_HOMEDIRECTORY\agent\worker\tools\nuget.exe"
      Write-Output "Looking for nuget.exe in $nugetFile"
      
      if (-not (Test-Path $nugetFile))
      {
        Write-Error "nuget.exe could not be located."
        return
      }
      
      Write-Output "nuget.exe located"
      
      $cmd = "$nugetFile sources add -name MyCompany -source https://nuget.mycompany.com:443/nuget -username $user -password $pwd -StorePasswordInClearText"
      Write-Output $cmd
      iex $cmd
      
    4. Next, we just continue to execute the default NuGet Restore step from Microsoft’s templates

    More here: https://codingcase.com/2016/07/27/vsts-build-setup-custom-nuget-feeds-with-authentication/

    HTH

    0 讨论(0)
提交回复
热议问题