0

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に使用することでこの問題を解決できることも知っていますnested properties${${user.name}_DropboxPublic}

ツールを使用してこの問題を解決するにはどうすればよいMSBuildですか?

4

1 に答える 1

1

ここにいくつかの「トリック」があります。

以下の xml を「MSBuild_Conditionals.xml」という名前のファイルに保存します。

<?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>

これを .bat ファイルに保存します。

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=

出力 (上記の .bat ファイルのパラメーターを使用)

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
于 2013-06-17T14:41:52.367 に答える