首页 > 解决方案 > 在 .Net Core 中添加 System.Windows.forms 的引用

问题描述

我想写在我的 .resx 文件中。我使用了 ResXResourceWriter,它在 Windows 表单中运行良好,但在 .Net Core 应用程序中不可用。它需要 system.Windows.Forms 但 .net 核心不引用它。

ResXResourceWriter resx = new ResXResourceWriter(hostingEnvironment.WebRootPath + "\Localization\LabelResource.EN.resx")

标签: c#asp.net.net.net-core

解决方案


如果您已经安装了 .net Core 3.0(或更高版本)并且想要添加对现有项目 (.csproj) 的引用。

您只能添加以下标签:

<UseWindowsForms>true</UseWindowsForms>进入以下部分: <PropertyGroup>

我认为它是新的:Visual Studio 中项目上下文菜单中的菜单“编辑项目文件”。

像这样(添加到 WPF 项目中):

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWPF>true</UseWPF>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\GeneralCore\GeneralCore.csproj" />   </ItemGroup>

</Project>

推荐阅读