是否可以从现有的SSDT项目中创建一个"新的".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 FilesMicrosoft SQL Server150DACbinSqlPackage.exe",
Arguments = "/TargetFile:D:/output_target.dacpac /Action:Extract
/SourceServerName:ServerName /SourceDatabaseName:DatabaseName
/SourceUser:UserId /SourcePassword:Password"
};
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();