designer resx file remains empty

2019-06-23 03:40发布

When I add or change a string to an existing resx file the corresponding designer.cs file becomes empty (0 KB) and the project no longer compiles:

error CS0234: The type or namespace name 'Properties' does not exist in the namespace 'Hundegger.Gui' (are you missing an assembly reference?)

Everything seems to be just fine, though.

From the .csproj file:

<Compile Include="Properties\Hundegger.Gui.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Hundegger.Gui.resx</DependentUpon>
    </Compile>

<EmbeddedResource Include="Properties\Hundegger.Gui.resx">
  <Generator>PublicResXFileCodeGenerator</Generator>
  <LastGenOutput>Hundegger.Gui.Designer.cs</LastGenOutput>
</EmbeddedResource>

Any ideas what could be wrong??? The resx file is rather simple. Currently just contains 10 strings.

Sometime ago we converted the project to target .net framework 4.5.2 (previously was using 4.0).

Another project in the same solution (which was also converted to 4.5.2) does not have this problem. As soon as a string in a resx file is modified/added the designer file is regenerated and is not empty. I notice no difference in the .csproj files concerning the resx files.

Am using Visual Studio 2013.

Thanks!

EDIT - getting somewhere!!

I ran into this other question and that gave me an idea. Visual Studio 2010 doesn't generate Resource (Resx) designer code if file is localized

It seems that certain extensions in the resx file name cause VS to NOT generate the corresponding designer.cs file.

The previous question mentions localization extensions: fr, en, de, etc...

However: Gui has the same effect.

If I rename the resx file to Hundegger.Gui2.resx then everything works just fine.

I could verify this by creating an empty project in VS 2013. If the resx file name ends with .gui or .job then the designer file is not generated.

This must have changed not too long ago, otherwise the existing designer files would have not been generated.

So I guess that in order to avoid such problems, avoid using '.' in the the resx file name.

So I guess for our purpose we will have to rename the resx files.

2条回答
Rolldiameter
2楼-- · 2019-06-23 04:19

I can reproduce the same behavior in VS 2015. But if you remove the dot in the resx file everything it working fine. So please change from Hundegger.Gui.resx to HundeggerGui.resx

查看更多
forever°为你锁心
3楼-- · 2019-06-23 04:20
Yes, Designer resx file remains empty.
you should follow the below steps, it will work 100%.
1) Create Resource.resx file under any folder

2) set CustomTools = PublicResXFileCodeGenerator and
Build Action = Embedded Resource in Resource.resx file property.

3) Now create the different language files like below,
Resources.en-US.resx
Resources.nl-NL.resx  etc

4)If MVC, in your MVC Model refer this namespace as project.folder

5) change the one of the property as below (example)

     [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MMM/yyyy}"), Display(Name = "dtMovinDate",ResourceType = typeof(Resources.Resource))]
                public DateTime dtMovinDate { get; set; }

6)

     In config file add this under System.web

        <globalization enableClientBasedCulture="true" culture="en-US" uiCulture="en-US" />

7) rebuild the project and test it.

It will work. The real reason of designer.cs file empty is resource designer.cs will refer these files based on your web.config file.
查看更多
登录 后发表回答