ReGenSource 0.4.0.50
See the version list below for details.
dotnet add package ReGenSource --version 0.4.0.50
NuGet\Install-Package ReGenSource -Version 0.4.0.50
<PackageReference Include="ReGenSource" Version="0.4.0.50" />
<PackageVersion Include="ReGenSource" Version="0.4.0.50" />
<PackageReference Include="ReGenSource" />
paket add ReGenSource --version 0.4.0.50
#r "nuget: ReGenSource, 0.4.0.50"
#:package ReGenSource@0.4.0.50
#addin nuget:?package=ReGenSource&version=0.4.0.50
#tool nuget:?package=ReGenSource&version=0.4.0.50
ReGenSource
I hate RESX files.
There. I said it.
I hate them because they are a pain to work with. They are not human-readable, they are not merge-friendly, they are never consistent in tabs/spaces or comments, and they are a pain to manage.
I hate them so much that I decided to write a tool to replace them.
What is ReGenSource?
ReGenSource is a tool that generates source code with localized resources from a JSON file.
How can I use this in my project?
Step one is to create a JSON file with the resources you want to localize. The file name must end with .res.json.
The JSON file must be added to your project file, along with a reference to the ReGenSource package.
<ItemGroup>
<AdditionalFiles Include="Resources.res.json" />
<PackageReference Include="ReGenSource" Version="0.1.0-ci.17" />
</ItemGroup>
The JSON file should be structured like this:
{
"namespace": "MyApp.Resources",
"class": "MyResources",
"resources": [
{
"name": "Welcome",
"default": "Welcome to my application",
"translations": {
"pt": "Bem-vindo ao meu aplicativo",
"nb,nn": "Velkommen til min applikasjon"
}
}
]
}
Namespace
The namespace is the namespace that the generated class will be placed in.
By default, the namespace is ReGenSource.
Class
The class is the name of the class that will be generated.
By default, the class is Resources.
Resources
The resources is an array of resources that will be generated. Each resource has a name, a default value, and a set of translations. The default value is used when no translation is found for the current culture.
CultureDefinition
By default the culture is defined by the Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName property. This is what is compared with the translation languages.
If you need a different way to define the culture, you can add a CultureDefinition property to the JSON file. This property should be a string that will be used as the culture definition in the generated code.
"CultureDefinition": "global::System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName"
ClassAccessModifier
By default the class is generated as a public class. It can however be set as internal by overriding the ClassAccessModifier property:
"ClassAccessModifier": "Internal"
Resources
Name
The name of the resource, used as the property name in the generated class.
Default
This is the translation to fallback to when no other translation is found for the given language.
Translations
Keys support comma-separated values to allow for multiple languages to be used for the same translation.
Variables
A translation (or the default value) may contain named placeholders written as {name}, where the name is a valid C# identifier. When a resource contains any placeholder, the generated member becomes a method that takes one object? parameter per distinct placeholder and formats the localized string with string.Format:
{
"name": "Welcome",
"default": "Welcome to my application, {name}",
"translations": {
"nb,nn": "Velkommen til min applikasjon, {name}",
"sv": "Välkommen till min applikation"
}
}
generates:
public static string Welcome(object? @name) => string.Format(/* culture switch */, @name);
Notes:
- The parameter list is the union of all placeholder names across the default and every translation, in order of first appearance. A translation that omits a placeholder (like
svabove) simply ignores the extra argument. - Resources without any placeholder keep the original property form (e.g.
public static string Welcome), so this is backward compatible. - Any literal
{or}that is not part of a placeholder is emitted escaped ({{/}}) sostring.Formattreats it as a literal brace.
Type
A resource can be one of the following types (defaulting to Text):
Text— an inline localized string (everything described above).TextFile— thedefault/translationsvalues are file paths; the generated member reads the file's text at runtime and returns astring.Binary— the values are file paths; the generated member reads the file's bytes at runtime and returns abyte[].
{
"name": "Logo",
"type": "Binary",
"default": "logo.png",
"cacheTimeout": "00:05:00"
}
generates:
public static byte[] Logo => /* reads logo.png at runtime */;
File-backed resources still support per-culture paths via translations, so an image or text file can be localized or shared across cultures.
Declaring referenced files
Each file referenced by a TextFile/Binary resource is declared once, as an AdditionalFiles item with CopyToOutputDirectory metadata:
<AdditionalFiles Include="logo.png" CopyToOutputDirectory="PreserveNewest" />
This single line does two jobs:
AdditionalFilesmakes the file visible to the generator for the compile-time existence check (source generators may not touch the disk, so this is the only way to see it).CopyToOutputDirectorycopies the file to the output directory. ReGenSource ships an MSBuild targets file (auto-imported with the NuGet package) that promotes suchAdditionalFilesinto the build's copy-to-output pipeline.
Loading and paths
File contents are not embedded in the assembly — they are read at runtime. Relative paths resolve against the application base directory (next to the assembly), not the working directory, which is why referenced files are copied to the output directory. The path in the JSON should therefore match the file's location relative to that output directory (mirroring its location in the project).
Binary resources return a fresh copy of the byte array on each access, so callers can safely mutate the result without corrupting the cache.
cacheTimeout
By default a file is read from disk on every access (nothing is retained in memory). Set cacheTimeout to keep the loaded content around:
- omitted — no caching (read every time).
- a TimeSpan string such as
"00:05:00"— cache for that duration measured from load, then reload on the next access. "infinite"— cache for the lifetime of the application.
The cache is thread-safe and keyed by the resolved path. A cached entry is evicted by a timer when it expires, so its memory is freed even if the resource is never accessed again (nothing is retained past its timeout). "infinite" entries are, by design, kept for the lifetime of the application.
Compile-time existence check
By default the generator verifies at compile time that every file referenced by a TextFile/Binary resource exists. Because source generators may not touch the disk, this check is performed against the project's AdditionalFiles — which is exactly how the files are declared above, so no extra setup is needed.
The check can be disabled globally with "validateFilePaths": false at the root of the JSON, or per resource with "validateFilePath": false. When disabled, a referenced file no longer needs to be an AdditionalFiles item, but it still needs to reach the output directory some other way (e.g. <None Include="..." CopyToOutputDirectory="PreserveNewest" />) to be loadable at runtime.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.5.0-feat-3.1 | 47 | 7/10/2026 |
| 0.5.0-dependabot-nuget-src-... | 38 | 7/6/2026 |
| 0.5.0-dependabot-nuget-src-... | 36 | 7/6/2026 |
| 0.5.0-dependabot-github-act... | 49 | 6/22/2026 |
| 0.4.1 | 9,766 | 2/24/2026 |
| 0.4.0.51 | 91 | 10/27/2026 |
| 0.4.0.50 | 86 | 10/27/2026 |
| 0.4.0.49 | 90 | 10/20/2026 |
| 0.4.0.48 | 93 | 10/14/2026 |
| 0.4.0.47 | 108 | 9/15/2026 |
| 0.4.0.46 | 96 | 9/15/2026 |
| 0.4.0.45 | 107 | 8/19/2026 |
| 0.4.0.44 | 109 | 8/18/2026 |
| 0.4.0.43 | 100 | 8/18/2026 |
| 0.4.0.42 | 103 | 8/18/2026 |
| 0.4.0.41 | 117 | 8/4/2026 |
| 0.4.0.40 | 118 | 8/4/2026 |
| 0.4.0.39 | 114 | 8/4/2026 |
| 0.4.0.38 | 106 | 7/14/2026 |
| 0.4.0.37 | 119 | 7/10/2026 |