Search code examples
sql-servermsbuildsql-server-data-tools

Comment Out Set Var Declarations True results in errors from MS Build


I am working to automate the scripting of an SSDT project so that it can be deployed later with alternative values for variables being passed in.

My publish profile looks like this.

<?xml version="1.0" encoding="utf-8"?>
  <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <IncludeCompositeObjects>True</IncludeCompositeObjects>
     <TargetConnectionString>Data Source=.;Integrated Security=True;Pooling=False</TargetConnectionString>
     <TargetDatabaseName>BLANK</TargetDatabaseName>
     <UpdateDatabase>False</UpdateDatabase>
     <ScriptDatabaseOptions>True</ScriptDatabaseOptions>
     <BlockOnPossibleDataLoss>True</BlockOnPossibleDataLoss>
     <CreateNewDatabase>True</CreateNewDatabase>
     <IgnoreObjectPlacementOnPartitionScheme>False</IgnoreObjectPlacementOnPartitionScheme>
     <ProfileVersionNumber>1</ProfileVersionNumber>
     <CommentOutSetVarDeclarations>True</CommentOutSetVarDeclarations>
   </PropertyGroup>
 </Project>

In my test script I am then calling the following from powershell

$Directory = 'C:\GitProjects\CI\DevPOC\Database\ETL POC\AdventureWorksDW\'
$Publish = 'AdventureWorksDW.publish.xml'

Set-Location $Directory
& $env:windir\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /t:Build
& $env:windir\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /t:Publish /p:SqlPublishProfilePath`="$Directory\$Publish"

I then get a number of errors which all relate to the variable values, examples below.

Deploy error SQL72014: SQL Execution error: A fatal error occurred. The variable DatabaseName could not be found.  [C:\GitProjects\CI\POC\Database\ETL POC\AdventureWorksDW\AdventureWorksDW.sqlproj]

If however I set CommentOutSetVarDeclarations to false the script is generated without error. When performing the same task through SSDT no errors are raised.

Has anyone experienced similar behaviour?


Solution

  • So after a bit of back and forth with Microsoft support I have a resolution for this problem. It seems that the parameter UpdateDatabase set in the publish profile is not picked up and used in this way. Not 100% sure if this was acknowledged as a bug or not but by using the following command instead it works OK.

    & $env:windir\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /t:Publish /p:SqlPublishProfilePath`="$Directory\$Publish" /p:UpdateDatabase=False