如何根据目标Azure Analysis Services环境定义不同的源数据库,但仍坚持VS 2017内部的部署过程?
但不想使用AMO部分进行部署。
我的想法是更改smproj文件->添加用于保存源数据库属性的变量,并根据目标分析服务对其进行调整。然后,我将使用自定义构建任务来处理* .asdatabase文件,并替换相应的字符串。在custom_build.target文件中:
<UsingTask TaskFactory="PowershellTaskFactory" TaskName="DeployDB" AssemblyFile="$(MSBuildExtensionsPath64)ExtensionPack\4.0\MSBuild.ExtensionPack.TaskFactory.PowerShell.dll">
<ParameterGroup>
<OutPath Required="True" ParameterType="System.String"/>
<DataSourceObj Required="True" ParameterType="System.String"/>
<DBName Required="True" ParameterType="System.String"/>
<ServerName Required="True" ParameterType="System.String"/>
</ParameterGroup>
<Task>
<![CDATA[
$OutPathFinal = ($OutPath + (get-ChildItem ($OutPath += "*.asdatabase") -name))
$file = Get-Content $OutPathFinal
$files = $file | ConvertFrom-Json
$files.model.dataSources | Where{$_.name -eq $DataSourceObj} | ForEach{$_.connectionDetails} | ForEach{$_.address} | ForEach{$_.server = $ServerName; $_.database = $DBName}
$files.model.dataSources | Where{$_.name -eq $DataSourceObj} | ForEach{$_.credential} | ForEach{$_.path = $ServerName + ';' + $DBName}
$log.LogMessage([Microsoft.Build.Framework.MessageImportance]"High", "Step 1")
$files | ConvertTo-Json -depth 100 | Out-File ($OutPathFinal)
$files | ConvertTo-Json -depth 100 | Out-File ($OutPathFinal + 'copy')
<# echo script to build output log to help debug as needed #>
$log.LogMessage([Microsoft.Build.Framework.MessageImportance]"High", "Step2")
]]>
</Task>
</UsingTask><Target Name="AfterBuild" Inputs="$(OutDir)$(DeploymentServerCubeName).asdatabase" Outputs="$(OutDir)$(DeploymentServerCubeName).asdatabasecopy" DependsOnTargets="CopyFilesToOutputDirectory">
<DeployDB OutPath="$(OutDir)" DataSourceObj="$(DataSourceName)" DBName="$(SourceServerDatabase)" ServerName="$(SourceServerName)"></DeployDB>
在Visual Studio 2017中执行“生成”步骤时,此方法有效,两个文件($(OutDir)$(DeploymentServerCubeName).asdatabase,$(OutDir)$(DeploymentServerCubeName).asdatabasecopy)包含正确的字符串。在执行“部署”步骤时,只有$(OutDir)$(DeploymentServerCubeName).asdatabasecopy文件包含正确的源数据库属性。我怀疑我选择的步骤不正确,但是使用
DependsOnTargets="CopyFilesToOutputDirectory"
导致
部分错误 $(OutDir)$(DeploymentServerCubeName).asdatabase
找不到。
我们非常感谢您的帮助!
预先感谢