正如标题所述,我需要能够以编程方式验证dacpac的版本,然后再将其发布到数据库中。有办法吗?
答案 0 :(得分:1)
您可以使用AssemblyInfo进行此操作:
Properties\AssemblyInfo.cs
。确保它包含在项目中并且至少包含以下代码:using System.Reflection;
[assembly: AssemblyVersion("1.0.*")] // Define however you want your version to be
*.sqlproj
文件,并添加以下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}}