I would like to minimize repetition in my msbuild xml, particularly inside my Target's Exec Command attribute.

1) Most importantly, in the following Target I would like to un-duplicate the pair of "%(ShaderVertex.Identity)" constructs in the Exec Command attribute (for example, the Property VertexTargetName is defined to be "ShaderVertex", but %($(VertexTargetName).Identity) will not expand $(VertexTargetName)):

<Target Name="ShaderVertexBuild"
    Inputs="@($(VertexTargetName))"
    Outputs="@($(VertexTargetName)$(OutputRelPathAndFileName))">

    <Exec Command="$(FxcPathFull)v$(ShaderArgNoFirstLetter) %(ShaderVertex.Identity)$(ShaderOutputFlagAndRelPath)%(ShaderVertex.Identity)$(OutputFileExtLetterToAppend)">
    </Exec>
</Target>

2) It would also be nice not to duplicate the "ShaderVertex" identifier in the ItemGroup that precedes my Target, but again I can't expand a $(VertexTargetName) in the context of an ItemGroup.

<ItemGroup>
    <ShaderPixel  Include="p*.fx"/>
    <ShaderVertex Include="v*.fx"/>
</ItemGroup>

3) Less importantly, it would be nice to be able to further reduce duplicate constructs between my Target's. Using the above example, I'd like to simply pass $(VertexTargetName) and the letter "v" (which tells the HLSL compiler to compile a vertex shader) to a magical Target generator that fills in all the data identical to all Targets -- or even better, just pass $(VertexTargetName) and allow the Target generator to infer from this argument that a "v" needs to be passed (instead of, say, a "p" for PixelShader, which could be inferred from $(PixelTargetName)).

Any ideas?

Caveats: I know that msbuild is not a functional programming language, and therefore may not be able to accommodate my desires here. I also know that VS2012 handles HLSL compilation automatically, but I'm on VS2010 for now, and would like to know enough about msbuild to accomplish this sort of task.

Here is the complete xml listing:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <!-- TODO NTF: does not take into account *.inc dependency -->
    <Target Name="Main">
        <CallTarget Targets="ShaderPixelBuild"/>
        <CallTarget Targets="ShaderVertexBuild"/>
    </Target>


    <ItemGroup>
        <ShaderPixel  Include="p*.fx"/>
        <ShaderVertex Include="v*.fx"/>
    </ItemGroup>

    <PropertyGroup>
        <ShaderModelNum>4</ShaderModelNum><!-- Radeon 8600 GTS doesn't support shader model 5 -->
        <ShaderArgNoFirstLetter>s_$(ShaderModelNum)_0</ShaderArgNoFirstLetter><!-- first letter defines shader type; v=vertex, p=pixel-->
        <FxcPathFull>&quot;%DXSDK_DIR%\Utilities\bin\x64\fxc.exe&quot; /T </FxcPathFull>
        <ShaderOutputRelPath>..\..\x64\shadersCompiled\</ShaderOutputRelPath>
        <ShaderOutputFlagAndRelPath> /Fo $(ShaderOutputRelPath)</ShaderOutputFlagAndRelPath>
        <OutputFileExtLetterToAppend>o</OutputFileExtLetterToAppend>
        <OutputRelPathAndFileName>->'$(ShaderOutputRelPath)%(identity)$(OutputFileExtLetterToAppend)'</OutputRelPathAndFileName>

        <!-- Note that the content of each of these properties must be duplicated in the Exec Command twice, since %($(PropertyName)) will not expand there -->
        <PixelTargetName>ShaderPixel</PixelTargetName>
        <VertexTargetName>ShaderVertex</VertexTargetName>        
    </PropertyGroup>    


    <Target Name="ShaderPixelBuild"
        Inputs="@($(PixelTargetName))"
        Outputs="@($(PixelTargetName)$(OutputRelPathAndFileName))">

        <Exec Command="$(FxcPathFull)p$(ShaderArgNoFirstLetter) %(ShaderPixel.Identity)$(ShaderOutputFlagAndRelPath)%(ShaderPixel.Identity)$(OutputFileExtLetterToAppend)">
        </Exec>
    </Target>

    <Target Name="ShaderVertexBuild"
        Inputs="@($(VertexTargetName))"
        Outputs="@($(VertexTargetName)$(OutputRelPathAndFileName))">

        <Exec Command="$(FxcPathFull)v$(ShaderArgNoFirstLetter) %(ShaderVertex.Identity)$(ShaderOutputFlagAndRelPath)%(ShaderVertex.Identity)$(OutputFileExtLetterToAppend)">
        </Exec>
    </Target>

</Project>
0

There are 0 answers