Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the generated class for a resource file in a file with a different name?

I have a resource file strings.resx, and the generated resource class is in strings1.designer.cs. Why is this the case? The problem specifically is the "1". The class name inside that file is "strings", as it should be.

screenshot

Note that I did try deleting the designer.cs and regenerating it by saving the resx file, but that didn't change anything.

like image 545
user2320724 Avatar asked Dec 05 '13 19:12

user2320724


People also ask

How are RESX files generated?

Resource files (. resx) are only generated with source code when building a Project in Developer Studio.

What is a resource file?

A resource file is a text file with the extension . rc. The file can use single-byte, double-byte, or Unicode characters. The syntax and semantics for the RC preprocessor are similar to those of the Microsoft C/C++ compiler. However, RC supports a subset of the preprocessor directives, defines, and pragmas in a script.

What is the use of RESX file in C#?

Resources in . resx files. Unlike text files, which can only store string resources, XML resource (. resx) files can store strings, binary data such as images, icons, and audio clips, and programmatic objects.


1 Answers

I just ran into this problem and found the issue inside the .csproj file. It appears that Visual Studio saves the last filename it used and attempts to generate using that filename again. So if for some reason the Strings.designer.cs is ever generated as Strings1.designer.cs it looks like VS will continue to use Strings1.

Below you can see the portions of the .csproj file that was giving me an issue. Most importantly the <LastGenOutput> at the end where Strings1.designer.cs is saved.

<Compile Include="App_GlobalResources\Strings.Designer.cs">
  <AutoGen>True</AutoGen>
  <DesignTime>True</DesignTime>
  <DependentUpon>Strings.resx</DependentUpon>
</Compile>
<Compile Include="App_GlobalResources\Strings.es.designer.cs">
  <AutoGen>True</AutoGen>
  <DesignTime>True</DesignTime>
  <DependentUpon>Strings.es.resx</DependentUpon>
</Compile>
...
<ItemGroup>
  <EmbeddedResource Include="App_GlobalResources\Strings.es.resx">
    <Generator>GlobalResourceProxyGenerator</Generator>
    <LastGenOutput>Strings.es.designer.cs</LastGenOutput>
  </EmbeddedResource>
  <EmbeddedResource Include="App_GlobalResources\Strings.resx">
    <Generator>GlobalResourceProxyGenerator</Generator>
    <LastGenOutput>Strings1.designer.cs</LastGenOutput>
  </EmbeddedResource>
</ItemGroup>

Changing the <LastGenOutput> to the following solved my problem:

<LastGenOutput>Strings.designer.cs</LastGenOutput>

like image 115
Ryan Avatar answered Oct 06 '22 01:10

Ryan