.NET Core 1.1资源文件问题 [英] .NET Core 1.1 Resource File Issue

查看:57
本文介绍了.NET Core 1.1资源文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的.NET Core类库项目中,当资源文件名中包含点时,资源文件不会更新.例如,当我在.NET Core项目中添加 Resources.en.resx Resources.es.resx 文件时,自定义工具将无法生成或更新C#资源文件.这是错误消息:

In my .NET Core class library project, the resource file does not get updated when the resource file name contains a dot in it. For example, when I add Resources.en.resx or Resources.es.resx files in the .NET Core project, the custom tool is not able to generate or update the C# resource file. Here is error message:

自定义工具ResXFileCodeGenerator未能为输入文件'Resources.en.resx'生成输出,但未记录特定错误.

如果您知道任何解决方法或解决方法,请向我指出正确的方向

If you know any workaround or any fix for it, please kindly point me to the right direction

推荐答案

删除当前资源目录中的所有.resx文件.

Delete any .resx files currently in your Resources directory.

现在转到您的 Resources 目录,然后右键单击 Add>新项目.

Now go to your Resources directory and right click for Add > New Item.

选择资源文件,然后在表单底部输入文件名.重要的是您第一次使用正确的名称并且不要重命名.您可以使用 Resource.resx 之类的东西.

Choose Resource File and enter in a file name down the bottom of the form. It's important you get the name right first time and don't rename. You can use something like Resource.resx.

第一个 Resource.resx 文件应具有其自己的设计器类.它还需要用于项目本地化的所有键和值,因此,如果您有现有的 Resource.en.resx ,则可以将其中的值复制并粘贴到该代码中.

This very first Resource.resx file should have its own designer class. It also needs all the keys and values for localization for your project so if you have an existing Resource.en.resx you can copy and paste the values from that into this one.

如果您需要 IStringLocalizer< Resource> ,或者换句话说,您需要以某种方式引用 Resource 类,则需要转到解决方案资源管理器并向左单击 Resource.resx.在属性"框中,有一个名为自定义工具"的字段.如果要从resx生成可公开访问的类,则需要将其从 ResXFileCodeGenerator 更改为 PublicResXFileCodeGenerator .

If you need IStringLocalizer<Resource> or, in other words, you need to reference the Resource class somehow then you will need to go to Solution Explorer and left-click on the Resource.resx. In the Properties box there is a field called "Custom Tool". If you want a publically accessible class to be generated from the resx you will need to change this from ResXFileCodeGenerator to PublicResXFileCodeGenerator.

现在,您可以添加单独的 Resource.ja.resx Resource.es.resx 文件.这些工具不需要不需要在其上运行自定义工具 ResXFileCodeGenerator ,以便您可以从属性中删除该工具.这将解决您的错误消息.

Now you can add the individual Resource.ja.resx, Resource.es.resx files. These do not need to have a custom tool ResXFileCodeGenerator run on them so you can remove that from the properties. This will fix your error message.

这篇关于.NET Core 1.1资源文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆