- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我需要能够以编程方式发布 SSDT 项目。我正在考虑使用 Microsoft.Build 这样做,但找不到任何文档。创建 .dacpac 似乎很简单,但我将如何发布到现有数据库或至少发布到 .sql 文件。我的想法是让它做当我右键单击项目并选择发布时它所做的事情。它应该与选定的数据库进行比较并生成升级脚本。
这是我到目前为止创建 .dacpac 的方法:
partial class DBDeploy
{
Project project;
internal void publishChanges()
{
Console.WriteLine("Building project " + ProjectPath);
Stopwatch sw = new Stopwatch();
sw.Start();
project = ProjectCollection.GlobalProjectCollection.LoadProject(ProjectPath);
project.Build();
//at this point the .dacpac is built and put in the debug folder for the project
sw.Stop();
Console.WriteLine("Project build Complete. Total time: {0}", sw.Elapsed.ToString());
}
}
本质上我正在尝试做这个 MSBuild Example显示但在代码中。
抱歉,我只有这些。 Build 类的文档非常差。任何帮助将不胜感激。
谢谢。
最佳答案
我不得不做类似的事情,因为我们之前使用的 VSDBCMD 没有部署到 SQL Server 2012,我们需要支持它。我发现的是 Microsoft.SqlServer.Dac 程序集,它似乎是 SQL Server 数据工具的一部分 (http://msdn.microsoft.com/en-us/data/tools.aspx)
当您在客户端计算机上运行此程序时,您将需要完整版本的 .NET 4 框架和 SQL CLR 类型以及可在此处找到的 SQL T-SQL ScriptDOM 包:http://www.microsoft.com/en-us/download/details.aspx?id=29065
下面的代码来 self 为测试新部署方法和部署给定的 .dacpac 文件而制作的模型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Dac;
using System.IO;
namespace ConsoleApplication3
{
class Program
{
private static TextWriter output = new StreamWriter("output.txt", false);
static void Main(string[] args)
{
Console.Write("Connection String:");
//Class responsible for the deployment. (Connection string supplied by console input for now)
DacServices dbServices = new DacServices(Console.ReadLine());
//Wire up events for Deploy messages and for task progress (For less verbose output, don't subscribe to Message Event (handy for debugging perhaps?)
dbServices.Message += new EventHandler<DacMessageEventArgs>(dbServices_Message);
dbServices.ProgressChanged += new EventHandler<DacProgressEventArgs>(dbServices_ProgressChanged);
//This Snapshot should be created by our build process using MSDeploy
Console.WriteLine("Snapshot Path:");
DacPackage dbPackage = DacPackage.Load(Console.ReadLine());
DacDeployOptions dbDeployOptions = new DacDeployOptions();
//Cut out a lot of options here for configuring deployment, but are all part of DacDeployOptions
dbDeployOptions.SqlCommandVariableValues.Add("debug", "false");
dbServices.Deploy(dbPackage, "trunk", true, dbDeployOptions);
output.Close();
}
static void dbServices_Message(object sender, DacMessageEventArgs e)
{
output.WriteLine("DAC Message: {0}", e.Message);
}
static void dbServices_ProgressChanged(object sender, DacProgressEventArgs e)
{
output.WriteLine(e.Status + ": " + e.Message);
}
}
}
这似乎适用于 2005 及更高版本的 SQL Server。 Microsoft.SqlServer.Management.Dac 中有一组类似的对象,但我相信这是在以前版本的 DACFx 中,未包含在最新版本中。因此,如果可以,请使用最新版本。
关于c# - 使用 Microsoft.Build.Evaluation 发布数据库项目 (.sqlproj),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10438258/
在厌倦了使用 hierarchyids 来管理我的节点树之后,我决定尝试使用 SQL Server 2017 的图形功能来缓解我的麻烦。 虽然我有点困惑。目前,我所有的 SQL 脚本都存储和组织在一个
我们的 .sqlproj 包含很多这样的语句,用于项目中存在的每个对象: 每当一个对象被添加到项目中时,SSDT 将通过在文件的随机行中添加一条记录来自动更新 sqlproj 文件。当多个开发人
目前 .sqlproj 文件有 15 条代码分析规则(SR0001 到 SR0015)。我想创建自己的代码分析规则,以确保对 where 子句中使用的列进行索引。 我将如何扩展当前的 .sqlproj
我正在尝试使用 Azure DevOps Pipelines 从 GitHub 构建我的 .NET Core 2.1 解决方案。它包含一个 SQL 项目,其 TargetFrameworkVersio
当我在 Visual Studio 解决方案中有一个 SQL Server 数据库项目 ( .sqlproj ) 时,我注意到每次构建解决方案时总是会构建该特定项目,即使项目文件没有更改。 这与正常不
无法使用“dotnet”命令行工具构建 .Net .sqlproj。这是错误: dotnet\sdk\3.1.300\Microsoft\VisualStudio\v11.0\SSDT\Microso
我继承了一个包含 .SQLPROJ 的 VS2010 项目。 我对 .csproj 没有任何问题。但是我在解决方案中打开 .SQLPROJ 时遇到问题。当我尝试打开 .SQLPROJ 时,出现以下错误
对于数据库项目中的sql脚本文件,使用Build或Compile的Build Action有什么好处吗?我通常只使用 None,但想知道 Build 或 Compile 是否对 sql 脚本执行任何操
我有许多 .sqlproj 项目需要在我们的构建服务器上构建。我不想在构建服务器上安装所有 Visual Studio,这样我就可以安装 SSDT 来构建它们。如何在没有完整 VS 安装的情况下构建
这一切都始于 TC 内的 VS2017 运行者类型。它失败了,没有任何错误或提示(除了解决方案级别的 (default Targets) -- FAILED. 消息)。我将范围缩小到 .sqlproj
我继承了从 VS2013 开始的 C# 代码库。我们现在正在转向 VS2017(从 VS2015)。该解决方案包含许多用于管理数据库架构的.rptproj 项目。安装后 MS Report Proje
我需要能够以编程方式发布 SSDT 项目。我正在考虑使用 Microsoft.Build 这样做,但找不到任何文档。创建 .dacpac 似乎很简单,但我将如何发布到现有数据库或至少发布到 .sql
我有一个旧的解决方案,我正在尝试使用其中的当前项目构建一个更新的解决方案。其中一个项目是 SQLUtils,它只包含 .cs 文件,它的目标框架是 .NET Framework 2.0。 在旧的解决方
我想在 linux 容器中构建一个 .sqlproj。问题是构建 .sqlproj 依赖于 SSDT 和 到目前为止,我找不到可以在 linux 上独立安装的 SSDT . 我看到在我的容器中运行“d
我正在努力通过 VS2013 部署 SQLProj(数据库项目),但遇到了一个可以使用一些反馈的问题。 当我发布更改时,它会为表执行 CCRD(创建、复制、重命名、删除)操作。在 PreDeploy
我们一直使用 .sqlproj 扩展名使用 VS2012 SSDT 完成我们的数据库设计和开发,并使用带有 DACPAC 的 SQLPackage 部署到 SQL Server ......或者从 V
我们有一个 sqlproj以本地 SQL 2014 为目标。生成和发布按 Visual Studio 的预期工作。 现在我们正在尝试使用 VS Online 构建数据库项目并将其部署到 Azure 数
我刚刚将现有的 SQL Server 2008 r2 .dbproj 升级到 SQL Server 2012 .sqlproj(使用 SQL Server Data Tools)。 以前,我能够在我的
我对Visual Studio 2017中的Git不是很熟悉,我从一个分支新建了一个分支。做了一些改动。将新更改推送到我们在 visualstudio.com 上的 repo。创建了一个新的 pull
我是一名优秀的程序员,十分优秀!