c# - 在 .net core 项目中的 Linux 上运行时设置 GCServer = True
问题描述
如何在 .net 核心项目中将 GCServer 设置为 true?通常在 .net 框架项目中,我添加一个 App.Config xml 文件,将 GCServer 变量设置为 true ,但这在 Linux 上运行的 .net 核心项目中不起作用(生成并发布 App.Config 文件,但变量仍然没有t改变)
解决方案
添加<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 文件是否有默认值msbuild /pp
:
$ dotnet msbuild /pp | grep -i ServerGarbage
<ServerGarbageCollection>true</ServerGarbageCollection>
<RuntimeHostConfigurationOption Include="System.GC.Server" Condition="'$(ServerGarbageCollection)' != ''" Value="$(ServerGarbageCollection)" />
如果你有一个带有 的 csproj 文件Sdk="Microsoft.NET.Sdk.Web"
,那么它已经是默认的:
<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)" />
推荐阅读
- excel - 每 n 列复制每 n 个单元格并粘贴到新行中,对于每一行
- c++ - 将 dynamic_cast 与 std::exception 一起使用
- pandas - 用 groupby 计算条件中位数
- sql - 如何获取汇总的月度数据并计算新字段?
- macos - 文件删除自身的Shell命令
- python-3.x - Paramiko:为什么阅读这么慢?
- python - 有没有更有效的方法可以根据条件参数数量在 Django 中编写此自定义 SQL?
- ant - 如何从蚂蚁脚本调用蚂蚁脚本
- php - 你能解释一下这个与内存耗尽有关的令人困惑的 PHP 致命错误吗?
- c - 为什么这个生成的汇编代码似乎包含废话?