1

I want to write in my .resx file. I have used ResXResourceWriter which works fine in Windows form but doesn't available in .Net Core application. It needs system.Windows.Forms but .net core don't reference to it.

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

Sohaib hassan
  • 31
  • 1
  • 1
  • 4
  • 1
    What exactly is your question? System.Windows.Forms does not exist in .net core. If you are looking for localization please see [Globalization and localization in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.2) – hawkstrider Jan 17 '19 at 17:18
  • I actually want to dump database data into .resx file. Is it possible in .net core? – Sohaib hassan Jan 17 '19 at 17:25
  • The ResXResourceWriter class is not available in .net core, to create one you would need to use .net framework – hawkstrider Jan 17 '19 at 17:27
  • Can you please tell me the procedure? – Sohaib hassan Jan 17 '19 at 17:36
  • Not sure what procedure you are talking about, if you want to learn about wrting resource files, look at [System.Resources Namespace](https://learn.microsoft.com/en-us/dotnet/api/system.resources?view=netframework-4.7.2) – hawkstrider Jan 17 '19 at 17:39

2 Answers2

10

If you already have .net Core 3.0 (or more) installed and want to add a reference to an existing project (.csproj).

You can only add the following tag:

<UseWindowsForms>true</UseWindowsForms> into the following section: <PropertyGroup>

I think it is new: Menu "Edit Project File" in project Contextual Menu in Visual Studio.

Like so (added into a WPF project):

<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>
Marc.2377
  • 7,807
  • 7
  • 51
  • 95
Eric Ouellet
  • 10,996
  • 11
  • 84
  • 119
3

You will currently need to use the .Net Core 3.0 Preview, as System.Windows.Forms is new in .Net Core 3.0. From the System.Windows.Forms repository:

You can create a new WinForms application with dotnet new command, using the following commands:

dotnet new winforms -o MyWinFormsApp
cd MyWinFormsApp
dotnet run
Jonathan Dickinson
  • 9,050
  • 1
  • 37
  • 60