如何在 "headless" 构建服务器上构建 SSDT 项目?

How to build SSDT project on a "headless" build server?

我有 Windows Server 2012 R2,我想用它在 CI 管道中从 SSDT 构建 .sqlproj 项目。这是我到目前为止所做的:

当我使用

构建解决方案时

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe database.solution.sln /p:tv=14 /p:SSDTPath=D:\Nuget\Microsoft.Data.Tools.Msbuild\lib\net40 /p:SQLDBExtensionsRefPath=D:\Nuget\Microsoft.Data.Tools.Msbuild\lib\net40 /p:Configuration=Debug

我收到一条错误消息 Could not load file or assembly 'Microsoft.Build.Utilities.Core

有什么我错过的想法吗?目标是让构建服务器尽可能轻便,因此不想在其上安装 Visual Studio 或 SSDT。

这是 MsBuild 的完整输出:

Microsoft (R) Build Engine version 4.6.1586.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 18/01/2017 17:00:19.
Project "D:\Jenkins\workspace\hcg\database.solution\database.solution.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|Any CPU".
Project "D:\Jenkins\workspace\hcg\database.solution\database.solution.sln" (1) is building "D:\Jenkins\workspace\hcg\database.solution\database.solution\database.solution.sqlproj" (2) on node 1 (default targets).
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(983,5): warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [D:\Jenkins\workspace\hcg\database.solution\database.solution\database.solution.sqlproj]
GenerateSqlTargetFrameworkMoniker:
Skipping target "GenerateSqlTargetFrameworkMoniker" because all output files are up-to-date with respect to the input files.
CoreCompile:
  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:x64 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+ /reference:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll /debug+ /debug:full /optimize- /out:obj\Debug\database.solution.dll /subsystemversion:6.00 /target:library /warnaserror- /utf8output "C:\Users\svc_jenkins\AppData\Local\Temp\.NETFramework,Version=v4.5.2.SqlClrAttributes.cs"
D:\Nuget\Microsoft.Data.Tools.Msbuild\lib\net40\Microsoft.Data.Tools.Schema.SqlTasks.targets(477,5): error MSB4062: The "SqlModelResolutionTask" task could not be loaded from the assembly D:\Nuget\Microsoft.Data.Tools.Msbuild\lib\net40\Microsoft.Data.Tools.Schema.Tasks.Sql.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [D:\Jenkins\workspace\hcg\database.solution\database.solution\database.solution.sqlproj]
Done Building Project "D:\Jenkins\workspace\hcg\database.solution\database.solution\database.solution.sqlproj" (default targets) -- FAILED.
Done Building Project "D:\Jenkins\workspace\hcg\database.solution\database.solution.sln" (default targets) -- FAILED.

Build FAILED.

"D:\Jenkins\workspace\hcg\database.solution\database.solution.sln" (default target) (1) ->
"D:\Jenkins\workspace\hcg\database.solution\database.solution\database.solution.sqlproj" (default target) (2) ->
(GetReferenceAssemblyPaths target) -> 
  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(983,5): warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [D:\Jenkins\workspace\hcg\database.solution\database.solution\database.solution.sqlproj]


"D:\Jenkins\workspace\hcg\database.solution\database.solution.sln" (default target) (1) ->
"D:\Jenkins\workspace\hcg\database.solution\database.solution\database.solution.sqlproj" (default target) (2) ->
(_SetupSqlBuildInputs target) -> 
  D:\Nuget\Microsoft.Data.Tools.Msbuild\lib\net40\Microsoft.Data.Tools.Schema.SqlTasks.targets(477,5): error MSB4062: The "SqlModelResolutionTask" task could not be loaded from the assembly D:\Nuget\Microsoft.Data.Tools.Msbuild\lib\net40\Microsoft.Data.Tools.Schema.Tasks.Sql.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [D:\Jenkins\workspace\hcg\database.solution\database.solution\database.solution.sqlproj]

    1 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.51

SSDT NuGet 包需要 MSBuild 版本 14.0 Update 3 或更新版本(即 15.0 RC)。可在此处获取:https://www.microsoft.com/en-us/download/details.aspx?id=48159

您还需要设置一些环境变量来引用 NuGet 包位置,如下所示: setx SQLDBExtensionsRefPath C:\agent\Microsoft.Data.Tools.Msbuild\lib\net40 /M setx SSDTPath C:\agent\Microsoft.Data.Tools.Msbuild\lib\net40 /M

参考资料link: https://blogs.msdn.microsoft.com/ssdt/2016/08/22/releasing-ssdt-with-visual-studio-15-preview-4-and-introducing-ssdt-msbuild-nuget-package/