工程文件csproj使用编译条件指定属性

csproj工程文件中有很多xml格式的属性,比如PropertyGroup、ItemGroup,某些属性操作默认是全部的或者是当前编译条件的而已,当我们想指定某些属性只在某个编译条件下发生时就可以通过以下xml属性来指定:

Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" 或者 Condition=" '$(Configuration)' == 'Debug' "

例如,Release和Debug都附带有xml注释文档,则这样解决:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DocumentationFile>bin\Release\netstandard2.0\XXXX.xml</DocumentationFile>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DocumentationFile>bin\Debug\netstandard2.0\XXXX.xml</DocumentationFile>
  </PropertyGroup>

再例如,你Debug运行需要包含项目文件,即“复制到输出目录”为“如果较新则复制”/“始终复制”,但是Release或发布到生产环境时又不希望包含进去(不包含狗血、乌龙的迭代事件就少了),可以这样做:

<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <None Update="Assets\Xxxx.key">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
</ItemGroup>

 

posted @ 2019-03-28 09:00  朝野布告  阅读(1440)  评论(2编辑  收藏  举报