Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DotNetCoreCLIV2 not being able to restore custom MsBuild SDKs. #10567

Merged
merged 13 commits into from
Jun 11, 2019
26 changes: 26 additions & 0 deletions Tasks/Common/packaging-common/nuget/NuGetConfigHelper2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import * as ngutil from "./Utility";
// NuGetConfigHelper2 handles authenticated scenarios where the user selects a source from the UI or from a service connection.
// It is used by the NuGetCommand >= v2.0.0 and DotNetCoreCLI >= v2.0.0

const nugetFileName: string = 'nuget.config';

export class NuGetConfigHelper2 {
public tempNugetConfigPath = undefined;
private nugetXmlHelper: INuGetXmlHelper;
private rootNuGetFiles: Array<string>;

constructor(
private nugetPath: string,
Expand Down Expand Up @@ -158,6 +161,21 @@ export class NuGetConfigHelper2 {
return packageSources.map((source) => this.convertToIPackageSource(source));
}

// TODO: Remove these two methods once NuGet issue https://github.com/NuGet/Home/issues/7855 is fixed.
public backupExistingRootNuGetFiles(): void {
this.rootNuGetFiles = fs.readdirSync('.').filter((file) => file.toLowerCase() === nugetFileName);
if (this.shouldWriteRootNuGetFiles()) {
this.rootNuGetFiles.forEach((file) => fs.renameSync(file, this.temporaryRootNuGetName(file)));
fs.writeFileSync(nugetFileName, fs.readFileSync(this.tempNugetConfigPath));
}
}
public restoreBackupRootNuGetFiles(): void {
if (this.shouldWriteRootNuGetFiles()) {
fs.unlinkSync(nugetFileName);
this.rootNuGetFiles.forEach((file) => fs.renameSync(this.temporaryRootNuGetName(file), file));
}
}

private removeSourceFromTempNugetConfig(packageSource: IPackageSource) {
this.nugetXmlHelper.RemoveSourceFromNuGetConfig(packageSource.feedName);
}
Expand Down Expand Up @@ -188,4 +206,12 @@ export class NuGetConfigHelper2 {
isInternal
};
}

// TODO: Remove these two methods once NuGet issue https://github.com/NuGet/Home/issues/7855 is fixed.
private temporaryRootNuGetName(nugetFile: string): string {
return `tempRename_${tl.getVariable('build.buildId')}_${nugetFile}`;
}
private shouldWriteRootNuGetFiles(): boolean {
return path.relative('.', this.nugetConfigPath).toLocaleLowerCase() == nugetFileName || this.rootNuGetFiles.length == 0;
}
}
4 changes: 4 additions & 0 deletions Tasks/DotNetCoreCLIV2/Tests/NuGetConfigHelper-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ export class NuGetConfigHelper2 {
static getTempNuGetConfigBasePath() {
return tl.getVariable("Agent.HomeDirectory");
}

backupExistingRootNuGetFiles() {}

restoreBackupRootNuGetFiles() {}
}
5 changes: 5 additions & 0 deletions Tasks/DotNetCoreCLIV2/restorecommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export async function run(): Promise<void> {
nuGetConfigHelper.setAuthForSourcesInTempNuGetConfig();

const configFile = nuGetConfigHelper.tempNugetConfigPath;

nuGetConfigHelper.backupExistingRootNuGetFiles();

const dotnetPath = tl.which('dotnet', true);

try {
Expand All @@ -133,6 +136,8 @@ export async function run(): Promise<void> {
}
} finally {
credCleanup();

nuGetConfigHelper.restoreBackupRootNuGetFiles();
}

tl.setResult(tl.TaskResult.Succeeded, tl.loc('PackagesInstalledSuccessfully'));
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DotNetCoreCLIV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 2,
"Minor": 153,
"Patch": 1
"Patch": 2
},
"minimumAgentVersion": "2.115.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DownloadPackageV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 153,
"Patch": 1
"Patch": 2
},
"demands": [],
"minimumAgentVersion": "1.99.0",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DownloadPackageV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 1,
"Minor": 153,
"Patch": 1
"Patch": 2
},
"demands": [],
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/NpmAuthenticateV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 154,
"Patch": 1
"Patch": 2
},
"runsOn": [
"Agent",
Expand Down Expand Up @@ -66,4 +66,4 @@
"argumentFormat": ""
}
}
}
}
4 changes: 2 additions & 2 deletions Tasks/NpmAuthenticateV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 153,
"Patch": 1
"Patch": 2
},
"runsOn": [
"Agent",
Expand Down Expand Up @@ -66,4 +66,4 @@
"argumentFormat": ""
}
}
}
}
2 changes: 1 addition & 1 deletion Tasks/NpmV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 1,
"Minor": 153,
"Patch": 1
"Patch": 2
},
"runsOn": [
"Agent",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetCommandV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 2,
"Minor": 153,
"Patch": 1
"Patch": 2
},
"runsOn": [
"Agent",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetPublisherV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 153,
"Patch": 1
"Patch": 2
},
"runsOn": [
"Agent",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetToolInstallerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 0,
"Minor": 153,
"Patch": 1
"Patch": 2
},
"preview": false,
"satisfies": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetToolInstallerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 1,
"Minor": 153,
"Patch": 1
"Patch": 2
},
"preview": false,
"satisfies": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"version": {
"Major": 0,
"Minor": 153,
"Patch": 1
"Patch": 2
},
"runsOn": [
"Agent",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PipAuthenticateV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 154,
"Patch": 0
"Patch": 1
},
"runsOn": [
"Agent",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/TwineAuthenticateV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 154,
"Patch": 0
"Patch": 1
},
"runsOn": [
"Agent",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/UniversalPackagesV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 153,
"Patch": 1
"Patch": 2
},
"runsOn": [
"Agent",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/UseDotNetV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 7
"Patch": 8
},
"satisfies": [
"DotNetCore"
Expand Down Expand Up @@ -153,4 +153,4 @@
"FailureWhileInstallingNuGetVersion": "Failed while installing NuGet version. Error: %s",
"SettingUpNugetProxySettings": "Setting up proxy configuration for NuGet."
}
}
}
4 changes: 2 additions & 2 deletions Tasks/UseDotNetV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 7
"Patch": 8
},
"satisfies": [
"DotNetCore"
Expand Down Expand Up @@ -153,4 +153,4 @@
"FailureWhileInstallingNuGetVersion": "ms-resource:loc.messages.FailureWhileInstallingNuGetVersion",
"SettingUpNugetProxySettings": "ms-resource:loc.messages.SettingUpNugetProxySettings"
}
}
}
4 changes: 2 additions & 2 deletions Tasks/UseNodeV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 154,
"Patch": 0
"Patch": 1
},
"satisfies": [
"Node",
Expand Down Expand Up @@ -52,4 +52,4 @@
"messages": {
"ToolFailed": "Node install failed: %s"
}
}
}
4 changes: 2 additions & 2 deletions Tasks/UseNodeV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 154,
"Patch": 0
"Patch": 1
},
"satisfies": [
"Node",
Expand Down Expand Up @@ -52,4 +52,4 @@
"messages": {
"ToolFailed": "ms-resource:loc.messages.ToolFailed"
}
}
}