如何在.net核心项目中将GCServer设置为true?通常,在.net Framework项目中,我会添加一个App.Config xml文件,该文件将GCServer变量设置为true,但在 在Linux上运行的.net核心项目(App.Config文件已生成并发布,但该变量仍然没有更改)
答案 0 :(得分:0)
将<ServerGarbageCollection>True</ServerGarbageCollection>
添加到您的csproj文件中。喜欢:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
<ServerGarbageCollection>true</ServerGarbageCollection>
...
</PropertyGroup>
</Project>
要确认在构建期间已正确设置该文件,请检查<PROJECT>.runtimeconfig.json
目录中的bin
文件。它应包含以下内容:
"configProperties": {
"System.GC.Server": true
}
在某些情况下,GCServer已经是默认值。您可以使用msbuild /pp
来检查msbuild文件是否存在默认值:
$ dotnet msbuild /pp | grep -i ServerGarbage
<ServerGarbageCollection>true</ServerGarbageCollection>
<RuntimeHostConfigurationOption Include="System.GC.Server" Condition="'$(ServerGarbageCollection)' != ''" Value="$(ServerGarbageCollection)" />
如果您有一个带有Sdk="Microsoft.NET.Sdk.Web"
的csproj文件,则该文件已经是默认文件:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
</Project>
$ dotnet msbuild /pp | grep -i ServerGarbage
<ServerGarbageCollection>true</ServerGarbageCollection>
<RuntimeHostConfigurationOption Include="System.GC.Server" Condition="'$(ServerGarbageCollection)' != ''" Value="$(ServerGarbageCollection)" />