【问题标题】:How to check for conditional compilation symbols in csproj如何在 csproj 中检查条件编译符号
【发布时间】:2020-04-09 13:54:24
【问题描述】:

出于安全原因,我需要从生成的exe 中排除一些代码和一些文件。我为此使用条件编译符号SECURE。 排除代码很简单

#if !SECURE
// Some secure code
#endif

但对于文件 - 不是那么多。只有在定义了SECURE 符号的情况下,我应该在下面的Condition 中写什么来排除这些文件?

  <ItemGroup Condition="???">
    <Compile Remove="SecureClass.cs" />
    <None Include="SecureClass.cs" />
  </ItemGroup>

【问题讨论】:

    标签: c# csproj conditional-compilation


    【解决方案1】:

    经过一番挖掘,我找到了this github issue

    所以答案是:

      <ItemGroup Condition="$(DefineConstants.Contains('SECURE'))">
        <Compile Remove="SecureClass.cs" />
        <None Include="SecureClass.cs" />
      </ItemGroup>
    

    也试过这种方法,但是没用

    <!--#if (SECURE)-->
      <ItemGroup>
        <Compile Remove="SecureClass.cs" />
        <None Include="SecureClass.cs" />
      </ItemGroup>
    <!--#endif-->
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      • 1970-01-01
      • 2012-01-06
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      • 2013-12-27
      相关资源
      最近更新 更多