2013-06-17 1 views
0

에서와 같이 중첩 된 속성을 사용하는 방법을 내 MSBuild 구성 파일은 MSBuild는 : 개미

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <PropertyGroup> 
     <USERNAME1_DropboxPublic>e:\path\to\Dropbox\for\first\user</USERNAME1_DropboxPublic> 
     <USERNAME2_DropboxPublic>e:\path\to\Dropbox\for\second\user</USERNAME2_DropboxPublic> 
     <USERNAME3_DropboxPublic>e:\path\to\Dropbox\for\third\user</USERNAME3_DropboxPublic> 
    </PropertyGroup> 
    .... 
</Project> 

에서 속성의 배치를하고 난 속성을 얻으려면 현재 사용자 이름에 따라 달라집니다.

또한 나는 ant 내가 MSBuild 도구를 사용하여이 문제를 해결할 수있는 방법이 ${${user.name}_DropboxPublic}

같은 nested properties를 사용하여이 문제를 해결할 수 있음을 알아?

답변

1

"트릭"중 일부는 다음과 같습니다.

을 저장 .BAT 파일로 저장이

<?xml version="1.0" encoding="utf-8"?> 
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapper"> 
    <!-- --> 

    <PropertyGroup> 
     <MyFavoriteFoodComplement Condition="'$(FavoriteFood)'=='PeanutButter'">Jelly</MyFavoriteFoodComplement> 
     <MyFavoriteFoodComplement Condition="'$(FavoriteFood)'=='Steak'">Potatoes</MyFavoriteFoodComplement> 

     <!-- Check to see if a match was given (by seeing if the variable value is an empty string), if no match (aka, an empty string), do a default --> 
     <MyFavoriteFoodComplement Condition="'$(MyFavoriteFoodComplement)'==''">CookiesTheDefaultFavoriteFoodComplement</MyFavoriteFoodComplement> 
    </PropertyGroup> 


    <Choose> 
     <When Condition=" '$(Configuration)'=='Debug' "> 
      <PropertyGroup> 
       <MyChooseVariable001>DebugSuffix001</MyChooseVariable001> 
       <MyChooseVariable002>DebugSuffix002</MyChooseVariable002> 
       <MyChooseVariable003>DebugSuffix003</MyChooseVariable003> 
      </PropertyGroup> 
     </When> 
     <When Condition=" '$(Configuration)'=='Release' "> 
      <PropertyGroup> 
       <MyChooseVariable001>ReleaseSuffix001</MyChooseVariable001> 
       <MyChooseVariable002>ReleaseSuffix002</MyChooseVariable002> 
       <MyChooseVariable003>ReleaseSuffix003</MyChooseVariable003>    
      </PropertyGroup> 
     </When> 

     <Otherwise> 
      <PropertyGroup> 
       <MyChooseVariable001>DefaultValue001</MyChooseVariable001> 
       <MyChooseVariable002>DefaultValue002</MyChooseVariable002> 
       <MyChooseVariable003>DefaultValue003</MyChooseVariable003>      
      </PropertyGroup> 
     </Otherwise>   


    </Choose> 

    <!-- --> 

    <Target Name="TestCreateProperty"> 

     <CreateProperty Value="Here is a created property using another property : $(MyFavoriteFoodComplement)"> 
      <Output TaskParameter="Value" PropertyName="MyCreateProperty" /> 
     </CreateProperty> 

     <Message Text=" MyCreateProperty = $(MyCreateProperty)" /> 

     <Message Text=" " /> 

     <CreateProperty Condition="'$(FavoriteFood)'=='PeanutButterX'" Value="Conditional Create Property : $(MyFavoriteFoodComplement)"> 
      <Output TaskParameter="Value" PropertyName="MyCreatePropertyWithCondition" /> 
     </CreateProperty> 

     <CreateProperty Condition="'$(MyCreatePropertyWithCondition)'==''" Value="Conditional Create Property : DEFAULT"> 
      <Output TaskParameter="Value" PropertyName="MyCreatePropertyWithCondition" /> 
     </CreateProperty>  

     <Message Text=" MyCreatePropertyWithCondition = $(MyCreatePropertyWithCondition)" /> 






    </Target> 

    <!-- --> 


    <Target Name="ShowVariables"> 

     <Message Text="Configuration = $(Configuration)" /> 
     <Message Text="FavoriteFood = $(FavoriteFood)" /> 

     <Message Text=" " /> 

     <Message Text="MyFavoriteFoodComplement = $(MyFavoriteFoodComplement)" /> 

     <Message Text="MyChooseVariable001 = $(MyChooseVariable001)" /> 
     <Message Text="MyChooseVariable002 = $(MyChooseVariable002)" /> 
     <Message Text="MyChooseVariable003 = $(MyChooseVariable003)" /> 

    </Target> 
    <!-- --> 
    <!-- --> 
    <!-- --> 
    <Target Name="AllTargetsWrapper"> 
     <!-- --> 
     <CallTarget Targets="ShowVariables" /> 
     <!-- --> 
     <CallTarget Targets="TestCreateProperty" /> 
     <!-- -->  
    </Target> 
    <!-- --> 
</Project> 

"MSBuild_Conditionals.xml"라는 파일에 아래의 XML.

set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v3.5 
call %msBuildDir%\msbuild.exe MSBuild_Conditionals.xml /p:Configuration=Release;FavoriteFood=PeanutButter /l:FileLogger,Microsoft.Build.Engine;logfile=MSBuild_Conditionals_LOG.log 
set msBuildDir= 

출력

Build started 6/01/2013 11:33:33 PM. 
__________________________________________________ 
Project ".\MSBuild_Conditionals.xml" (default targets): 

Target AllTargetsWrapper: 
    Target ShowVariables: 
     Configuration = Release 
     FavoriteFood = PeanutButter 

     MyFavoriteFoodComplement = Jelly 
     MyChooseVariable001 = ReleaseSuffix001 
     MyChooseVariable002 = ReleaseSuffix002 
     MyChooseVariable003 = ReleaseSuffix003 
    Target TestCreateProperty: 
     MyCreateProperty = Here is a created property using another property : Jelly 

     MyCreatePropertyWithCondition = Conditional Create Property : DEFAULT 

Build succeeded. 
    0 Warning(s) 
    0 Error(s) 

Time Elapsed 00:00:00.01 
(위 .bat 파일의 매개 변수)