从 Visual Studio 中的数据库项目执行脚本

发布于 2024-07-29 17:33:06 字数 232 浏览 3 评论 0原文

我正在尝试使用数据库项目 (*.dbp) 将一些存储过程添加到 Visual Studio 中的构建过程(使用 MSBuild)。

然而,与 VS 中可用的其他一些数据库项目不同,它无法构建或运行。 (我相信这是我想要的项目文件,因为我正在使用 SQL2000

如何在构建项目时运行 SQL 脚本? 我知道我可以通过右键单击并按运行来运行脚本...但这不是问题。

I am trying to add some stored procedures to a build process in visual studio (using MSBuild) with a database project (*.dbp).

However unlike some of the other database projects available in VS, it cannot be built or run. ( I believe this is the project file i want as I am using SQL2000)

How can I get the SQL scripts to run as I build the project?
I know that I can run the scripts by right clicking and pressing run....but that is not the question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吾家有女初长成 2024-08-05 17:33:06

数据库项目的构建与普通项目不同。 如果您想在该项目中执行脚本,我的建议是扩展与 MSBuild 兼容的关联项目(csproj、vbproj 等),并使用您选择的工具从那里引用/执行您的脚本。

如何实现它取决于您,例如,您可以连接到 BeforeBuild 使用 SqlExecute 任务定位并执行脚本。

FWIW,我们必须支持 SQL Server 2000、2005、2008+,因此任务变得更加困难; 想想 NVarchar(max) (2005+) 与 NText (2000+) 以及版本之间的所有 sp 重命名等。 我们还需要一个供开发人员、QA 和安装人员使用的单一脚本来确保一致性。 因此,我们的方法是一个自定义工具,它允许在脚本内替换令牌/关键字,从而在不同的 SQL Server 版本和客户安装(例如用户/登录详细信息、数据库名称)之间提供灵活性,并集成到各种技术中,以便脚本可以从命令行、MSBuild、使用 Wix 项目的 MSI 自定义操作,或者我们需要它们运行的​​任何内容。

Database projects are not built like normal projects. If you want to execute scripts inside this project, my advice would be to extend the associated project(s) which are MSBuild compatible (csproj, vbproj, etc.) and reference/execute your scripts from there using your tool of choice.

How you implement it is up to you, for example, you could hook into BeforeBuild target and execute scripts using SqlExecute task.

FWIW, we have to support SQL Server 2000, 2005, 2008+, so the task becomes much harder; think NVarchar(max) (2005+) vs NText (2000+) plus all the sp renames, etc between versions. We also wanted a single script which developers, QA and installer used to ensure consistency. So our approach was a custom tool which allowed token/keyword replacements inside scripts, which provides flexibility between different SQL Server versions and customers installations (e.g. user/login details, db names), as well as integration into various technologies so scripts can run from command line, MSBuild, MSI custom action using Wix projects, or whatever we need them to run from.

巷子口的你 2024-08-05 17:33:06

可以构建数据库项目。

它们无法运行 - 它们可以部署。

部署时,项目会构建然后部署。 该代码将与预构建和构建后脚本以及部署前和部署后脚本一起部署。

因此,如果您希望脚本在构建项目时运行,则需要查看项目属性中“构建事件”下的“预构建”和“后构建”。

Database projects can be Built.

They cannot be run - they can be Deployed.

When you deploy, the project builds and then deploys. The code will be deployed along with the Pre-Build and Post-Build scripts and the Pre-Deployment and Post-Deployment scripts.

So if you want scripts to run as you BUILD the project, you want to look into the Pre-Build and Post-Build under Build Events in the Project properties.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文