设计器 resx 文件仍为空

本文关键字:文件 resx | 更新日期: 2023-09-27 18:34:25

当我向现有的resx文件添加或更改字符串时,相应的设计器.cs文件变为空(0 KB(,项目不再编译:

错误 CS0234:类型或命名空间名称"属性"不存在 在命名空间"Hundegger.Gui"中(您是否缺少程序集 参考?

不过,一切似乎都很好。

从 .csproj 文件:

<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>

任何想法可能出错???resx 文件相当简单。目前仅包含 10 个字符串。

前段时间,我们将项目转换为面向 .net Framework 4.5.2(以前使用 4.0(。

同一解决方案中的另一个项目(也转换为 4.5.2(没有此问题。一旦修改/添加了 resx 文件中的字符串,设计器文件就会重新生成并且不为空。我注意到 .csproj 文件与 resx 文件没有区别。

我使用的是Visual Studio 2013。

谢谢!

编辑 - 到达某个地方!!

遇到了另一个问题,这给了我一个想法。如果文件已本地化,Visual Studio 2010 不会生成资源 (Resx( 设计器代码

似乎resx文件名中的某些扩展名导致VS不生成相应的设计器.cs文件。

上一个问题提到了本地化扩展:fr、en、de 等......

但是:桂也有同样的效果。

如果我将resx文件重命名为Hundegger.Gui2.resx,那么一切正常。

我可以通过在VS 2013中创建一个空项目来验证这一点。如果 resx 文件名以 .gui 或 .job 结尾,则不会生成设计器文件。

这在不久前一定发生了变化,否则就不会生成现有的设计器文件。

所以我想为了避免此类问题,请避免在 resx 文件名中使用"."。

所以我想为了我们的目的,我们将不得不重命名 resx 文件。

设计器 resx 文件仍为空

>我可以在VS 2015中重现相同的行为。但是,如果您删除resx文件中的点,则一切正常。所以请从Hundegger.Gui.resx改为HundeggerGui.resx

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.