解决方案预设的项目文件的自定义属性

时间:2017-04-04 14:49:19

标签: visual-studio msbuild csproj visual-studio-project

我的项目中有一个自定义属性,用不同的资源(图片)构建相同的应用程序。

project.jsproj

<ItemGroup>
    <Content Condition="$(Customization) == ''" Include="images\uwp\*.png" />
    <Content Condition="$(Customization) != ''" Include="images\$(Customization)\uwp\*.png" />
</ItemGroup>

这可以通过msbuild正常工作:

msbuild project.jsproj /property:Configuration=Release;Platform=x64;Customization=theme_xy

我的问题是,是否有可能在VisualStudio 上的解决方案中预设此自定义属性,该属性也将应用于那里的构建。

例如:

a) Solution1.sln 使用自定义属性清空

嵌入project.jsproj

b) Solution2.sln 使用Customization属性嵌入project.jsproj =&#34; theme_xy &#34;

感谢任何帮助 - 谢谢

2 个答案:

答案 0 :(得分:1)

  

如果有可能在VisualStudio上的解决方案上预设此自定义属性,该解决方案也将应用于构建。

答案是肯定的,但条件限制是您无法在Solution1.sln和Solution2.sln中使用相同的project.jsproj文件。您可以在Solution1.sln中的project.jsproj文件中设置PropertyGroup:

    <PropertyGroup>
        <Customization></Customization>
    </PropertyGroup>
    <ItemGroup>
       <Content Condition="$(Customization) == ''" Include="images\uwp\*.png" />
       <Content Condition="$(Customization) != ''" Include="images\$(Customization)\uwp\*.png" />
    </ItemGroup>

这相当于更改solution1.sln中的project.jsproj文件:

  <ItemGroup>
    <Content Include="images\uwp\*.png" />
  </ItemGroup>

Solution2.sln 中,您需要更改project.jsproj文件

  <PropertyGroup>
    <Customization>theme_xy</Customization>
  </PropertyGroup>

但是如果你想在solution1.sln和solution2.sln中使用相同的project.jsproj而没有任何其他额外的更改,你仍然需要为PropertyGroup设置Condition并且这个Condition需要从VS外部传输,就像命令一样线。在这种情况下,您无法在不同的解决方案中使用条件自定义属性嵌入相同的project.jsproj。

<PropertyGroup Condition="$(Customization) == ''">
    <Customization></Customization>
  </PropertyGroup>

答案 1 :(得分:0)

通过区分解决方案名称解决了这个问题:

<PropertyGroup>
    <Customization></Customization>
</PropertyGroup>

<PropertyGroup Condition="'$(SolutionName)' == 'Solution1'">
    <Customization>theme_xy</Customization>
</PropertyGroup>