从 SSDT 项目以编程方式创建 dacpac 文件
Create dacpac file programmatically from SSDT project
是否可以从现有的 SSDT 项目创建 'fresh' .dacpac
文件?我希望能够在每次自动端到端测试之前重新创建数据库(拆卸 + 设置):
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);
我已经使用 PowerShell 通过调用类似
的方式完成了此操作
> msbuild.exe <mysolution>.sln /p:Configuration=<myconfig>
这将生成解决方案并且应该生成 dacpac。
之后我打电话给
> sqlpackage.exe /Action:<someaction> /SourceFile:<thatdacpac> /Profile:<publishprofile>
但是如果您要部署 dacpac 而不是进行模式比较和发布,则您可能只需要第一步。这有什么帮助吗?
var process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo
{
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
FileName = @"C:\Program Files\Microsoft SQL Server0\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();
是否可以从现有的 SSDT 项目创建 'fresh' .dacpac
文件?我希望能够在每次自动端到端测试之前重新创建数据库(拆卸 + 设置):
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);
我已经使用 PowerShell 通过调用类似
的方式完成了此操作> msbuild.exe <mysolution>.sln /p:Configuration=<myconfig>
这将生成解决方案并且应该生成 dacpac。
之后我打电话给
> sqlpackage.exe /Action:<someaction> /SourceFile:<thatdacpac> /Profile:<publishprofile>
但是如果您要部署 dacpac 而不是进行模式比较和发布,则您可能只需要第一步。这有什么帮助吗?
var process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo
{
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
FileName = @"C:\Program Files\Microsoft SQL Server0\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();