diff --git a/vscode-dotnet-runtime-library/distro-data/distro-support.json b/vscode-dotnet-runtime-library/distro-data/distro-support.json index 304bf448..af00a70f 100644 --- a/vscode-dotnet-runtime-library/distro-data/distro-support.json +++ b/vscode-dotnet-runtime-library/distro-data/distro-support.json @@ -130,11 +130,6 @@ "version": "18.04", "preInstallCommands": [ - { - "runUnderSudo": true, - "commandRoot": "apt-get", - "commandParts": ["update"] - }, { "runUnderSudo": true, "commandRoot": "apt-get", @@ -149,6 +144,11 @@ "runUnderSudo": true, "commandRoot": "dpkg", "commandParts": ["-i", "packages-microsoft-prod.deb"] + }, + { + "runUnderSudo": true, + "commandRoot": "apt-get", + "commandParts": ["update"] } ] }, diff --git a/vscode-dotnet-runtime-library/src/Acquisition/GenericDistroSDKProvider.ts b/vscode-dotnet-runtime-library/src/Acquisition/GenericDistroSDKProvider.ts index d11b6638..2a907091 100644 --- a/vscode-dotnet-runtime-library/src/Acquisition/GenericDistroSDKProvider.ts +++ b/vscode-dotnet-runtime-library/src/Acquisition/GenericDistroSDKProvider.ts @@ -15,13 +15,7 @@ export class GenericDistroSDKProvider extends IDistroDotnetSDKProvider { public async installDotnet(fullySpecifiedVersion : string, installType : LinuxInstallType): Promise { - const supportStatus = await this.getDotnetVersionSupportStatus(fullySpecifiedVersion, installType); - if(supportStatus === DotnetDistroSupportStatus.Microsoft) - { - const myVersionDetails = this.myVersionDetails(); - const preInstallCommands = myVersionDetails[this.preinstallCommandKey] as CommandExecutorCommand[]; - await this.commandRunner.executeMultipleCommands(preInstallCommands); - } + await this.injectPMCFeed(fullySpecifiedVersion, installType); let commands = this.myDistroCommands(this.installCommandKey); const sdkPackage = await this.myDotnetVersionPackageName(fullySpecifiedVersion, installType); @@ -39,6 +33,10 @@ export class GenericDistroSDKProvider extends IDistroDotnetSDKProvider public async getInstalledGlobalDotnetPathIfExists(installType : LinuxInstallType) : Promise { const commandResult = await this.commandRunner.executeMultipleCommands(this.myDistroCommands(this.currentInstallPathCommandKey)); + if(commandResult[0]) + { + commandResult[0] = commandResult[0].trim(); + } return commandResult[0]; } @@ -129,7 +127,7 @@ export class GenericDistroSDKProvider extends IDistroDotnetSDKProvider // we need to run this command in the root directory otherwise local dotnets on the path may interfere const rootDir = path.parse(__dirname).root; - let commandResult = (await this.commandRunner.executeMultipleCommands(command, rootDir))[0]; + let commandResult = (await this.commandRunner.executeMultipleCommands(command, { cwd: path.resolve(rootDir), shell: true }))[0]; commandResult = commandResult.replace('\n', ''); if(!this.versionResolver.isValidLongFormVersionFormat(commandResult)) @@ -170,37 +168,6 @@ export class GenericDistroSDKProvider extends IDistroDotnetSDKProvider return Promise.resolve(DotnetDistroSupportStatus.Unknown); } - protected myVersionDetails() : any - { - - const distroVersions = this.distroJson[this.distroVersion.distro][this.distroVersionsKey]; - const versionData = distroVersions.filter((x: { [x: string]: string; }) => x[this.versionKey] === this.distroVersion.version)[0]; - if(!versionData) - { - const closestVersion = this.findMostSimilarVersion(this.distroVersion.version, distroVersions.map((x: { [x: string]: string; }) => parseFloat(x[this.versionKey]))); - return distroVersions.filter((x: { [x: string]: string; }) => parseFloat(x[this.versionKey]) === closestVersion)[0]; - } - return versionData; - } - - private findMostSimilarVersion(myVersion : string, knownVersions : number[]) : number - { - const sameMajorVersions = knownVersions.filter(x => Math.floor(x) === Math.floor(parseFloat(myVersion))); - if(sameMajorVersions && sameMajorVersions.length) - { - return Math.max(...sameMajorVersions); - } - - const lowerMajorVersions = knownVersions.filter(x => x < Math.floor(parseFloat(myVersion))); - if(lowerMajorVersions && lowerMajorVersions.length) - { - return Math.max(...lowerMajorVersions); - } - - // Just return the lowest known version, as it will be the closest to our version, as they are all larger than our version. - return Math.min(...knownVersions); - } - public async getRecommendedDotnetVersion(installType : LinuxInstallType) : Promise { let maxVersion = '0'; diff --git a/vscode-dotnet-runtime-library/src/Acquisition/IDistroDotnetSDKProvider.ts b/vscode-dotnet-runtime-library/src/Acquisition/IDistroDotnetSDKProvider.ts index 752ce0a3..4b3141fc 100644 --- a/vscode-dotnet-runtime-library/src/Acquisition/IDistroDotnetSDKProvider.ts +++ b/vscode-dotnet-runtime-library/src/Acquisition/IDistroDotnetSDKProvider.ts @@ -172,7 +172,7 @@ export abstract class IDistroDotnetSDKProvider { return supportedType; } - protected async myVersionPackages(installType : LinuxInstallType) : Promise + protected async myVersionPackages(installType : LinuxInstallType, haveTriedFeedInjectionAlready = false) : Promise { const availableVersions : LinuxPackageCollection[] = []; @@ -203,9 +203,60 @@ export abstract class IDistroDotnetSDKProvider { } } + if(availableVersions.length === 0 && !haveTriedFeedInjectionAlready) + { + // PMC is only injected and should only be injected for MSFT feed distros. + // Our check runs by checking the feature band first, so that needs to be supported for it to fallback to the preinstall command check. + const fakeVersionToCheckMicrosoftSupportStatus = '6.0.1xx'; + + await this.injectPMCFeed(fakeVersionToCheckMicrosoftSupportStatus, installType); + return this.myVersionPackages(installType, true); + } return availableVersions; } + protected async injectPMCFeed(fullySpecifiedVersion : string, installType : LinuxInstallType) + { + const supportStatus = await this.getDotnetVersionSupportStatus(fullySpecifiedVersion, installType); + if(supportStatus === DotnetDistroSupportStatus.Microsoft) + { + const myVersionDetails = this.myVersionDetails(); + const preInstallCommands = myVersionDetails[this.preinstallCommandKey] as CommandExecutorCommand[]; + await this.commandRunner.executeMultipleCommands(preInstallCommands); + } + } + + protected myVersionDetails() : any + { + + const distroVersions = this.distroJson[this.distroVersion.distro][this.distroVersionsKey]; + const versionData = distroVersions.filter((x: { [x: string]: string; }) => x[this.versionKey] === this.distroVersion.version)[0]; + if(!versionData) + { + const closestVersion = this.findMostSimilarVersion(this.distroVersion.version, distroVersions.map((x: { [x: string]: string; }) => parseFloat(x[this.versionKey]))); + return distroVersions.filter((x: { [x: string]: string; }) => parseFloat(x[this.versionKey]) === closestVersion)[0]; + } + return versionData; + } + + protected findMostSimilarVersion(myVersion : string, knownVersions : number[]) : number + { + const sameMajorVersions = knownVersions.filter(x => Math.floor(x) === Math.floor(parseFloat(myVersion))); + if(sameMajorVersions && sameMajorVersions.length) + { + return Math.max(...sameMajorVersions); + } + + const lowerMajorVersions = knownVersions.filter(x => x < Math.floor(parseFloat(myVersion))); + if(lowerMajorVersions && lowerMajorVersions.length) + { + return Math.max(...lowerMajorVersions); + } + + // Just return the lowest known version, as it will be the closest to our version, as they are all larger than our version. + return Math.min(...knownVersions); + } + protected myDistroStrings(stringKey : string) : string { return this.distroJson[this.distroVersion.distro][stringKey];