4

.dacpac是否可以从现有 SSDT 项目创建“新”文件?我希望能够在每次自动端到端测试之前重新创建数据库(拆卸 + 设置):

const string dacPacFileName = @"D:\Bla.dacpac";
var connectionString = ConfigurationManager.ConnectionStrings["BlaConnectionString"].ConnectionString;

var dacPackage = DacPackage.Load(dacPacFileName);
var dacServices = new DacServices(connectionString);      
var dacOptions = new DacDeployOptions();
dacOptions.CreateNewDatabase = true;
dacServices.Deploy(dacPackage, "Bla", true, dacOptions); 
4

2 回答 2

3

我已经使用 PowerShell 通过调用类似

> msbuild.exe <mysolution>.sln /p:Configuration=<myconfig>

这将构建解决方案,并且应该制作 dacpac。

之后我打电话

> sqlpackage.exe /Action:<someaction> /SourceFile:<thatdacpac> /Profile:<publishprofile>

但如果您正在部署 dacpac,而不是进行模式比较和发布,您可能只需要第一步。这些帮助有用?

于 2015-12-08T22:35:12.603 回答
2
var process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo
{
    WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
    FileName = @"C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe",
    Arguments = "/TargetFile:D:/output_target.dacpac /Action:Extract 
                /SourceServerName:ServerName /SourceDatabaseName:DatabaseName 
                /SourceUser:UserId /SourcePassword:Password"
};
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
于 2020-03-23T10:06:25.830 回答