The following worked for me.
Adding the following line to the .csproj file in a PropertyGroup
section:
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Next create a file named runtimeconfig.template.json in the same directory as your project file containing:
{
"configProperties": {
"System.Drawing.EnableUnixSupport": true
}
}
I used the dotnet publish
command, which created a [YourAppNameHere].runtimeconfig.json file in the output directory I supplied to the dotnet publish
command.
For my asp.net project, the publish resulted in the following [YourAppNameHere].runtimeconfig.jsonfile:
{
"runtimeOptions": {
"tfm": "net6.0",
"includedFrameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.1"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "6.0.1"
}
],
"configProperties": {
"System.Drawing.EnableUnixSupport": true,
"System.GC.Server": true,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}
This worked, where trying to follow the documentation on the page linked to in the question did not. I think this is because I was adding the runtimeOptions
section in the runtimeconfig.template.json file, but the dotnet publish
command was also adding a section named runtimeOptions
, which seems to have prevented the runtime from seeing the System.Drawing.EnableUnixSupport
option.
For this reason, I excluded the runTimeOptions
section in my runtimeconfig.template.json file as the publish resulted in the following file that did not work:
{
"runtimeOptions": {
"tfm": "net6.0",
"includedFrameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.1"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "6.0.1"
}
],
"runtimeOptions": {
"configProperties": {
"System.Drawing.EnableUnixSupport": true
}
},
"configProperties": {
"System.GC.Server": true,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}
Note the nested runtimeOptions
, which I believe was causing it to fail when trying to follow the documentation in the link from the question.