【问题标题】:Add reference of System.Windows.forms in .Net Core在 .Net Core 中添加 System.Windows.forms 的引用
【发布时间】:2019-06-11 22:57:55
【问题描述】:

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

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

【问题讨论】:

  • 您的问题到底是什么? System.Windows.Forms 在 .net 核心中不存在。如果您正在寻找本地化,请参阅Globalization and localization in ASP.NET Core
  • 我实际上想将数据库数据转储到 .resx 文件中。 .net core 有可能吗?
  • ResXResourceWriter 类在 .net 核心中不可用,要创建一个您需要使用 .net 框架的类
  • 你能告诉我程序吗?
  • 不知道你说的是什么程序,如果你想了解写资源文件,看System.Resources Namespace

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


【解决方案1】:

如果您已经安装了 .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>

【讨论】:

【解决方案2】:

您目前需要使用.Net Core 3.0 Preview,因为 System.Windows.Forms 是 .Net Core 3.0 中的新功能。来自System.Windows.Forms repository

您可以使用 dotnet new 命令创建一个新的 WinForms 应用程序, 使用以下命令:

dotnet new winforms -o MyWinFormsApp
cd MyWinFormsApp
dotnet run

【讨论】:

  • 我认为我的问题不够清楚。实际上,它是一个基于 .net core MVC 的网站
  • 根据您问题中的 cmets,.resx 文件只是 XML 文件。您应该能够使用 XDocument 来打开和更改它们。
猜你喜欢
  • 2020-03-09
  • 2022-01-17
  • 1970-01-01
  • 1970-01-01
  • 2012-06-06
  • 1970-01-01
  • 2019-03-29
  • 2016-12-30
相关资源
最近更新 更多