【问题标题】:Unable to resolve System.Windows.Forms.dll in .Net Core 3.1无法在 .Net Core 3.1 中解析 System.Windows.Forms.dll
【发布时间】:2020-05-10 10:22:57
【问题描述】:

我有一个场景,我们在 .Net core 3.1 类库中使用旧版 .Net Framework dll。 .Net Framework dll 在内部使用 System.Windows.Forms.dll,.Net 核心无法解析。

我在运行时收到以下错误消息

无法加载文件或程序集“System.Windows.Forms,版本=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”。系统找不到指定的文件。

在理想情况下,将 System.Windows.Forms.dll 添加到类库是没有意义的,但是有没有办法在 .Net 核心类库中添加 System.Windows.Forms 及其依赖项。

注意:我曾尝试手动添加 System.Windows.Forms.dll,但没有成功。

【问题讨论】:

  • “无法解决”是什么意思?您可以编辑您的帖子以包含您看到的确切错误消息吗?

标签: c# .net .net-core .net-framework-version


【解决方案1】:

我得到了解决方案,我们可以通过框架参考来实现。

<FrameworkReference Include="Microsoft.WindowsDesktop.App" /> 

更多详情请参考https://natemcmaster.com/blog/2019/01/09/netcore-primitives-3/

【讨论】:

  • 我用 .NET Core 3.1 Azure Function 尝试了这种方法,但没有帮助。
  • @Murphybro2 你解决过这个问题吗?如果是这样,解决方案是什么?我也面临 .NET Core 2.1 / 3.1 Azure 函数的问题
  • @JurgenCuschieri 不,很遗憾没有。我们认为这是不可能的,因此不得不更改规范。我们还尝试在需要 Windows 窗体的 Azure 函数中使用 .dll。
  • 如果您想在 .net core 3.0.5 中使用 winforms dll,那么您需要在您的 csproj 文件中进行如下更改。 net5.0-windowsTrue
【解决方案2】:

通过在项目 .csproj 文件中添加 &lt;UseWindowsForms&gt;True&lt;/UseWindowsForms&gt; 使其在 .net core 3.1 中与我一起工作,如下所示:

<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWindowsForms>True</UseWindowsForms>
</PropertyGroup>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-22
    • 2020-06-04
    • 2020-08-27
    • 1970-01-01
    • 2022-01-19
    相关资源
    最近更新 更多