maxc137
maxc137

Reputation: 2741

How to check for conditional compilation symbols in csproj

For security reasons, I need to exclude some code and some files from resulting exe. I'm using conditional compilation symbol SECURE for that. Excluding code is simple

#if !SECURE
// Some secure code
#endif

But for files - not so much. What should I write in Condition below to exclude these files only if SECURE symbol is defined?

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

Upvotes: 3

Views: 1115

Answers (1)

maxc137
maxc137

Reputation: 2741

After some digging, I found this github issue.

So the answer is:

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

Also tried this approach, but it didn't work:

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

Upvotes: 6

Related Questions