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

Custom property on projectfile preset by solution

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

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 embedds project.jsproj with Customization 属性 empty

b) Solution2.sln 嵌入 project.jsproj 自定义 属性 = "theme_xy"

感谢任何帮助 - 谢谢

if there is a possibility to preset this custom property on a solution on VisualStudio that will be applied on a build there as well.

答案是肯定的,但是条件限制是你不能在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>

相当于把project.jsproj文件改成solution1.sln:

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

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

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

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