.NET:RESGEN教程教程、NET、RESGEN

2023-09-06 23:30:51 作者:看透也是解脱。

首先,我有 RFM 并 RFM ,然后我试图跟随一些网站,但我无法掌握资源管理器的概念。

有人能向我解释如何生成一个资源管理器类似于VS IDE的。

例如,如果我编译VBC从命令行我可以看到我所有的资源文件。

  

VBC /吨:EXE myfile.vb / RES:RES1 / RES:RES2

 暗淡了作为大会= Assembly.GetExecutingAssembly()
对于每一个我的字符串中a.GetManifestResourceNames()
    Console.writeline㈠
接下来我
 

  

RES1

     

RES2

.net教程 –

如果我编译VS IDE的我只看到:

  

myprogram.Resources.resource

如何通过命令行手动创建一个资源管理器,这样我就可以使用资源管理器就像我会与VS IDE?

 昏暗CurrentResourceManager作为新的ResourceManager(_
myprogram.Resources,CurrentAssembly)
昏暗CurrentResourceSet作为的ResourceSet = CurrentResourceManager.GetResourceSet(_
CultureInfo.CurrentCulture,真,真)
 

当我尝试使用RESGEN它抱怨我的文件扩展

  

C:...> RESGEN image.bmp myfile.Resource.resource源

     

RESGEN:错误RG0000:名为image.bmp该文件没有一个已知的扩展名。受管资源文件必须结束的.resx,.txt或的.resources。

在手册它规定使用 RESXGEN 的图像,但我不相信,可在VS2008。我卡住了。

更新:发现这一点:的http:// MSDN。 microsoft.com/en-us/library/ekyft91f(VS.80).aspx 说明如何写的ResX文件。似乎是一个重复的过程。我不知道他们为什么不包括使用Visual Studio工具来创建它。

我试图使用ResourceWriter的例子​​。 RESGEN吐得在使用微软提供ResourceWriter类。

解决方案

一个视觉工作室的Resx的简化版本生成的文件。我已删除的公共令牌和架构映射。纲要映射为创建/修改这些文件时,为您提供帮助。为演示和简单起见,我已经剥离出来。

 < XML版本=1.0编码=UTF-8&GT?;
<根>
  < resheader名=resmimetype>
    <价值>文字/微软RESX< /值GT;
  < / resheader>
  < resheader NAME =版本>
    <价值> 2.0< /值GT;
  < / resheader>
  < resheader名=读者>
    <价值> System.Resources.ResXResourceReader,System.Windows.Forms的,版本= 2.0.0.0,文化=中性< /值GT;
  < / resheader>
  < resheader名=作家>
    <价值> System.Resources.ResXResourceWriter,System.Windows.Forms的,版本= 2.0.0.0,文化=中性< /值GT;
  < / resheader>
  <装配别名为System.Windows.Forms的NAME =System.Windows.Forms的,版本= 2.0.0.0,文化=中性/>
  <数据NAME =MyLibrary的TYPE =System.Resources.ResXFileRef,System.Windows.Forms的>
    <价值>资源\ mylibrary.dll; System.Byte [],mscorlib程序,版本= 2.0.0.0,文化=中性< /值GT;
  < /数据>
  <数据NAME =MYTEXTTYPE =System.Resources.ResXFileRef,System.Windows.Forms的>
    <价值>资源\ mytext.txt; System.String,mscorlib程序,版本= 2.0.0.0,文化=中性< /值GT;
  < /数据>
< /根>
 

有关每种类型的字节或字符串包括以下数据。其中名称是您​​想通过访问它的名称和值eitehr相对或硬路径:

 <数据NAME =MYTEXTTYPE =System.Resources.ResXFileRef,System.Windows.Forms的>
    <价值>资源\ mytext.txt; System.String,mscorlib程序,版本= 2.0.0.0,文化=中性< /值GT;
<数据>
 

编译您的资源,以一个单一的资源管理器文件,并在项目中包含

  RESGEN /编译myrex.resx

VBC /吨:EXE myprogram.vb /res:myresx.resource
CSC / T:EXE myprogram.cs /res:myresx.resource
 

您必须在您的程序访问这些文件创建一个资源管理器。如果你想有一个强类型的资源管理器,你必须从你的项目中按照Resource.Designer类,并修改该文件。如果你想要一个简单的资源管理器直接使用的GetString或GetBytes会。

 昏暗RM作为新的ResourceManager(RMC,[大会] .GetExecutingAssembly())
天= rm.GetString(MYTEXT)
O = rm.GetObject(mylibrary.dll)
 

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.

Can someone please explain to me how to generate a resource manager similar to that of the VS IDE.

For example if I compile with VBC from the commandline I can see all my resource files.

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

res2

If I compile with the VS IDE I only see:

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?

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

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

ResGen : error RG0000: The file named "image.bmp" does not have a known extension. Managed resource files must end in .ResX, .txt, or .resources.

In the Manual it states to use RESXGEN for images, but I do not believe that is available in 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. Seems like a repeatable process. I am not sure why they would not include a utility with visual studio to create it.

I attempted to use the example of the ResourceWriter. Resgen puked upon using the MS Provided ResourceWriter Class.

解决方案

Simplified version of a Visual Studios Resx generated file. 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:

<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. If you want a simple resource manager simply use GetString or GetBytes.

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