Skip to content

Commit 232af91

Browse files
authored
Set an env var to use shorter path for nuget cache (#9516) (#9526)
* Set an env var to use shorter path for nuget cache
1 parent 1b29ed8 commit 232af91

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Tasks/Common/packaging-common/nuget/NuGetToolRunner2.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {NuGetQuirkName, NuGetQuirks, defaultQuirks} from "./NuGetQuirks";
77
import * as ngutil from "./Utility";
88
import * as peParser from "../pe-parser";
99
import * 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
}

Tasks/NuGetCommandV2/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": {
1010
"Major": 2,
1111
"Minor": 147,
12-
"Patch": 2
12+
"Patch": 4
1313
},
1414
"runsOn": [
1515
"Agent",

0 commit comments

Comments
 (0)