diff --git a/extensions/sql-database-projects/src/common/constants.ts b/extensions/sql-database-projects/src/common/constants.ts index 4bc4e45bd3..9949c4613a 100644 --- a/extensions/sql-database-projects/src/common/constants.ts +++ b/extensions/sql-database-projects/src/common/constants.ts @@ -377,8 +377,10 @@ export const invalidSqlConnectionString = localize('invalidSqlConnectionString', export const extractTargetRequired = localize('extractTargetRequired', "Target information for extract is required to create database project."); export const schemaCompareNotInstalled = localize('schemaCompareNotInstalled', "Schema compare extension installation is required to run schema compare"); export const buildFailedCannotStartSchemaCompare = localize('buildFailedCannotStartSchemaCompare', "Schema compare could not start because build failed"); -export function updateProjectForRoundTrip(projectName: string) { return localize('updateProjectForRoundTrip', "The targets, references, and system database references need to be updated to build the project '{0}'. If the project was created in SSDT, it will continue to work in both tools. Do you want to update the project?", projectName); } -export function updateProjectDatabaseReferencesForRoundTrip(projectName: string) { return localize('updateProjectDatabaseReferencesForRoundTrip', "The system database references need to be updated to build the project '{0}'. If the project was created in SSDT, it will continue to work in both tools. Do you want to update the project?", projectName); } +export function projectNeedsUpdatingForCrossPlat(projectName: string) { return localize('projectNeedsUpdatingForCrossPlat', "The targets, references, and system database references need to be updated to build the project '{0}'.", projectName); } +export function updateProjectForCrossPlatform(projectName: string) { return localize('updateProjectForCrossPlatform', "{0} If the project was created in SSDT, it will continue to work in both tools. Do you want to update the project?", projectNeedsUpdatingForCrossPlat(projectName)); } +export function updateProjectForCrossPlatformShort(projectName: string) { return localize('updateProjectForCrossPlatformShort', "Update {0} for cross-platform support?", projectName); } +export function updateProjectDatabaseReferencesForCrossPlatform(projectName: string) { return localize('updateProjectDatabaseReferencesForRoundTrip', "The system database references need to be updated to build the project '{0}'. If the project was created in SSDT, it will continue to work in both tools. Do you want to update the project?", projectName); } export const databaseReferenceTypeRequired = localize('databaseReferenceTypeRequired', "Database reference type is required for adding a reference to a database"); export const systemDatabaseReferenceRequired = localize('systemDatabaseReferenceRequired', "System database selection is required for adding a reference to a system database"); export const dacpacFileLocationRequired = localize('dacpacFileLocationRequired', "Dacpac file location is required for adding a reference to a database"); diff --git a/extensions/sql-database-projects/src/controllers/projectController.ts b/extensions/sql-database-projects/src/controllers/projectController.ts index 399ce328c9..c394d3a0f9 100644 --- a/extensions/sql-database-projects/src/controllers/projectController.ts +++ b/extensions/sql-database-projects/src/controllers/projectController.ts @@ -298,6 +298,14 @@ export class ProjectsController { argument: this.buildHelper.constructBuildArguments(project.projectFilePath, this.buildHelper.extensionBuildDirPath, project.sqlProjStyle) }; + const crossPlatCompatible: boolean = await Project.checkPromptCrossPlatStatus(project, true /* blocking prompt */); + + if (!crossPlatCompatible) { + // user rejected updating for cross-plat + void vscode.window.showErrorMessage(constants.projectNeedsUpdatingForCrossPlat(project.projectFileName)); + return '' + } + try { await this.netCoreTool.runDotnetCommand(options); const timeToBuild = new Date().getTime() - startTime.getTime(); diff --git a/extensions/sql-database-projects/src/models/project.ts b/extensions/sql-database-projects/src/models/project.ts index 4b0c1c3755..6ecbbbdda1 100644 --- a/extensions/sql-database-projects/src/models/project.ts +++ b/extensions/sql-database-projects/src/models/project.ts @@ -158,17 +158,42 @@ export class Project implements ISqlProject { await proj.readProjFile(); - if (!proj.isCrossPlatformCompatible && promptIfNeedsUpdating) { - const result = await window.showWarningMessage(constants.updateProjectForRoundTrip(proj.projectFileName), constants.yesString, constants.noString); - - if (result === constants.yesString) { - await proj.updateProjectForRoundTrip(); - } + if (promptIfNeedsUpdating) { + await this.checkPromptCrossPlatStatus(proj, false /* don't block the thread until the prompt*/); } return proj; } + /** + * If project does not support cross-plat building, prompts the user for whether to update and updates if accepted + * @param project + * @param blockingPrompt whether to block the thread until the user updates, or to fire and forget + * @returns true if the project is updated after return, false if the user rejected the prompt + */ + public static async checkPromptCrossPlatStatus(project: Project, blockingPrompt: boolean): Promise { + if (project.isCrossPlatformCompatible) { + return true; + } + + if (blockingPrompt) { + const result = await window.showWarningMessage(constants.updateProjectForCrossPlatform(project.projectFileName), { modal: true }, constants.yesString, constants.noString); + + if (result === constants.yesString) { + await project.updateProjectForCrossPlatform(); + } + } else { + // use "void" with a .then() to not block the UI thread while prompting the user + void window.showErrorMessage(constants.updateProjectForCrossPlatform(project.projectFileName), constants.yesString, constants.noString).then(async (result) => { + if (result === constants.yesString) { + await project.updateProjectForCrossPlatform(); + } + }); + } + + return project.isCrossPlatformCompatible; + } + /** * Reads the project setting and contents from the file */ @@ -407,7 +432,7 @@ export class Project implements ISqlProject { this._configuration = Configuration.Debug; } - public async updateProjectForRoundTrip(): Promise { + public async updateProjectForCrossPlatform(): Promise { if (this.isCrossPlatformCompatible) { return; } diff --git a/extensions/sql-database-projects/src/test/project.test.ts b/extensions/sql-database-projects/src/test/project.test.ts index 11601ffad3..a7882eebfb 100644 --- a/extensions/sql-database-projects/src/test/project.test.ts +++ b/extensions/sql-database-projects/src/test/project.test.ts @@ -1108,7 +1108,7 @@ async function testUpdateInRoundTrip(test: Mocha.Runnable | undefined, fileBefor project.isCrossPlatformCompatible.should.be.false('Project should not be cross-plat compatible before conversion'); - await project.updateProjectForRoundTrip(); + await project.updateProjectForCrossPlatform(); (project.isCrossPlatformCompatible).should.be.true('Project should be cross-plat compatible after conversion'); (await exists(projFilePath + '_backup')).should.be.true('Backup file should have been generated before the project was updated');