首页 文章

设计者resx文件仍为空

提问于
浏览
5

当我将字符串添加或更改为现有resx文件时,相应的designer.cs文件变为空(0 KB),并且项目不再编译:

错误CS0234:名称空间'Hundegger.Gui'中不存在类型或命名空间名称'Properties'(您是否缺少程序集引用?)

但是,一切似乎都很好 .

从.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框架4.5.2(之前使用的是4.0) .

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

我使用的是Visual Studio 2013 .

谢谢!

EDIT - getting somewhere!!

我遇到了另一个问题,这给了我一个想法 . Visual Studio 2010 doesn't generate Resource (Resx) designer code if file is localized

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

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

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

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

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

这必须在不久前改变,否则现有的设计器文件将不会生成 .

所以我想这是为了避免这些问题,避免使用' . '在resx文件名中 .

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

2 回答

  • 3

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

  • 13
    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.
    

相关问题