ResxCodeGenerator 1.4.6

dotnet add package ResxCodeGenerator --version 1.4.6                
NuGet\Install-Package ResxCodeGenerator -Version 1.4.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ResxCodeGenerator" Version="1.4.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ResxCodeGenerator --version 1.4.6                
#r "nuget: ResxCodeGenerator, 1.4.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ResxCodeGenerator as a Cake Addin
#addin nuget:?package=ResxCodeGenerator&version=1.4.6

// Install ResxCodeGenerator as a Cake Tool
#tool nuget:?package=ResxCodeGenerator&version=1.4.6                

Snippet

Snippet

ResxCodeGenerator

Generates strongly typed wrapper classes. Include contants for each string resource. Avoid the usage of "magic string". Ensure code and resource file coherence.

The generated classes are named with the same name as their associated resx. These classes can then be used as follows:

file : MyResource.en.resx

    @inject IMyResourceLocalizer Localizer
    <span>@Localizer.Hello</span>

As the designated solution for localization is to use IStringLocalizer.

Usage

  • Install the package
Install-Package ResxCodeGenerator
  • Define .resx files
  • On the paramters of the resx set <generation action> to "additionnal c# analyzer file"

in csproj this look like this

<ItemGroup>
  <AdditionalFiles Include="*.en.resx" /> 
</ItemGroup>

N.B. - Set this option for only one language per resource. Otherwise, the generated classes will conflict.

Add Interfaces services in App

The package also include a tools to register all Resources Interfaces. in Program.cs

*I'm a bit allergic to magic string. That's kind of why I reference my namespace from code reflection.*😉

var assemblyName = typeof(<YourNameSpaceRoot>.Resources.<AnyOfGeneratedClass>).Namespace);

But it also possible to reference like this

var assemblyName = "<YourNameSpaceRoot>.Resources";

Then use the extension method to add resources's Interfaces

using ResxCodeGeneration.Tools;
...

builder.Services
    .AddLocalizedResources(
	    Assembly.GetExecutingAssembly(),
	    assemblyName);
Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ResxCodeGenerator:

Package Downloads
ResxCodeGenerator

A code generator for .resx files

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.6 108 7/11/2024
1.4.0 86 7/11/2024

Initial release