【发布时间】:2012-08-17 13:49:50
【问题描述】:
我对资源文件有一个奇怪的问题。奇怪,因为它工作得很好。 好吧,我有一些资源文件。我在我的 asp.net mvc 3 项目结构上创建了一个 Resources 文件夹,我正在镜像视图的文件夹结构。现在我有:
Views
Shared
_Layout.cshtml
Resources
Shared
Layout.pt-BR.resx
Layout.en-US.resx
Layout.ko-KR.resx
所有资源文件都配置为嵌入式资源、PublicResXFileCodeGenerator 和自定义工具命名空间“ViewRes”。所有“.Designer.cs”文件都是空的。我记得在它工作的时候看到了其中的一些代码。
在我的 .csproj 文件中,我有这些数据:
<ItemGroup>
<EmbeddedResource Include="Resources\Shared\Layout.en-US.resx">
<SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Layout.en-US.Designer.cs</LastGenOutput>
<CustomToolNamespace>ViewRes</CustomToolNamespace>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Shared\Layout.ko-KR.resx">
<SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator>
<CustomToolNamespace>ViewRes</CustomToolNamespace>
<LastGenOutput>Layout.ko-KR.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Shared\Layout.pt-BR.resx">
<SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Layout.pt-BR.Designer.cs</LastGenOutput>
<CustomToolNamespace>ViewRes</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>
问题是:当我尝试访问我的视图上的@ViewRes 时,它无法识别。我已经尝试删除自定义工具命名空间,但 @Resource 也无法识别。在这两种情况下,我都得到了这个编译错误:
Compiler Error Message: CS0103: The name 'ViewRes' does not exist in the current context
有人知道吗? 谢谢, 保罗
编辑:新信息
我在 VS2010 中通过项目的属性菜单创建了一个全局 Resources.resx 文件,它正在使用我输入的自定义工具命名空间。 “资源”命名空间仍然无法正常工作。我认为问题出在本地资源文件上。不幸的是,我需要它们,因为我无法重命名包含文化代码的全局 resources.resx 文件。
编辑 2 我在 Resource 文件夹上创建了新的 .resx 文件,我可以看到文件名不能有 2 个“.”。名字是Resources.resx,它可以工作。如果名称是 Resource-en-US.resx,它可以工作,但是,如果名称是 Resources.en-US.resx,它会失败!
【问题讨论】:
-
我认为它可能会帮助你stackoverflow.com/questions/886473/…
-
我注意到你应该添加一个不带两个点的资源文件来创建命名空间
标签: asp.net-mvc-3 localization globalization