简体   繁体   English

.NET:Resgen教程

[英].NET: Resgen Tutorial

First off I have RFM and RFM and I have tried to follow a few sites but I cannot grasp the concept of the Resource Manager. 首先,我有RFMRFM,并且我尝试关注一些站点,但是我无法理解资源管理器的概念。

Can someone please explain to me how to generate a resource manager similar to that of the VS IDE. 有人可以向我解释一下如何生成类似于VS IDE的资源管理器。

For example if I compile with VBC from the commandline I can see all my resource files. 例如,如果我从命令行使用VBC进行编译,则可以看到我的所有资源文件。

vbc /t:exe myfile.vb /res:res1 /res:res2 vbc / t:exe myfile.vb / res:res1 / res:res2

Dim a as Assembly = Assembly.GetExecutingAssembly()
For Each i as string in a.GetManifestResourceNames()
    Console.writeline(i)
Next i

res1 1号

res2 res2

If I compile with the VS IDE I only see: 如果我使用VS IDE进行编译,则只会看到:

myprogram.Resources.resource myprogram.Resources.resource

How do I create a resource manager manually from the command line so that I can use the resource manager like I would with the VS IDE? 如何从命令行手动创建资源管理器,以便可以像使用VS IDE一样使用资源管理器?

Dim CurrentResourceManager As New ResourceManager(_
"myprogram.Resources", CurrentAssembly)
Dim CurrentResourceSet As ResourceSet = CurrentResourceManager.GetResourceSet( _
CultureInfo.CurrentCulture, True, True)

When I do try to use resgen it complains about my file extention 当我尝试使用resgen时,它抱怨我的文件扩展名

C:...>resgen image.bmp myfile.Resource.resource source C:...> resgen image.bmp myfile.Resource.resource源

ResGen : error RG0000: The file named "image.bmp" does not have a known extension. ResGen:错误RG0000:名为“ image.bmp”的文件没有已知的扩展名。 Managed resource files must end in .ResX, .txt, or .resources. 托管资源文件必须以.ResX,.txt或.resources结尾。

In the Manual it states to use RESXGEN for images, but I do not believe that is available in VS2008. 在《手册》中,它指出要对图像使用RESXGEN ,但我认为VS2008中不提供此功能。 I am stuck. 我被困住了。

Update: Found this : http://msdn.microsoft.com/en-us/library/ekyft91f(VS.80).aspx Explains how to write a ResX file. 更新:找到了: http : //msdn.microsoft.com/zh-cn/library/ekyft91f( VS.80) .aspx介绍了如何编写ResX文件。 Seems like a repeatable process. 似乎是一个可重复的过程。 I am not sure why they would not include a utility with visual studio to create it. 我不确定为什么他们不会在Visual Studio中包含实用程序来创建它。

I attempted to use the example of the ResourceWriter. 我尝试使用ResourceWriter的示例。 Resgen puked upon using the MS Provided ResourceWriter Class. Resgen使用了MS提供的ResourceWriter类。

Simplified version of a Visual Studios Resx generated file. Visual Studios Resx生成文件的简化版本。 I have removed Public Token and the Schema mappings. 我已经删除了公共令牌和架构映射。 The Schema mapping is to assist you when creating/modifying these files. 模式映射可在创建/修改这些文件时为您提供帮助。 For demonstration and simplicity I have stripped it out. 为了演示和简化,我将其删除。

<?xml version="1.0" encoding="utf-8"?>
<root>
  <resheader name="resmimetype">
    <value>text/microsoft-resx</value>
  </resheader>
  <resheader name="version">
    <value>2.0</value>
  </resheader>
  <resheader name="reader">
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral</value>
  </resheader>
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral</value>
  </resheader>
  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral" />
  <data name="mylibrary" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>Resources\mylibrary.dll;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral</value>
  </data>
  <data name="mytext" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>Resources\mytext.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral</value>
  </data>
</root>

For each type byte or string include the following data. 对于每种类型的字节或字符串,请包含以下数据。 Where name is the name you want to access it by and value is eitehr a relative or hard path: 其中name是您要通过其访问的名称,而value是相对路径或硬路径:

<data name="mytext" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>Resources\mytext.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral</value>
<data>

Compile your resource to a single resource manager file and include in your project 将您的资源编译为一个资源管理器文件,并包含在您的项目中

resgen /compile myrex.resx

vbc /t:exe myprogram.vb /res:myresx.resource
csc /t:exe myprogram.cs /res:myresx.resource

You have to create a resource manager in your program to access these files. 您必须在程序中创建一个资源管理器才能访问这些文件。 If you want a strongly typed resource manager you must follow the Resource.Designer class from inside your project and modify that file. 如果需要强类型的资源管理器,则必须从项目内部遵循Resource.Designer类,然后修改该文件。 If you want a simple resource manager simply use GetString or GetBytes. 如果您想要一个简单的资源管理器,只需使用GetString或GetBytes。

Dim rm As New ResourceManager("rmc", [Assembly].GetExecutingAssembly())
day = rm.GetString("mytext")
o = rm.GetObject("mylibrary.dll")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM