-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Issue Description
Hi.
The GenerateResource task fails with a resource string key/name containing an equals or back tick character in a resources file (resx).
Building the same resources file works when using ResXFileCodeGenerator or PublicResXFileCodeGenerator.
Steps to Reproduce
- Create a new C# project (ex. "MSTest Test project").
- Add a new resources file (ex. "Resource1.resx").
- Add a new resource with the name
equalsand value=. - Notice the project builds successfully.
- Right-click on the resx file and select "Open With..." and select "XML (Text) Editor".
- Change the name from
equalsto=. - Notice the project builds successfully.
- Open the csproj file and replace this:
<ItemGroup>
<Compile Update="Resource1.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resource1.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resource1.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource1.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>With this:
<ItemGroup>
<EmbeddedResource Update="Resource1.resx" Type="Resx">
<Generator>MSBuild:Compile</Generator>
<StronglyTypedLanguage>$(Language)</StronglyTypedLanguage>
</EmbeddedResource>
</ItemGroup>- Notice the build fails with the following errors:
1>C:\Program Files\Microsoft Visual Studio\18\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(3442,5): error MSB3557: Error(s) generating strongly typed resources for file "Resource1.resx".
1>C:\Program Files\Microsoft Visual Studio\18\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(3442,5): error MSB3567: Could not generate property on class "=".
Expected Behavior
I expected the build to succeed and a strongly typed class generated for the resources file.
In production, my string resource key is not actually one character, but more like:
'User name' contains invalid characters. The following characters are not allowed: "/[]:|<>+=;,?%@`
And the error is
Could not generate property on class "'User name' contains invalid characters. The following characters are not allowed: "/[]:|<>+=;,?%@`"
So it was not exactly clear why the property on the class was not generated (which characters caused the issue).
If I remove the equals sign (=) and back tick (`) characters, the build succeeds and the strongly typed class is generated successfully.
The name of the property that is created has underscore characters instead of some of the other symbols, so I expected the GenerateResource task to do the same for the equals and back tick characters.
Actual Behavior
The build fails with the following errors:
1>C:\Program Files\Microsoft Visual Studio\18\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(3442,5): error MSB3557: Error(s) generating strongly typed resources for file "Resource1.resx".
1>C:\Program Files\Microsoft Visual Studio\18\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(3442,5): error MSB3567: Could not generate property on class "=".
A strongly typed class is not generated.
Analysis
No response
Versions & Configurations
Windows 11 Version 25H2 (OS Build 26200.7171)
Visual Studio 2026 Version 18.1.1
MSBuild version 18.0.5+e22287bf1 for .NET Framework 18.0.5.56406