EugeneLepekhin.StrongTypeResource
1.1.0
See the version list below for details.
dotnet add package EugeneLepekhin.StrongTypeResource --version 1.1.0
NuGet\Install-Package EugeneLepekhin.StrongTypeResource -Version 1.1.0
<PackageReference Include="EugeneLepekhin.StrongTypeResource" Version="1.1.0" />
<PackageVersion Include="EugeneLepekhin.StrongTypeResource" Version="1.1.0" />
<PackageReference Include="EugeneLepekhin.StrongTypeResource" />
paket add EugeneLepekhin.StrongTypeResource --version 1.1.0
#r "nuget: EugeneLepekhin.StrongTypeResource, 1.1.0"
#:package EugeneLepekhin.StrongTypeResource@1.1.0
#addin nuget:?package=EugeneLepekhin.StrongTypeResource&version=1.1.0
#tool nuget:?package=EugeneLepekhin.StrongTypeResource&version=1.1.0
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: Generates a class with strongly typed properties and methods 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:
MSBuild:StrongTypeResourceInternal
- Creates an internal classMSBuild:StrongTypeResourcePublic
- Creates a public class (useful for cross-project access and WPF binding)
If you have been using older versions of StrongTypeResource, you will need to replace old Custom Tool
StrongTypeResource.internal
orStrongTypeResource.public
withMSBuild:StrongTypeResourceInternal
orMSBuild:StrongTypeResourcePublic
.
The new generator strings allow to generate the wrapper code after you save the .resx file, so you can see changes immediately without rebuilding the project.
Option A: Using Visual Studio
- Right-click your .resx file
- Select Properties
- Change Custom Tool to
MSBuild:StrongTypeResourceInternal
orMSBuild:StrongTypeResourcePublic
Option B: Edit .csproj Directly
<ItemGroup>
<EmbeddedResource Update="Resources\Text.resx">
<Generator>MSBuild:StrongTypeResourceInternal</Generator>
</EmbeddedResource>
</ItemGroup>
For public access (recommended for WPF projects):
<ItemGroup>
<EmbeddedResource Update="Resources\Text.resx">
<Generator>MSBuild:StrongTypeResourcePublic</Generator>
</EmbeddedResource>
</ItemGroup>
3. Remove the Original Generated File
In Solution Explorer, right-click on the generated file (<YourResourceFile>.Designer.cs
next to your .resx file) and select Delete.
This prevents conflicts with the new StrongTypeResource-generated code.
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 of the main (neutral language) .resx file - comments in satellite .resx files are ignored.
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
Enumeration Strings
For strings that should be restricted to specific values, add a comment with !
followed by allowed values:
!(Value1, Value2, Value3)
This ensures the string in the main resource file or any satellite files matches one of the allowed values, generating a compile-time error if it doesn't match.
Special Features
WPF Support
In WPF projects, the tool automatically generates a FlowDirection
helper property for XAML binding.
Pseudo Resources (Testing)
Generates 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:
Option A: Using Visual Studio
In your project properties, enter Pseudo
in the Conditional compilation symbols field.
Option B: Edit .csproj Directly
<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.
Learn more about Target Frameworks and .NET Standard.
-
.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.
Allow update of resource wrapper code after saving .resx file. Better tool performance.