Skip to content

Instantly share code, notes, and snippets.

@naramdash
Last active April 25, 2022 10:15
Show Gist options
  • Save naramdash/3f0fb936492d4062648e020ee9d07369 to your computer and use it in GitHub Desktop.
Save naramdash/3f0fb936492d4062648e020ee9d07369 to your computer and use it in GitHub Desktop.
C# Preprocessor with Operating System
#if Windows
Console.WriteLine("Windows!");
#elif Linux
Console.WriteLine("Linuxw!");
#elif OSX
Console.WriteLine("osx!");
#endif
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>notepad_asp</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">Windows</DefineConstants>
<DefineConstants Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">OSX</DefineConstants>
<DefineConstants Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">Linux</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.1" />
</ItemGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment