Update: breaking change: http://sqlproj.com/index.php/2012/10/dacfx-sept-2012-updates-break-headless-build/

This article describes how to install the required components to build and publish SQL Server Data Tools projects (*.sqlproj) using MSBuild without installing the full SQL Server Data Tool hosted inside the Visual Studio IDE.

In order to acquire the binaries needed you have to create an Administrative install of SSDT, which is described in detail in this previously published article.

NOTE: You could download all but one components from the SQL Server 2012 Feature Pack download page, however there currently is no separate download of the SSDTBuildUtilities.msi available.

Before we start, let’s setup a small test environment first. In this example I will start with a Windows Server 2008 installation, which has .NET 4.0 installed. I created a sample project on another machine using the IDE which I want to build and publish from my server. The sample project is available online: nw-sqlproj.zip, for this example I extracted the project in to the “c:\projects\nw-sqlproj” directory.

Second step is that we have to be able to call MSBuild.exe from the command prompt. In my example I am using a 32-bit Windows Server 2008 installation, after starting a command window using cmd.exe, I can invoke MSBuild.exe using:

%WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe

Normally I create a command file, named msbuild.cmd which I place in %WINDIR%, which looks like this:

@echo off

if (%PROCESSOR_ARCHITECTURE%)==(AMD64) (
%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe %*
) else (
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe %*
)

Let’s start a command window and see what happens when we try to build our test project!

The result is clear, and expected at this point. The build fails, since the project system references the SSDT build task via the Microsoft.Data.Tools.Schema.SqlTasks.targets file.

Below the MSBuild output as text:

C:\Projects\nw-sqlproj>%WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.239]
Copyright (C) Microsoft Corporation 2007. All rights reserved. Build started 3/7/2012 3:31:19 PM.
Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" (1) is building "C:\Projects\nw-sqlproj\nw-sqlproj.sqlproj" (2) on node 1 (default targets).
C:\Projects\nw-sqlproj\nw-sqlproj.sqlproj(90,3): error MSB4019: The imported project "C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
Done Building Project "C:\Projects\nw-sqlproj\nw-sqlproj.sqlproj" (default targets) -- FAILED. Done Building Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" (default targets)
-- FAILED. Build FAILED. "C:\Projects\nw-sqlproj\nw-sqlproj.sln" (default target) (1) ->
"C:\Projects\nw-sqlproj\nw-sqlproj.sqlproj" (default target) (2) ->
C:\Projects\nw-sqlproj\nw-sqlproj.sqlproj(90,3): error MSB4019: The imported project "C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. 0 Warning(s)
1 Error(s) Time Elapsed 00:00:00.04 C:\Projects\nw-sqlproj>

In order to get the MSBuild task and dependent components installed, you need to perform the following five steps:

  1. Install the Microsoft® SQL Server® 2012 Data-Tier Application FrameworkX86 Package(dacframework.msi)X64 Package (dacframework.msi)
  2. Install the Microsoft® SQL Server® 2012 Transact-SQL ScriptDomX86 Package(SQLDOM.MSI)X64 Package (SQLDOM.MSI)
  3. Install the Microsoft® SQL Server® 2012 Transact-SQL Compiler ServiceX86 Package(SQLLS.MSI)X64 Package (SQLLS.MSI)
  4. Install the Microsoft® System CLR Types for Microsoft® SQL Server® 2012X86 Package(SQLSysClrTypes.msi)X64 Package (SQLSysClrTypes.msi)
  5. Install the SQL Server Data Tools Build Utilities from the Administrative install point.\ssdt\x86\SSDTBuildUtilities.msi

Now we are ready to try again!

And we can now successfully build our project.

Below the MSBuild output as text:

C:\Projects\nw-sqlproj>%WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.239]
Copyright (C) Microsoft Corporation 2007. All rights reserved. Build started 3/7/2012 3:52:23 PM.
Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" (1) is building "C:\Projects\nw-sqlproj\nw-sqlproj.sqlproj" (2) on node 1 (default targets).
GenerateSqlTargetFrameworkMoniker:
Skipping target "GenerateSqlTargetFrameworkMoniker" because all output files are up-to-date with respect to the input files.
CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
SqlBuild:
Skipping target "SqlBuild" because all output files are up-to-date with respect
to the input files.
CopyFilesToOutputDirectory:
nw-sqlproj -> C:\Projects\nw-sqlproj\bin\Debug\nw_sqlproj.dll
SqlPrepareForRun:
nw-sqlproj -> C:\Projects\nw-sqlproj\bin\Debug\nw-sqlproj.dacpac
Done Building Project "C:\Projects\nw-sqlproj\nw-sqlproj.sqlproj" (default targ
ets). Done Building Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" (default targets)
. Build succeeded.
0 Warning(s)
0 Error(s) Time Elapsed 00:00:00.40 C:\Projects\nw-sqlproj>

Now that we can build lets publish our project, using MSBuild.

C:\Projects\nw-sqlproj>msbuild /t:Publish /p:SqlPublishProfilePath=nw-sqlproj.publish.xml

This will publish the project to the server specified in the publish profile, which is an MSBuild structure XML file.

nw-sqlproj.publish.xml

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>NorthwindTest</TargetDatabaseName>
<DeployScriptFileName>nw-sqlproj.sql</DeployScriptFileName>
<TargetConnectionString>Data Source=localhost;Integrated Security=True;Pooling=False</TargetConnectionString>
<ProfileVersionNumber>1</ProfileVersionNumber>
</PropertyGroup>
</Project>

MSBuild output of the Deploy operation:

C:\Projects\nw-sqlproj>msbuild /t:Publish /p:SqlPublishProfilePath=nw-sqlproj.pblish.xml
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.239]
Copyright (C) Microsoft Corporation 2007. All rights reserved. Build started 3/7/2012 5:37:52 PM.
Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" on node 1 (Publish target(s)).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" (1) is building "C:\Projects\nw -sqlproj\nw-sqlproj.sqlproj" (2) on node 1 (Publish target(s)).
SqlPublish:
Deployment script generated to:
C:\Projects\nw-sqlproj\bin\Debug\nw-sqlproj.publish.sql Creating NorthwindTest...
Creating [dbo].[Categories]...
Creating [dbo].[Categories].[CategoryName]...
Creating [dbo].[CustomerCustomerDemo]...
Creating [dbo].[CustomerDemographics]...
Creating [dbo].[Customers]...
Creating [dbo].[Customers].[City]...
Creating [dbo].[Customers].[CompanyName]...
Creating [dbo].[Customers].[PostalCode]...
Creating [dbo].[Customers].[Region]...
Creating [dbo].[Employees]...
Creating [dbo].[Employees].[LastName]...
Creating [dbo].[Employees].[PostalCode]...
Creating [dbo].[EmployeeTerritories]...
Creating [dbo].[Order Details]...
Creating [dbo].[Order Details].[OrderID]...
Creating [dbo].[Order Details].[OrdersOrder_Details]...
Creating [dbo].[Order Details].[ProductID]...
Creating [dbo].[Order Details].[ProductsOrder_Details]...
...
...<lines deleted for clarity> Update complete.
Done Building Project "C:\Projects\nw-sqlproj\nw-sqlproj.sqlproj" (Publish target(s)). Done Building Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" (Publish target(s)). Build succeeded.
0 Warning(s)
0 Error(s) Time Elapsed 00:00:06.43 C:\Projects\nw-sqlproj>

And if we would publish it again, by default it will only perform an incremental update!

C:\Projects\nw-sqlproj>msbuild /t:Publish /p:SqlPublishProfilePath=nw-sqlproj.publish.xml
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.239]
Copyright (C) Microsoft Corporation 2007. All rights reserved. Build started 3/7/2012 5:41:23 PM.
Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" on node 1 (Publish target(s)).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" (1) is building "C:\Projects\nw-sqlproj\nw-sqlproj.sqlproj" (2) on node 1 (Publish target(s)).
SqlPublish:
Deployment script generated to:
C:\Projects\nw-sqlproj\bin\Debug\nw-sqlproj.publish.sql Update complete.
Done Building Project "C:\Projects\nw-sqlproj\nw-sqlproj.sqlproj" (Publish target(s)). Done Building Project "C:\Projects\nw-sqlproj\nw-sqlproj.sln" (Publish target(s)). Build succeeded.
0 Warning(s)
0 Error(s) Time Elapsed 00:00:11.50 C:\Projects\nw-sqlproj>

We are done, we enabled build and publishing from MSBuild, without installing the SQL Server Data Tools IDE inside the Visual Studio shell.

I hope this helps you getting started with SQL Server Data Tools (SSDT)

Headless MSBuild Support for SSDT (*.sqlproj) Projects [利用msbuild自动化部署 .sqlproj]- 摘自网络的更多相关文章

  1. 利用 Ansiable 自动化部署 Veeam Backup & Replication 9.5U4b

    利用 Ansiable 自动化部署 Veeam Backup & Replication 9.5U4b 前言 上周出差期间接到一个做CMP(云管平台)Partner的需求,要在无人值守的安装 ...

  2. Headless MSBuild Support for SSDT (*.sqlproj) Projects

    http://sqlproj.com/index.php/2012/03/headless-msbuild-support-for-ssdt-sqlproj-projects/ Update: bre ...

  3. 如何使用SSDT进行SQL数据库的自动化部署到生产环境和版本控制

    简介 在开发过程,我们常常会遇到数据库环境部署的问题,当部署正式环境中,数据库产生的多文件脚本在管理上就容易出现混乱,特别是你还没有权限访问正式环境的情况,就更为困难.SSDT为我们提供了很好的解决方 ...

  4. 利用PowerShell+Jenkins,实现项目的自动化部署

    当项目越来越庞大,部署环境越来越多以后,就会越来越依赖于自动化.比如本人公司的项目,目前有6个web和4个windows service,同时本地有两套环境:开发自测试环境和QA测试环境.每次版本发布 ...

  5. 利用WSGI来部署你的网站

    利用WSGI来部署你的网站 当需要部署你的django项目的时候,可以使用apache+python来部署访问你的网站. 由于网上的有关的都是老版本的.所以这里使用apache2.4和python3. ...

  6. Android利用tcpdump和wireshark抓取网络数据包

    Android利用tcpdump和wireshark抓取网络数据包 主要介绍如何利用tcpdump抓取andorid手机上网络数据请求,利用Wireshark可以清晰的查看到网络请求的各个过程包括三次 ...

  7. 利用jenkins做项目的自动化部署

    最近领导要求上海本地的项目需要使用进jenkins实现自动化部署,以便可以直接将项目移交给运维的同学,减轻开发的工作量.记录下这次爬坑的过程. 一.前言 Jenkins是基于Java开发的一种持续集成 ...

  8. Asp.Net Core 轻松学-利用xUnit进行主机级别的网络集成测试

    前言     在开发 Asp.Net Core 应用程序的过程中,我们常常需要对业务代码编写单元测试,这种方法既快速又有效,利用单元测试做代码覆盖测试,也是非常必要的事情:但是,但我们需要对系统进行集 ...

  9. 自动化部署-Jenkins+SVN+MSBuild

    这篇文章主要介绍下使用Jenkins实现自动化部署 下载 https://jenkins.io/download/ 安装 按步骤安装即可,下载的是windows版本,安装完成后,会看到这样一个正在运行 ...

随机推荐

  1. 【BZOJ】1006: [HNOI2008]神奇的国度 弦图消除完美序列问题

    1006: [HNOI2008]神奇的国度 Description K国是一个热衷三角形的国度,连人的交往也只喜欢三角原则. 他们认为三角关系:即AB相互认识,BC相互认识,CA相互认识,是简洁高效的 ...

  2. 产生一个长度为100的int数组,并向其中随机插入1-100,不能重复

    ]; ArrayList myList=new ArrayList(); Random rnd=new Random(); ) { ,); if(!myList.Contains(num)) myLi ...

  3. Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]:思考题——谢勤政11061197

    第一题: 大楼里面的电梯一般分区域,或考虑思考题第四题的情况,运行楼层不一样的电梯属于不同的区域.然后在接口IRequest和IPassenger还有IElevator里面都加上int area这个属 ...

  4. css3 Transition动画执行时有可能会出现闪烁的bug

    css3 Transition动画执行时有可能会出现闪烁的bug,一般出现在开始的时候. 解决方法: 1.-webkit-backface-visibility: hidden; 2.-webkit- ...

  5. mysql的错误:The server quit without updating PID file /usr/local/mysql/data/door.pid).

    mysql错误解决: 先 参考:http://www.jb51.net/article/48625.htm 参考第四条: mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打 ...

  6. Ubuntu 14.04 开启启动器图标最小化功能

    转自Ubuntu 14.04 怎样开启启动器图标最小化功能 前本站报道过 Ubuntu 14.04 终于加入了启动器图标最小化功能,这个功能默认是不开启的,要怎么开启呢? 之前报道的原文阅读:Ubun ...

  7. Windows Phone 8 开发环境搭建

    原地址:http://blog.csdn.net/md521/article/details/11015139 Windows Phone 8将采用与Windows 8相同的NT内核,这就意味着WP8 ...

  8. 在8086中,[ idata],[bx]表示内存单元时。可能是一个字节,也可能是一个字。

    可能表示一个字节,也可能表示一个字.主要由指令中另一个计算对象决定.如al表示一个字节.ax就表示一个字. 这个区别主要体现在循环中,偏移地址的循环变量是加1还是加2,al是偏移地址加1,ax是偏移地 ...

  9. [unity菜鸟] controller.SimpleMove(transform .forward); 无法移动

    今天做demo时遇到一个问题:当使用角色控制器操作物体,用 controller.SimpleMove(transform .forward); 语句时物体不能移动,搜索请教了很久,最后终于googl ...

  10. 汉字与区位码互转(天天使用的String存储的是内码),几个常见汉字编码,附有读书笔记

    汉=BABA(内码)=-A0A0=2626(区位码)字=D7D6(内码)=-A0A0=5554(区位码) 各种编码查询表:http://bm.kdd.cc/ “啊”字是GB2312之中的第一个汉字,会 ...