我有一个msbuild脚本,它只包含PropertyGroup:DefaultVariables.msbuild
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- default values if nothing is set in Main.proj -->
<PropertyGroup>
<ProjectName Condition="'$(PublishService)'==''">DefaultService</ProjectName>
</PropertyGroup>
</Project>
PublishService可以根据环境进行更改。 我还有一个Variables.msbuild与上面的脚本相同,除了服务名称:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- default values if nothing is set in Main.proj -->
<PropertyGroup>
<ProjectName Condition="'$(PublishService)'==''">ErpService</ProjectName>
</PropertyGroup>
</Project
我的主构建脚本:BuildMsi.msbuild导入DefaultVariables.msbuild,并有一个目标CreateEnvironmentSpecificInstaller,它调用Msi.msbuild
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CreateInstaller">
<PropertyGroup>
<BaseDir Condition="$(BaseDir)==''">$(MSBuildProjectDirectory)</BaseDir>
</PropertyGroup>
<Import Project="DefaultVariables.msbuild" />
<!-- Something else -->
<Target Name="CreateEnvironmentSpecificInstaller" DependsOnTargets="$(SpecificBuildSteps)">
<MSBuild Projects="$(RedistDir)\Framework\Msi.msbuild" Targets="CreateBatchScripts" StopOnFirstFailure="true" Properties="Configuration=$(Configuration)" RebaseOutputs="true" />
</Target>
<Target Name="CreateInstaller" DependsOnTargets="PrintVersion;$(GenericBuildSteps)">
<MSBuild Condition=" '$(EnvironmentName)' == '**AllEnvironments**' " Projects="$(BaseDir)\$(BtsDeploymentFrameworkDir)\BuildMsi.msbuild" Targets="CreateEnvironmentSpecificInstaller" StopOnFirstFailure="true"
Properties="Configuration=$(Configuration);" RebaseOutputs="true" />
<CallTarget Targets="RemoveGeneratedEnvironmentSettings" />
</Target>
</Project>
在Msi.msbuild脚本中,我添加了一个Import to Variables.msbuild脚本,但是之后的PublishService仍然是DefaultService:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CreateInstaller">
<Import Project="Variables.msbuild" />
<Target Name="CreateBatchScripts">
<Message Text="PublishService = $(PublishService)" />
</Target>
</Project>
如何在运行时覆盖此属性值?
答案 0 :(得分:1)
首先,你永远不会给PublishService
一个价值。我假设你在DefaultVariables.msbuild中想要做的是
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- default values if nothing is set in Main.proj -->
<PropertyGroup>
<PublishService> Condition="'$(PublishService)'==''">DefaultService</PublishService>
</PropertyGroup>
</Project>
然后,我建议您在Variables.msbuild中重命名该属性并删除条件Condition="'$(PublishService)'==''
。由于您已在DefaultVariables.msbuild中为该属性指定了默认值,因此将不会满足该条件,因此不会更改该值。
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishService>ErpService</PublishService>
</PropertyGroup>
</Project>