@@ -61,6 +61,7 @@ export class PublishProjectWebViewController extends FormWebviewController<
6161 private _cachedDatabaseList ?: { displayName : string ; value : string } [ ] ;
6262 private _cachedSelectedDatabase ?: string ;
6363 private _preloadedContainerPort ?: Promise < number > ;
64+ private _deploymentOptionsPromise ?: Promise < void > ;
6465 private _connectionUri ?: string ;
6566 private _serverTypes : string = "" ;
6667 private _availableConnections ?: IConnectionDialogProfile [ ] ;
@@ -203,6 +204,8 @@ export class PublishProjectWebViewController extends FormWebviewController<
203204 databaseName : string ,
204205 upgradeExisting : boolean ,
205206 ) : Promise < void > {
207+ // Ensure deployment options are loaded before executing DacFx operations.
208+ await this . _deploymentOptionsPromise ;
206209 const connectionUri = this . _connectionUri || "" ;
207210 const sqlCmdVariables = new Map ( Object . entries ( state . formState . sqlCmdVariables || { } ) ) ;
208211
@@ -268,6 +271,8 @@ export class PublishProjectWebViewController extends FormWebviewController<
268271 dacpacPath : string ,
269272 databaseName : string ,
270273 ) : Promise < void > {
274+ // Ensure deployment options are loaded before executing DacFx operations.
275+ await this . _deploymentOptionsPromise ;
271276 const connectionUri = this . _connectionUri || "" ;
272277 const sqlCmdVariables = new Map ( Object . entries ( state . formState . sqlCmdVariables || { } ) ) ;
273278
@@ -780,12 +785,16 @@ export class PublishProjectWebViewController extends FormWebviewController<
780785 }
781786
782787 // Fetch deployment options in the background while other init work proceeds.
788+ // Cache the promise so consumers can await it if they run before the fetch completes.
783789 if ( this . _dacFxService ) {
784790 // getDeploymentOptions returns a Thenable; wrap in Promise.resolve() for .catch support.
785- void Promise . resolve (
791+ this . _deploymentOptionsPromise = Promise . resolve (
786792 this . _dacFxService . getDeploymentOptions ( DeploymentScenario . Deployment ) ,
787793 )
788794 . then ( ( result ) => {
795+ if ( this . isDisposed ) {
796+ return ;
797+ }
789798 const options = result ?. defaultDeploymentOptions ;
790799 if ( options ) {
791800 // Clear default excludeObjectTypes — no default exclude options for the publish dialog.
@@ -801,6 +810,8 @@ export class PublishProjectWebViewController extends FormWebviewController<
801810 . catch ( ( err ) => {
802811 this . logger . error ( "Failed to fetch deployment options:" , err ) ;
803812 } ) ;
813+ // Intentionally not awaited here — callers await _deploymentOptionsPromise before using the options.
814+ void this . _deploymentOptionsPromise ;
804815 }
805816
806817 // Get the project properties from the proj file
@@ -1321,6 +1332,8 @@ export class PublishProjectWebViewController extends FormWebviewController<
13211332 }
13221333
13231334 try {
1335+ // Ensure deployment options are loaded before saving profile.
1336+ await this . _deploymentOptionsPromise ;
13241337 const databaseName = state . formState . databaseName || projectName ;
13251338 // Connection string depends on publish target:
13261339 // - For container targets: empty string because we're provisioning a new container
@@ -1397,6 +1410,8 @@ export class PublishProjectWebViewController extends FormWebviewController<
13971410 // Request handler to generate sqlpackage command string
13981411 this . onRequest ( GenerateSqlPackageCommandRequest . type , async ( params ) => {
13991412 try {
1413+ // Ensure deployment options are loaded before building the command.
1414+ await this . _deploymentOptionsPromise ;
14001415 const dacpacPath = this . state . projectProperties ?. dacpacOutputPath ;
14011416
14021417 if ( ! dacpacPath ) {
0 commit comments