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

可紊 提交于 2019-12-07 03:09:49

问题


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.

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


回答1:


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>



来源:https://stackoverflow.com/questions/20408370/why-is-the-generated-class-for-a-resource-file-in-a-file-with-a-different-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!