且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Visual Studio 2012中创建/打开DAC应用程序?

更新时间:2022-06-05 02:51:42

DACPAC的目的是提供数据库模式的可移植表示形式,可用于将该模式部署到数据库中,并将其导入数据库中Visual Studio中的项目,并在Schema Compare之类的功能中使用以检查不同源之间的差异.每当您在Visual Studio中构建数据库项目时,都会生成一个.dacpac文件,然后可以将其用于将该项目中定义的架构部署到数据库中.

The purpose of a DACPAC is to provide a portable representation of a database schema, that can be used to deploy that schema to a database, import it into a database project in Visual Studio, and be used in functions like Schema Compare to examine differences between different sources. Whenever you build a database project in Visual Studio a .dacpac file will be generated, and this can then be used to deploy the schema defined in that project to a database.

完整信息的***位置是 SSDT帮助,但是我给您一个简短的摘要.

The best place for full information is the SSDT help, but I'll give you a quick summary.

如果您已经拥有DACPAC,则可以通过以下方式在VS中使用它:

If you already have a DACPAC, you can use it in VS in the following ways:

  • 通过在解决方案资源管理器中右键单击项目,然后选择导入->数据层应用程序(* .dacpac)",将模式导入到项目中.然后选择您的dacpac,内容将转换为SQL脚本并添加到项目中.
  • 通过打开SQL Server对象资源管理器,导航到服务器,右键单击数据库并选择发布数据层应用程序...",将dacpac发布到数据库中.这会将DACPAC的内容发布到数据库中在该服务器上.您可以通过右键单击数据库"列表中的数据库来更新数据库.请注意,如果未打开"SQL Server对象资源管理器"视图,则可以选择视图-> SQL Server对象资源管理器"以确保它出现.

要在Visual Studio中创建DACPAC,您可以

To create a DACPAC in Visual Studio, you can

  • 构建一个项目.这会在bin \ Debug目录中创建一个dacpac(假设您以Debug模式构建).
  • 快照项目.这将创建一个dacpac并将其保存在项目中.跟踪数据库架构的时间点版本并将数据库的早期版本与最新定义进行比较非常有用.
  • 在SQL Server对象资源管理器中右键单击数据库,然后选择提取数据层应用程序...".这将创建一个代表数据库内容的dacpac.

最后,我不确定您所观看的视频是什么,但是很可能他们显示了在SQL Server Object Explorer中右键单击数据库并从那里创建项目的情况.这是使用数据库项目开始开发的一种非常常见的方法,因为通常您已经拥有一个包含架构的数据库.通常,***实践是使用项目进行开发,并在将其部署到生产服务器等不同环境时使用dacpacs(以及可能的命令行部署工具,例如SqlPackage.exe)(同样,dacpacs非常适合传输架构定义和部署它们)到不同的环境).希望这有助于回答您的问题!

Finally I'm not sure what video you viewed, but it's possible they showed right-clicking on a DB in SQL Server Object Explorer and creating a project from there. That's a very common way to start development using a database project, since often you'll already have a database containing your schema. Generally the best practices would be to develop using a project, and use dacpacs (and possibly command line deployment tools like SqlPackage.exe) when deploying out to different environments such as your production servers (again dacpacs are great for transporting schema definitions and deploying them to different environments). Hope this helps answer your question!