We use PowerShell scripts to deploy SQL database. This scripts are using SqlPackage.exe utility to publish our main database, it was working fine until we upgraded SSDT to it's latest release SSDT 2015 when it stated to throw the error below.
PowerShell Script Line:
& "C:\Program Files (x86)\Microsoft SQL Server\120\DAC\bin\SqlPackage.exe" /Action:Publish /SourceFile:"$DatabaseDacpacLocation" /TargetServerName:$DataServerSqlInstance /TargetDatabaseName:$Database /Variables:master="$MasterDatabase" /v:DatabaseName="$pDatabaseName" /p:ExcludeObjectType=Sequences
Error:
Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.SqlServer.Dac.DacPackage' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.SqlServer.Dac.DacServices' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SqlSchemaModelStaticState' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SqlServer.TransactSql.ScriptDom, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
It looks like your deployment environment is missing SqlDom version 12 (Microsoft.SqlServer.TransactSql.ScriptDom.dll), which is expected to be in the GAC. You can download it from the SQL Server 2014 Feature Pack page here: https://www.microsoft.com/en-us/download/details.aspx?id=42295
There are two files you should download and install - the x64 and x86 versions of SqlDom.msi.
It appears that you're currently using the SQL Server 2014 version of the data-tier application framework. Note that if you update to the SQL Server 2016 version of the data-tier application framework (DacFX), you'll need to ensure that the newer version (v13) of DacFX's dependencies (SqlSysClrTypes.msi and SqlDom.msi) are also installed.