.NET 6 System.Drawing.Common 运行时开关

互联网 行业动态 更新时间:2024-06-13 00:19:06

Dpc*_*Dpc 12

以下对我有用。

将以下行添加到 PropertyGroup 部分的 .csproj 文件中:

<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

接下来在与项目文件相同的目录中创建一个名为 runtimeconfig.template.json 的文件,其中包含:

{
      "configProperties": {
         "System.Drawing.EnableUnixSupport": true
      }
}

我使用了 dotnet publish 命令,它在我提供给 dotnet publish 命令的输出目录中创建了一个 [YourAppNameHere].runtimeconfig.json 文件。

对于我的 asp.net 项目,发布导致以下 [YourAppNameHere].runtimeconfig.json 文件:

{
  "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
    }
  }
}

这有效,但尝试遵循问题中链接到的页面上的文档却没有。我认为这是因为我在 runtimeconfig.template.json 文件中添加了“runtimeOptions”部分,但 dotnet publish 命令还添加了一个名为“runtimeOptions”的部分,这似乎阻止了运行时看到“System. Drawing.EnableUnixSupport”选项。

出于这个原因,我在 runtimeconfig.template.json 文件中排除了“runTimeOptions”部分,因为发布导致以下文件不起作用:

{
  "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
    }
  }
}

请注意嵌套的“runtimeOptions”,我认为在尝试遵循问题链接中的文档时会导致它失败。

这很糟糕,自 DNX 时代以来我一直在使用 .net 核心,每次有新的更新时,他们都会做出一些糟糕的破坏性更改,需要对 csproj 和其他东西进行糟糕的添加才能使工作再次正常工作,这绝对令人沮丧。而这个也是绝对没有必要的。 (2认同)

更多推荐

System,NET,Common,Drawing

本文发布于:2023-04-20 20:38:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/hyzx/e564f89ee1194b8f2b67ece3ece262a7.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:System   NET   Common   Drawing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!