2017-02-10 3 views
1

과 속성 값을 덮어 쓰기 : 환경에 따라 변경 될 수 있습니다 은 MSBuild가 난 단지 PropertyGroup 포함 된 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

을 DefaultVariables.msbuild. 는 또한 서비스 이름을 제외하고, 위의 스크립트와 동일과 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 

내 주요 빌드 스크립트는 다음 DefaultVariables.msbuild를 가져 MSI는 호출 대상 CreateEnvironmentSpecificInstaller있다 BuildMsi.msbuild. 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 스크립트에서 나는 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> 

런타임시이 속성 값을 어떻게 덮어 쓸 수 있습니까?

답변

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>