Skip to content

Commit 2555eb3

Browse files
authored
Set an env var to use shorter path for nuget cache (#9516) (#9527)
* Set an env var to use shorter path for nuget cache
1 parent c4d32a3 commit 2555eb3

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
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.
@@ -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
}

Tasks/NuGetCommandV2/task.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": 146,
12-
"Patch": 1
12+
"Patch": 2
1313
},
1414
"runsOn": [
1515
"Agent",

Tasks/NuGetCommandV2/task.loc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"author": "Microsoft Corporation",
99
"version": {
1010
"Major": 2,
11-
"Minor": 145,
12-
"Patch": 3
11+
"Minor": 146,
12+
"Patch": 2
1313
},
1414
"runsOn": [
1515
"Agent",

0 commit comments

Comments
 (0)