EugeneLepekhin.StrongTypeResource 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package EugeneLepekhin.StrongTypeResource --version 1.0.3
                    
NuGet\Install-Package EugeneLepekhin.StrongTypeResource -Version 1.0.3
                    
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="EugeneLepekhin.StrongTypeResource" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EugeneLepekhin.StrongTypeResource" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="EugeneLepekhin.StrongTypeResource" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EugeneLepekhin.StrongTypeResource --version 1.0.3
                    
#r "nuget: EugeneLepekhin.StrongTypeResource, 1.0.3"
                    
#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.
#:package EugeneLepekhin.StrongTypeResource@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EugeneLepekhin.StrongTypeResource&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=EugeneLepekhin.StrongTypeResource&version=1.0.3
                    
Install as a Cake Tool

StrongTypeResource

StrongTypeResource is a NuGet package that provides strongly typed access to .NET resources with additional verification of satellite .resx files.

What It Does

  • Strongly Typed Access: Generate strongly typed classes that provide safe access to your .resx resources
  • Parameter Validation: Automatically verify that format parameters match across different culture files
  • Build-Time Safety: Catch resource-related errors during compilation instead of runtime

Example

Given these resources in your .resx file:

WelcomeMessage = Welcome to our application
ItemsFound = Found {0} items in {1} seconds

Traditional .NET resource generation creates properties for both:

// Both are properties - no compile-time parameter validation
string message = Resources.WelcomeMessage;
string formatted = string.Format(Resources.ItemsFound, count, time); // Easy to mess up parameters

With StrongTypeResource (using comment {int count, double time} for ItemsFound):

// Simple strings remain properties, formatted strings become type-safe methods
string message = Resources.WelcomeMessage;
string formatted = Resources.ItemsFound(count, time); // Compile-time parameter validation

Getting Started

1. Install the Package

Add the StrongTypeResource NuGet package to your project.

2. Configure Your Resource Files

Replace the default Custom Tool for your .resx files with one of these generators:

  • StrongTypeResource.internal - Creates internal class
  • StrongTypeResource.public - Creates public class (useful for cross-project access and WPF binding)
Option A: Using Visual Studio
  1. Right-click your .resx file
  2. Select Properties
  3. Change Custom Tool to StrongTypeResource.internal or StrongTypeResource.public
Option B: Edit .csproj Directly
<ItemGroup>
    <EmbeddedResource Update="Resources\Text.resx">
        <Generator>StrongTypeResource.internal</Generator>
    </EmbeddedResource>
</ItemGroup>

For public access (recommended for WPF projects):

<ItemGroup>
    <EmbeddedResource Update="Resources\Text.resx">
        <Generator>StrongTypeResource.public</Generator>
    </EmbeddedResource>
</ItemGroup>

How Resources Are Generated

Simple Strings → Properties

Plain strings without formatting become string properties:

Welcome=Welcome to our application

Generates: string Welcome { get; }

Formatted Strings → Methods

Strings with placeholders become methods with parameters. You must specify parameter types in the comment field:

Resource Value:

Found {0} items in {1} seconds.

Comment:

{int itemCount, double seconds}

Generated Method:

string FoundItems(int itemCount, double seconds)

Skip Method Generation

To generate a formatted string as a property instead of a method, add a minus (-) at the beginning of the comment:

-This will be a property, not a method

Special Features

WPF Support

In WPF projects, the tool automatically generates a FlowDirection helper property for XAML binding.

Pseudo Resources (Testing)

Generate longer, non-Latin character strings for UI testing while keeping them readable. This helps you test how your UI handles:

  • Longer text: Pseudo strings are typically 30-50% longer than original text
  • Different character sets: Uses accented and non-Latin characters to simulate international content
  • Layout issues: Helps identify truncation, wrapping, and spacing problems before deploying to different cultures

For example, "Save" might become "[Šàvë!!!!]" - longer and using accented characters, but still readable for testing.

Enable pseudo resources:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
  <DefineConstants>$(DefineConstants);Pseudo</DefineConstants>
</PropertyGroup>

Legacy Compatibility

For transitioning from old resource systems to StrongTypeResource, enable optional parameters to generate warnings instead of errors for formatted strings without proper parameter comments:

<PropertyGroup>
    <StrongTypeResourceOptionalParameters>true</StrongTypeResourceOptionalParameters>
</PropertyGroup>

This allows you to gradually migrate your resources - formatted strings without parameter comments will still generate properties (like traditional resources) but with build warnings reminding you to add parameter definitions to get full strongly typed benefits.

Automatic Verification

StrongTypeResource automatically verifies that:

  • Format parameters match between main and satellite .resx files
  • All cultures have consistent parameter types and counts
  • Potential runtime errors are caught at build time

Verification results appear in Visual Studio's Output window during build.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.1.8 153 9/22/2025
1.1.6 133 9/11/2025
1.1.4 139 9/1/2025
1.1.2 134 8/20/2025
1.1.0 142 8/11/2025
1.0.4 145 7/17/2025
1.0.3 94 7/11/2025
1.0.2 145 7/9/2025
1.0.1 149 7/8/2025
1.0.0 146 7/8/2025