Just as the title states, I need to be able to programatically validate the version of a dacpac prior to publishing it to a database. Is there a way to do this?
You can do this with AssemblyInfo:
Properties\AssemblyInfo.cs
. Make sure it's included in the project and contains at least this code:using System.Reflection;
[assembly: AssemblyVersion("1.0.*")] // Define however you want your version to be
*.sqlproj
file in an outside editor (notepad etc) and add the following XML: <Target Name="SetDacVersionToAssemblyVersion" AfterTargets="CoreCompile">
<GetAssemblyIdentity AssemblyFiles="$(IntermediateTargetFullFileName)">
<Output TaskParameter="Assemblies" PropertyName="IntermediateTargetAssembly" />
</GetAssemblyIdentity>
<PropertyGroup>
<DacVersion>$(IntermediateTargetAssembly.Split(',')[1].Split('=')[1])
</DacVersion>
</PropertyGroup>
<Message Text="DacVersion set to $(DacVersion)" Importance="high" />
</Target>
Get-ChildItem -Filter *.dacpac -Recurse | Select-Object Name,@{n='FileVersion';e={$_.VersionInfo.FileVersion}},@{n='AssemblyVersion';e={[Reflection.AssemblyName]::GetAssemblyName($_.FullName).Version}}