'How can I enable Server GC in .NET Core?

I have a .NET Core app (MyApp.exe) developed in VS2017 running on the 1.0.4 version of the SDK. I have tried adding an App.config with the following entries:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <gcServer enabled="true"/>
  </runtime>
</configuration>

Which on build is renamed to: MyApp.config.

But this does not change the GC mode; Any ideas?



Solution 1:[1]

Based on this source, you do that via the csproj:

<PropertyGroup>
  <ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>

Solution 2:[2]

There are few ways and they vary depends on the dotnet version.

enter image description here

runtimeconfig.json file:

{
   "runtimeOptions": {
      "configProperties": {
         "System.GC.Server": true
      }
   }
}

Project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <ServerGarbageCollection>true</ServerGarbageCollection>
  </PropertyGroup>

</Project>

More details you can find here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marc Gravell
Solution 2 Krzysztof Madej