There are preprocessor defines for Net Core, you can use this to set a constant when the project is running in ASP.NET Core
#if NETSTANDARD1_6
public const IsCore = true;
#elif NETSTANDARD1_5
public const IsCore = true;
#elif NETSTANDARD1_4
public const IsCore = true;
#elif NETSTANDARD1_3
public const IsCore = true;
#elif NETSTANDARD1_2
public const IsCore = true;
#elif NETSTANDARD1_1
public const IsCore = true;
#elif NETSTANDARD1_0
public const IsCore = true;
#else
public const IsCore = false;
#endif
Alternatively, if you (can) add the following to your .csproj, you can use a simpler form which won't need to be modified when new frameworks are released:
In .csproj:
<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netcoreapp\d'))">
<DefineConstants>NETCORE</DefineConstants>
</PropertyGroup>
And the following code somewhere to set up the constant:
#if NETCORE
public const IsCore = true;
#else
public const IsCore = false;
#endif
See How to set .NET Core in #if statement for compilation