命名配置属性函数

时间:2014-12-03 17:46:30

标签: msbuild

我有一个项目有一组项目上下文(为简洁省略了完整的属性组):

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'v82_Release|x64' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'v90_Release|x64' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'v90_Debug|x64' ">

引用的程序集因配置开头的版本号而异 变量,所以我打开了VS生成的csproj文件并编辑了引用(为了简洁省略了父Reference项):

<HintPath>Lib\$(Configuration.Substring(0,3))\Assembly1.dll</HintPath>
<HintPath>Lib\$(Configuration.Substring(0,3))\Assembly2.dll</HintPath>
<HintPath>Lib\$(Configuration.Substring(0,3))\Assembly3.dll</HintPath>

这有效,但有没有办法有效地定义$(LibVersionNum) = $(Configuration.Substring(0,3)),从而清理我的语法?

1 个答案:

答案 0 :(得分:1)

试试这个:

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

    <PropertyGroup>
        <Configuration>v82_Release</Configuration>
        <Platform>x64</Platform>
    </PropertyGroup>

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'v82_Release|x64' ">

    </PropertyGroup>

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'v90_Release|x64' ">

    </PropertyGroup>

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'v90_Debug|x64' ">

    </PropertyGroup>

    <PropertyGroup>
        <LibVersionNum>$(Configuration.Substring(0,3))</LibVersionNum>
    </PropertyGroup>

    <ItemGroup>
        <MyItem Include="Ref1">
            <HintPath>Lib\$(LibVersionNum)\Assembly1.dll</HintPath>
        </MyItem>
        <MyItem Include="Ref2">
            <HintPath>Lib\$(LibVersionNum)\Assembly2.dll</HintPath>
        </MyItem>
        <MyItem Include="Ref3">
            <HintPath>Lib\$(LibVersionNum)\Assembly3.dll</HintPath>
        </MyItem>
    </ItemGroup>

    <Target Name="Build">
        <Message Text="Current Config: $(Configuration)"/>
        <Message Text="%(MyItem.Identity): %(MyItem.HintPath)"/>
    </Target>
</Project>