2010-04-22 17 views

Respuesta

17

Puede Add existing item un .resx archivo a un proyecto F #, debería obtener automáticamente un BuildAction de EmbeddedResource y funcionar. Las herramientas de VS aquí no son tan buenas como las demás, pero MSBuild hace todo el trabajo pesado, por lo que solo se trata de obtener el fragmento correcto de XML en el archivo .fsproj.

10

Estoy usando un .resx en un proyecto F # 2.0. Siéntete libre de echarle un vistazo y espero que te ayude. No hay grandes batidos, pero aquí es lo que vale.

http://github.com/OnorioCatenacci/ExtendedSearch

EDIT: Por lo que vale la pena, aquí está la parte pertinente del archivo fsproj

<ItemGroup> 
    <Compile Include="assemblyinfo.ExtendedSearch.exe.fs" /> 
    <Compile Include="ExtendedSearch.fs" /> 
    <EmbeddedResource Include="ExtendedSearch.resx" /> 
    </ItemGroup> 

Y aquí está ExtendedSearch.resx:

<?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, ...</value> 
    </resheader> 
    <resheader name="writer"> 
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, ...</value> 
    </resheader> 
    <!-- 
    Microsoft ResX Schema 

    Version 2.0 

    The primary goals of this format is to allow a simple XML format 
    that is mostly human readable. The generation and parsing of the 
    various data types are done through the TypeConverter classes 
    associated with the data types. 

    Example: 

    ... ado.net/XML headers & schema ... 
    <resheader name="resmimetype">text/microsoft-resx</resheader> 
    <resheader name="version">2.0</resheader> 
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> 
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> 
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> 
    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> 
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> 
     <value>[base64 mime encoded serialized .NET Framework object]</value> 
    </data> 
    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> 
     <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> 
     <comment>This is a comment</comment> 
    </data> 

    There are any number of "resheader" rows that contain simple 
    name/value pairs. 

    Each data row contains a name, and value. The row also contains a 
    type or mimetype. Type corresponds to a .NET class that support 
    text/value conversion through the TypeConverter architecture. 
    Classes that don't support this are serialized and stored with the 
    mimetype set. 

    The mimetype is used for serialized objects, and tells the 
    ResXResourceReader how to depersist the object. This is currently not 
    extensible. For a given mimetype the value must be set accordingly: 

    Note - application/x-microsoft.net.object.binary.base64 is the format 
    that the ResXResourceWriter will generate, however the reader can 
    read any of the formats listed below. 

    mimetype: application/x-microsoft.net.object.binary.base64 
    value : The object must be serialized with 
      : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter 
      : and then encoded with base64 encoding. 

    mimetype: application/x-microsoft.net.object.soap.base64 
    value : The object must be serialized with 
      : System.Runtime.Serialization.Formatters.Soap.SoapFormatter 
      : and then encoded with base64 encoding. 

    mimetype: application/x-microsoft.net.object.bytearray.base64 
    value : The object must be serialized into a byte array 
      : using a System.ComponentModel.TypeConverter 
      : and then encoded with base64 encoding. 
    --> 
    <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> 
    <xsd:element name="root" msdata:IsDataSet="true"> 
     <xsd:complexType> 
     <xsd:choice maxOccurs="unbounded"> 
      <xsd:element name="metadata"> 
      <xsd:complexType> 
       <xsd:sequence> 
       <xsd:element name="value" type="xsd:string" minOccurs="0" /> 
       </xsd:sequence> 
       <xsd:attribute name="name" use="required" type="xsd:string" /> 
       <xsd:attribute name="type" type="xsd:string" /> 
       <xsd:attribute name="mimetype" type="xsd:string" /> 
       <xsd:attribute ref="xml:space" /> 
      </xsd:complexType> 
      </xsd:element> 
      <xsd:element name="assembly"> 
      <xsd:complexType> 
       <xsd:attribute name="alias" type="xsd:string" /> 
       <xsd:attribute name="name" type="xsd:string" /> 
      </xsd:complexType> 
      </xsd:element> 
      <xsd:element name="data"> 
      <xsd:complexType> 
       <xsd:sequence> 
       <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> 
       <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> 
       </xsd:sequence> 
       <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> 
       <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> 
       <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> 
       <xsd:attribute ref="xml:space" /> 
      </xsd:complexType> 
      </xsd:element> 
      <xsd:element name="resheader"> 
      <xsd:complexType> 
       <xsd:sequence> 
       <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> 
       </xsd:sequence> 
       <xsd:attribute name="name" type="xsd:string" use="required" /> 
      </xsd:complexType> 
      </xsd:element> 
     </xsd:choice> 
     </xsd:complexType> 
    </xsd:element> 
    </xsd:schema> 
    <data name = "AppDisplayName"> 
    <value>Extended Search</value> 
    </data> 
    <data name="FilePathSpecLabel"> 
    <value>Base File Path:</value> 
    </data> 
    <data name="FilePathSpecDefault"> 
    <value>C:\</value> 
    </data> 
    <data name ="SelectDirButtonLabel"> 
    <value>. . .</value> 
    </data> 
    <data name="FileNameSpecLabel"> 
    <value>File Name Spec:</value> 
    </data> 
    <data name="FileNameSpecDefault"> 
    <value>*.dll</value> 
    </data> 
    <data name="RecurseIntoSubdirsLabel"> 
    <value>Recurse Into Subdirectories</value> 
    </data> 
    <data name ="MajorVerDefault"> 
    <value>1</value> 
    </data> 
    <data name="MinorVerDefault"> 
    <value>0</value> 
    </data> 
    <data name="RevisionVerDefault"> 
    <value>0</value> 
    </data> 
    <data name="BuildVerDefault"> 
    <value>0</value> 
    </data> 
    <data name="VersionLabel"> 
    <value>File &amp;Version:</value> 
    </data> 
    <data name="SearchButtonCaption"> 
    <value>&amp;Search</value> 
    </data> 
    <data name="CancelButtonCaption"> 
    <value>&amp;Cancel</value> 
    </data> 
</root> 

espero que esto elimina cualquier futuro problemas con personas que no pueden encontrar esto en GitHub.

+0

Gracias, me he ido por un camino similar, la mano de codificación de un envoltorio de administrador de recursos. Ahora estoy preguntando si va a la localización funcionará ... –

+0

Me interesaría saber si la localización funciona. He utilizado principalmente la causa Resx quería refrescarme la memoria - habilidades de mi .Net de codificación son un poco oxidado. –

+0

me ha dado un error 404, siguiendo el enlace a github :( – Joh

6

Aquí hay otra manera. Aunque sé que es demasiado tarde para la pregunta original, espero que ayude a otros.

  1. Crea un archivo de texto limpio con un formato de nombre = valor, un par de clave/valor por línea. En un archivo llamado "strings.txt", escribe

    name1=hello 
    name2=world 
    
  2. Crear un archivo de recursos utilizando Resgen.exe que actúe en su archivo de texto desde el Paso 1. Usted puede aprender sobre ResGen en http://msdn.microsoft.com/en-us/library/ccec7sz1%28v=vs.80%29.aspx. ResGen creará un archivo binario CLR llamado "strings.resources". Coloque este archivo de recursos donde su compilador pueda encontrarlo.

  3. Agregue "--resource: strings.resources" como una opción del compilador. Hice esto desde el cuadro de texto "Otros indicadores" en las propiedades de compilación. Puede encontrar más información en http://msdn.microsoft.com/en-us/library/dd233171.aspx

  4. Escriba lo siguiente en su # proyecto F

    open System.Resources 
    let res = ResourceManager("strings", System.Reflection.Assembly.GetExecutingAssembly()) 
    res.GetString("name1") + res.GetString("name2") |> printfn "%s" 
    
4

Para agregar un recurso a un proyecto de F # existente, por @ "Onorio Catenacci" GitHub Linke por encima de ...

  1. Crear un archivo de texto y llenarlo con el contenido a continuación a continuación, guardar y cerrar.
  2. Cambiar el nombre de esta extensión de archivo de texto a .resx (archivo de recursos XML)
  3. actualización de la Build Action a EmbeddedResource
  4. El archivo ahora debe abrir correctamente en el editor de recursos VS que le permite editar su contenido.

.resx plantilla de archivo:

<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, ...</value></resheader> 
     <resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, ...</value></resheader> 
     <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
     <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> 
     <xsd:element name="root" msdata:IsDataSet="true"> 
      <xsd:complexType> 
      <xsd:choice maxOccurs="unbounded"> 
       <xsd:element name="metadata"> 
       <xsd:complexType> 
        <xsd:sequence> 
        <xsd:element name="value" type="xsd:string" minOccurs="0" /> 
        </xsd:sequence> 
        <xsd:attribute name="name" use="required" type="xsd:string" /> 
        <xsd:attribute name="type" type="xsd:string" /> 
        <xsd:attribute name="mimetype" type="xsd:string" /> 
        <xsd:attribute ref="xml:space" /> 
       </xsd:complexType> 
       </xsd:element> 
       <xsd:element name="assembly"> 
       <xsd:complexType> 
        <xsd:attribute name="alias" type="xsd:string" /> 
        <xsd:attribute name="name" type="xsd:string" /> 
       </xsd:complexType> 
       </xsd:element> 
       <xsd:element name="data"> 
       <xsd:complexType> 
        <xsd:sequence> 
        <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> 
        <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> 
        </xsd:sequence> 
        <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> 
        <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> 
        <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> 
        <xsd:attribute ref="xml:space" /> 
       </xsd:complexType> 
       </xsd:element> 
       <xsd:element name="resheader"> 
       <xsd:complexType> 
        <xsd:sequence> 
        <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> 
        </xsd:sequence> 
        <xsd:attribute name="name" type="xsd:string" use="required" /> 
       </xsd:complexType> 
       </xsd:element> 
      </xsd:choice> 
      </xsd:complexType> 
     </xsd:element> 
     </xsd:schema> 
    </root> 
Cuestiones relacionadas