@@ -7,6 +7,7 @@ import {NuGetQuirkName, NuGetQuirks, defaultQuirks} from "./NuGetQuirks";
77import * as ngutil from "./Utility" ;
88import * as peParser from "../pe-parser" ;
99import * as commandHelper from "./CommandHelper" ;
10+ import * as path from "path" ;
1011
1112// NuGetToolRunner2 can handle environment setup for new authentication scenarios where
1213// we are accessing internal or external package sources.
@@ -37,11 +38,14 @@ function prepareNuGetExeEnvironment(
3738 let env : EnvironmentDictionary = { } ;
3839 let originalCredProviderPath : string = null ;
3940 let envVarCredProviderPathV2 : string = null ;
41+ let nugetCacheDir : string = null ;
42+ let disableNuGetPluginCacheWorkaround : boolean = false ;
4043
4144 for ( let e in input ) {
4245 if ( ! input . hasOwnProperty ( e ) ) {
4346 continue ;
4447 }
48+
4549 // NuGet.exe extensions only work with a single specific version of nuget.exe. This causes problems
4650 // whenever we update nuget.exe on the agent.
4751 if ( e . toUpperCase ( ) === "NUGET_EXTENSIONS_PATH" ) {
@@ -65,9 +69,34 @@ function prepareNuGetExeEnvironment(
6569 continue ;
6670 }
6771
72+ if ( e . toUpperCase ( ) === "DISABLE_NUGET_PLUGINS_CACHE_WORKAROUND" ) {
73+ // Specifically disable NUGET_PLUGINS_CACHE_PATH workaround
74+ disableNuGetPluginCacheWorkaround = true ;
75+ continue ;
76+ }
77+
78+ // NuGet plugins cache
79+ if ( e . toUpperCase ( ) === "NUGET_PLUGINS_CACHE_PATH" ) {
80+ nugetCacheDir = input [ e ] ;
81+ continue ;
82+ }
83+
6884 env [ e ] = input [ e ] ;
6985 }
7086
87+ // If DISABLE_NUGET_PLUGINS_CACHE_WORKAROUND variable is not set
88+ // and nugetCacheDir is not populated by NUGET_PLUGINS_CACHE_PATH,
89+ // set NUGET_PLUGINS_CACHE_PATH to the temp directory
90+ // to work aroud the NuGet issue with long paths: https://github.com/NuGet/Home/issues/7770
91+ if ( nugetCacheDir == null && disableNuGetPluginCacheWorkaround === false ) {
92+ const tempDir = tl . getVariable ( 'Agent.TempDirectory' ) ;
93+ nugetCacheDir = path . join ( tempDir , "NuGetPluginsCache" ) ;
94+ }
95+ if ( nugetCacheDir != null ) {
96+ env [ "NUGET_PLUGINS_CACHE_PATH" ] = nugetCacheDir ;
97+ tl . debug ( `NUGET_PLUGINS_CACHE_PATH set to ${ nugetCacheDir } ` ) ;
98+ }
99+
71100 if ( authInfo && authInfo . internalAuthInfo ) {
72101 env [ "VSS_NUGET_ACCESSTOKEN" ] = authInfo . internalAuthInfo . accessToken ;
73102 env [ "VSS_NUGET_URI_PREFIXES" ] = authInfo . internalAuthInfo . uriPrefixes . join ( ";" ) ;
@@ -351,6 +380,11 @@ function buildCredentialJson(authInfo: auth.NuGetExtendedAuthInfo): string {
351380 }
352381 } ) ;
353382
383+ if ( enpointCredentialsJson . endpointCredentials . length < 1 ) {
384+ tl . debug ( `None detected.` ) ;
385+ return null ;
386+ }
387+
354388 const externalCredentials : string = JSON . stringify ( enpointCredentialsJson ) ;
355389 return externalCredentials ;
356390 }
0 commit comments