如何将自定义 SQLCLR 程序集添加到 Visual Studio 数据库项目

发布于 12-13 17:12 字数 133 浏览 3 评论 0原文

我在同一解决方案中有数据库项目和 SQLCLR 数据库项目。这两个项目都将代码部署到数据库,但是我希望数据库项目负责所有代码的部署,包括自定义程序集。

我们使用数据库项目部署到我们的暂存和生产环境,目前还不清楚如何部署单独项目的程序集。

I have Database project and a SQLCLR database project in the same solution. Both projects deploy code to a database, however I would like the database project to be responsible for the deployment of all the code, including the custom assembly.

We use the database project to deploy to our staging and production environments, what's unclear is how to get the assembly of the seperate project to be deployed as well.

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

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

发布评论

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

评论(2

七禾2024-12-20 17:12:30

事实证明这非常简单。在数据库项目中添加对 SqlClr 项目的引用。然后,数据库项目将自动识别程序集,并将其添加到其脚本集中。

将程序集添加到数据库后,在 CLR 类型、函数、聚合等的创建脚本中引用它就很简单了。

逐步添加 SQLCLR 聚合函数:
1)右键单击数据库项目->添加参考。
从解决方案中的项目列表中选择SQL CLR项目

2)切换到数据库Schema(View -> Database Schema View)
验证程序集是否出现在程序集文件夹中

3) 深入到函数文件夹(架构 -> dbo -> 可编程性 -> 函数)
右键单击并添加->功能->聚合函数

相应地编辑模板以创建聚合。

现在,数据库项目是完整的部署单元,并且 SQL CLR 项目不再需要作为部署的一部分。

As it turns out this is very simple. In the Database project add a reference to the SqlClr project. The database project will then automatically identify the assembly, and add it to it's set of scripts.

With the assembly added to to the database, it's a simple matter to reference it in the create scripts of the CLR types, functions, aggregates, etc.

Step by step to adda SQLCLR aggregate function:
1) right-click the database project -> Add Reference.
Select the SQL CLR project from the list of projects in the solution

2) Switch to the database Schema (View -> Database Schema View)
Verify that the Assembly appears in the Assemblies foler

3) Drill down to the Functions Folder (Schema -> dbo -> Programmability -> Functions)
Right click and Add -> Function -> Aggregate Function

Edit the template accordingly to create the aggregate.

Now the database project is the a complete unit of deployment and the SQL CLR project is not needed as part of the deployment.

零時差2024-12-20 17:12:30

这两个项目文件都是msbuild项目文件。因此,您可以使用 msbuild 脚本来驱动它们。

数据库项目导入此文件。
$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.SqlTask​​s.targets

在我的 64 位机器中

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamData

它有类似的目标
DSP构建
Dsp安装部署
DspDeploy

当 SqlClr 项目导入时,

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.SqlClr.targets

它具有诸如

SqlClrDeploy

调用两个部署目标的简单 msbuild 文件之类的目标应该足够了。

或者,您可以自定义数据库项目的文件,以在构建其他文件的目标之前调用。这会更复杂。

This two project file are msbuild project files. Therefore you can use a msbuild script to drive both of them.

Database Project imports this file.
$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.SqlTasks.targets

In my 64 bit machine

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamData

It has targets like
DspBuild
DspSetupDeploy
DspDeploy

While SqlClr project imports

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.SqlClr.targets

It has targets like

SqlClrDeploy

A simple msbuild file which calls both of deploy target should be enough.

Or you can customize database project's file to call before build to other file's target. Which will be more complex.

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