@@ -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.
@@ -45,11 +46,14 @@ function prepareNuGetExeEnvironment(
4546 let env : EnvironmentDictionary = { } ;
4647 let originalCredProviderPath : string = null ;
4748 let envVarCredProviderPathV2 : string = null ;
49+ let nugetCacheDir : string = null ;
50+ let disableNuGetPluginCacheWorkaround : boolean = false ;
4851
4952 for ( let e in input ) {
5053 if ( ! input . hasOwnProperty ( e ) ) {
5154 continue ;
5255 }
56+
5357 // NuGet.exe extensions only work with a single specific version of nuget.exe. This causes problems
5458 // whenever we update nuget.exe on the agent.
5559 if ( e . toUpperCase ( ) === "NUGET_EXTENSIONS_PATH" ) {
@@ -73,9 +77,34 @@ function prepareNuGetExeEnvironment(
7377 continue ;
7478 }
7579
80+ if ( e . toUpperCase ( ) === "DISABLE_NUGET_PLUGINS_CACHE_WORKAROUND" ) {
81+ // Specifically disable NUGET_PLUGINS_CACHE_PATH workaround
82+ disableNuGetPluginCacheWorkaround = true ;
83+ continue ;
84+ }
85+
86+ // NuGet plugins cache
87+ if ( e . toUpperCase ( ) === "NUGET_PLUGINS_CACHE_PATH" ) {
88+ nugetCacheDir = input [ e ] ;
89+ continue ;
90+ }
91+
7692 env [ e ] = input [ e ] ;
7793 }
7894
95+ // If DISABLE_NUGET_PLUGINS_CACHE_WORKAROUND variable is not set
96+ // and nugetCacheDir is not populated by NUGET_PLUGINS_CACHE_PATH,
97+ // set NUGET_PLUGINS_CACHE_PATH to the temp directory
98+ // to work aroud the NuGet issue with long paths: https://github.com/NuGet/Home/issues/7770
99+ if ( nugetCacheDir == null && disableNuGetPluginCacheWorkaround === false ) {
100+ const tempDir = tl . getVariable ( 'Agent.TempDirectory' ) ;
101+ nugetCacheDir = path . join ( tempDir , "NuGetPluginsCache" ) ;
102+ }
103+ if ( nugetCacheDir != null ) {
104+ env [ "NUGET_PLUGINS_CACHE_PATH" ] = nugetCacheDir ;
105+ tl . debug ( `NUGET_PLUGINS_CACHE_PATH set to ${ nugetCacheDir } ` ) ;
106+ }
107+
79108 if ( authInfo && authInfo . internalAuthInfo ) {
80109 env [ "VSS_NUGET_ACCESSTOKEN" ] = authInfo . internalAuthInfo . accessToken ;
81110 env [ "VSS_NUGET_URI_PREFIXES" ] = authInfo . internalAuthInfo . uriPrefixes . join ( ";" ) ;
@@ -460,6 +489,11 @@ function buildCredentialJson(authInfo: auth.NuGetExtendedAuthInfo): string {
460489 }
461490 } ) ;
462491
492+ if ( enpointCredentialsJson . endpointCredentials . length < 1 ) {
493+ tl . debug ( `None detected.` ) ;
494+ return null ;
495+ }
496+
463497 const externalCredentials : string = JSON . stringify ( enpointCredentialsJson ) ;
464498 return externalCredentials ;
465499 }
0 commit comments