- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.7k
Description
New issue checklist
- I searched for existing GitHub issues
- I read pipeline troubleshooting guide
- I checked how to collect logs
Task name
SqlAzureDacpacDeployment
Task version
1.257.0
Issue Description
What happened:
When using the SqlAzureDacpacDeployment task (v1) in classic Azure DevOps pipelines, along with the Export-Bacpac (backup/export) task, both tasks generate files in the same fixed path:
$(System.DefaultWorkingDirectory)\GeneratedOutputFiles\<DatabaseName>.bacpac
$(System.DefaultWorkingDirectory)\GeneratedOutputFiles\<DatabaseName>.dacpac
For example, if you run a backup step and then a deploy step for the same database name, the deploy task will overwrite or attempt to overwrite the backup file, leading to either loss of the backup or a 'file in use' error if the backup is still open.
Code evidence:
From SqlAzureActions.ps1:
$targetDacpacFilePath = "$ENV:SYSTEM_DEFAULTWORKINGDIRECTORY\GeneratedOutputFiles\$databaseName.dacpac"
Write-Host (Get-VstsLocString -Key "SAD_GeneratedFile" -ArgumentList "$targetDacpacFilePath")
Write-Host "##vso[task.uploadfile]$targetDacpacFilePath"
Write-Host (Get-VstsLocString -Key "SAD_SetOutputVariable" -ArgumentList "SqlDeploymentOutputFile", $targetDacpacFilePath)
Write-Host "##vso[task.setVariable variable=SqlDeploymentOutputFile]$targetDacpacFilePath"From Export-Bacpac in the same file:
$targetBacpacFilePath = "$ENV:SYSTEM_DEFAULTWORKINGDIRECTORY\GeneratedOutputFiles\$databaseName.bacpac"
Write-Host (Get-VstsLocString -Key "SAD_GeneratedFile" -ArgumentList "$targetBacpacFilePath")
Write-Host "##vso[task.uploadfile]$targetBacpacFilePath"
Write-Host (Get-VstsLocString -Key "SAD_SetOutputVariable" -ArgumentList "SqlDeploymentOutputFile", $targetBacpacFilePath)
Write-Host "##vso[task.setVariable variable=SqlDeploymentOutputFile]$targetBacpacFilePath"Example log:
The process cannot access the file 'D:\a\1\s\GeneratedOutputFiles\MyDb.dacpac' because it is being used by another process.
Repro steps:
- Create a backup .dacpacfile in$(System.DefaultWorkingDirectory)\GeneratedOutputFiles\MyDb.dacpac
- Run SqlAzureDacpacDeployment task for the same database name MyDb
- Both tasks use the same path and name, causing one to overwrite the other or fail.
Expected behavior:
The deployment (and backup/export) tasks should not overwrite user-created artifacts or use hardcoded file paths/names that can easily collide with user files. File name/path for temporary/intermediate files should be configurable, or the tasks should generate unique file names to avoid such collisions.
Impact:
- User backups or artifacts may be lost or corrupted.
- The task fails if the file is locked, blocking pipeline execution.
- Users have no way to avoid this except by knowing the internal file naming.
Suggested solutions:
- Add an input to configure the path/name of the intermediate .dacpac/.bacpacfile.
- Generate unique names (e.g., with a build ID or a GUID) for intermediate files by default.
- Document the internal filenames used by the tasks, or avoid using user-accessible directories for temporary files.
Environment type (Please select at least one enviroment where you face this issue)
- Self-Hosted
- Microsoft Hosted
- VMSS Pool
- Container
Azure DevOps Server type
dev.azure.com (formerly visualstudio.com)
Azure DevOps Server Version (if applicable)
N/A
Operation system
Windows Server 2022
Relevant log output
2025-10-06T13:39:51.7517426Z ##[error]The process cannot access the file '[DATABASE-NAME].bacpac' because it is being used by another process.Full task logs with system.debug enabled
2025-10-06T13:36:45.6927365Z ##[section]Starting: Azure SQL Backup
2025-10-06T13:36:45.6936543Z ==============================================================================
2025-10-06T13:36:45.6936683Z Task         : Azure SQL Database deployment
2025-10-06T13:36:45.6936757Z Description  : Deploy an Azure SQL Database using DACPAC or run scripts using SQLCMD
2025-10-06T13:36:45.6936874Z Version      : 1.257.0
...
2025-10-06T13:39:38.3594065Z Successfully exported database and saved it to file 'C:\myagent_work\r1\a\GeneratedOutputFiles[DATABASE-NAME].bacpac'.
2025-10-06T13:39:38.3597345Z Time elapsed 0:02:36.19
2025-10-06T13:39:38.3835312Z Generated file C:\myagent_work\r1\a\GeneratedOutputFiles[DATABASE-NAME].bacpac. Uploading file to the logs.
2025-10-06T13:39:38.3857728Z Setting output variable 'SqlDeploymentOutputFile' to 'C:\myagent_work\r1\a\GeneratedOutputFiles[DATABASE-NAME].bacpac'
2025-10-06T13:39:38.4287812Z ##[section]Finishing: Azure SQL Backup
...
2025-10-06T13:39:38.4311486Z ##[section]Starting: Azure SQL Generate Script
2025-10-06T13:39:38.4320626Z ==============================================================================
...
2025-10-06T13:39:51.7517426Z ##[error]The process cannot access the file '[DATABASE-NAME].bacpac' because it is being used by another process.Check out how to troubleshoot failures at https://aka.ms/sqlazuredeployreadme#troubleshooting-
Repro steps
1. Step: Create a backup .dacpac file in $(System.DefaultWorkingDirectory)\GeneratedOutputFiles\MyDb.dacpac
2. Step: Run SqlAzureDacpacDeployment task for the same database name (MyDb)
3. Both tasks use the same path and name, causing one to overwrite the other or fail.
Expected: The deployment should proceed without affecting the backup.
Actual: The backup file is overwritten or the task fails with a file lock error.