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

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的更多相关文章

  1. Headless MSBuild Support for SSDT (*.sqlproj) Projects [利用msbuild自动化部署 .sqlproj]- 摘自网络

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

  2. Using MSBuild to publish a VS 2012 SSDT .sqlproj database project

    http://blog.danskingdom.com/using-msbuild-to-publish-a-vs-2012-ssdt-sqlproj-database-project-the-sam ...

  3. Using Headless Mode in the Java SE Platform--转

    原文地址: By Artem Ananiev and Alla Redko, June 2006     Articles Index This article explains how to use ...

  4. SSDT – Error SQL70001 This statement is not recognized in this context-摘自网络

    March 28, 2013 — arcanecode One of the most common errors I get asked about when using SQL Server Da ...

  5. CMake support in Visual Studio

    Visual Studio 2017 introduces built-in support for handling CMake projects. This makes it a lot simp ...

  6. Visual Studio For MacOS .NetCore开发踩坑记

    自从Visual Studio For  MacOS公布以来,就开始尝试在Mac上进行net core开发.断断续续遇到了各种奇奇怪怪的问题.虽然大部分利用google查查(百度屁都查不出来),都能找 ...

  7. Multi-Targeting and Porting a .NET Library to .NET Core 2.0

    Creating a new .NET Standard Project The first step for moving this library is to create a new .NET ...

  8. ASP.NET Core 阶段性总结

    自从年前用 ASP.NET 5 磕磕绊绊重写了一个项目后 (2015.12),就没怎么关注 ASP.NET 5 相关内容了,为啥?因为实际应用问题太多,而且不是正式版本,变化实在太快,可能你今天了解的 ...

  9. Spring-Boot - 初步搭建

    official document:http://projects.spring.io/spring-boot/ 项目代码: https://github.com/chenxing12/springb ...

随机推荐

  1. iOS面试题 02

    在面试的时候,面试官问我,“你对内存管理了解的多吗?” 我忘了当时是怎么回答的了,但是,肯定是一时没想起来怎么回答. 1.谁创建谁释放 2.autoreleasepool 3.retain,copy, ...

  2. Interview Question

    HDS(11.16.2015): How to design an non-stop website like Google or Amazon? What design patterns are y ...

  3. Java Main Differences between HashMap and HashTable

    转自这篇帖子:http://www.importnew.com/7010.html HashMap和Hashtable的比较是Java面试中的常见问题,用来考验程序员是否能够正确使用集合类以及是否可以 ...

  4. MFC和GDI+一起使用

    VS2010,新建MFC项目,在头文件stdafx.h中添加: #include <gdiplus.h> using namespace Gdiplus; #pragma comment ...

  5. javascript设计模式学习之五——策略模式

    一.策略模式定义: 定义一些列的算法/规则,将它们封装起来,使得它们可以互相替换/组合使用.其目的在于将算法/规则封装起来,将算法/规则的使用与实现分离出来. 通过策略模式,可以减少算法计算过程中大量 ...

  6. javascript实例学习之一——联动下拉框

    经常碰到这样的需求,如省市_城市_乡镇下拉框.后一个下拉框的内容会根据前一个的改变而改变,之前的解决方法往往是在前一个改变的时候,向后台发送请求临时获取对应的内容.这样每触发一次就会网络请求一次,这种 ...

  7. [转] [环境搭建] VS-Visual Studio-IIS Express 支持局域网访问

    ------------------------------------------- 更正, 我发现Program一项只设置为iisexpress.exe是不可行的. 只能设置为Any才行(当然这是 ...

  8. 使用awk统计字段重复实践

    awk awk是一种规格化文件的分析工具, 主要处理对象类似数据库导出的条目文本文件, 其中一行,就对应一个记录,每个记录包含若干个字段. 类似这种文本: [root@www ~]# last -n ...

  9. 第8章 委托、Lamdba表达式和事件

    本章内容: 委托    Lambda表达式 事件 8.1.3   简单的委托示例 首先定义一个类MathOperations,它有两个静态方法,对double类型的值执行两个操作. public cl ...

  10. Spring shiro使用

    maven依赖: <dependency> <groupId>commons-collections</groupId> <artifactId>com ...