Precompiler notion for project type (target) in VC#

Viewed 43

Just the same as if a project in DEBUG / RELEASE mode We use

#ifdef DEBUG
...

Is there something the same for TARGET? (exe / lib / winexe) ?

1 Answers

There isn't anything built in, but in your build you can define anything you like; this could be done manually per-project, or you can do it more dynamically; here's an example that conditionally appends a PLAT_NO_EMITDLL symbol if the target framework is (either of a few), so that the code can #if PLAT_NO_EMITDLL rather than having all the "which framework has what platform features" logic in the C# files:

  <PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
    <DefineConstants>$(DefineConstants);PLAT_NO_EMITDLL</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
    <DefineConstants>$(DefineConstants);PLAT_NO_EMITDLL</DefineConstants>
  </PropertyGroup>

In your case, you might want to look at $(OutputType).

Related