Lex Webb
Lex Webb

Reputation: 2852

Using MSBuild to build SSDT projects with VS2017 fails

I am trying to set up continuous integration of .sqlproj SSDT projects on our windows server 2016 server.

In order to do this I have installed VS2017 and SSDT tools onto the server to get the required tools. I have also installed MS build tools 2017.

The issue I am currently having is regarding what looks to be miss-matched versions of installed ms build tools and ssdt.

The command i am using to run the build is as follows:

C:\\Windows\Microsoft.NET\\Framework64\\v4.0.30319\\MSBuild.exe /p:VisualStudioVersion=15.0 /property:MSBuildExtensionsPath="C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\" /property:VsInstallRoot="C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\" DPAP-SQL-Slim.sln

The two switches passed there are to set two environment parameters that the .sqlproj file is expecting to find when run through Visual studio. This is done because MSBuild does not supply them by default.

The error i am currently getting is as follows:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets(477,5): error MSB4062: The "SqlModelResolutionTask" task could not be loaded from the assembly C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\IDE\Extensions\Microsoft\SQLDB\Dac\140\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.

Now, i can see from running the command: gacutil /l in the VS2017 command prompt that the apparently installed version of the Microsoft.Build.Utilities.Core dll is v14: Microsoft.Build.Conversion.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL

Am i missing something key here? It appears that installing build tools 2017 did not in-fact update the GAC and register the correct DLLs.

Upvotes: 3

Views: 8572

Answers (2)

ccoutinho
ccoutinho

Reputation: 4534

I was having this issue building a SQL Server project on a CI/CD pipeline. None of the pre-built build tasks on Azure DevOps would work for me. I solved this by avoiding to add a SQL Server project to the solution.

I achieved this by using an MSBuild SDK, capable of producing a SQL Server Data-Tier Application package (.dacpac) from the set of SQL scripts. By adding this second project to the solution, I managed to continue taking advantage of linking the project to a live database through SQL Server Object Explorer on Visual Studio. I gave a more detailed explanation in this answer.

Upvotes: 2

Martin Ullrich
Martin Ullrich

Reputation: 100543

Do not use the msbuild.exe included in .NET Framework (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe). It is old and does not support some features of newer msbuild versions.

Always use the version of MSBuild installed with visual studio or the build tools. Depending on the version of VS installed, this could be

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe

Starting in VS 2017, MSBuild is also not installed system-wide but many versions (e.g. VS 2017 preview versions, different editions like Build Tools / Enterprise / Community etc.) can be installed side-by-side, which is why you won't find these MSBuild assemblies in the GAC.

Upvotes: 9

Related Questions