首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何管理F#项目中的资源?

如何管理F#项目中的资源?
EN

Stack Overflow用户
提问于 2010-04-22 17:03:38
回答 4查看 3.9K关注 0票数 21

我可以在F# 2.0项目中使用.resx文件吗?

如果是这样,我该如何添加,然后使用这些资源。

提前谢谢。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-04-22 22:41:55

你可以将一个.resx文件Add existing item到一个F#项目中,它应该会自动获得一个BuildAction of EmbeddedResource并工作。这里的VS工具还不如其他语言好,但是MSBuild做了所有繁重的工作,所以问题只是把正确的XML片段放到.fsproj文件中即可。

票数 17
EN

Stack Overflow用户

发布于 2010-04-22 20:14:57

我在一个F# 2.0项目中使用.resx。请随意看一下,我希望它能对你有所帮助。没有很大的震撼,但这是值得的。

http://github.com/OnorioCatenacci/ExtendedSearch

编辑:这里是fsproj文件的相关部分

代码语言:javascript
运行
复制
  <ItemGroup>
    <Compile Include="assemblyinfo.ExtendedSearch.exe.fs" />
    <Compile Include="ExtendedSearch.fs" />
    <EmbeddedResource Include="ExtendedSearch.resx" />
  </ItemGroup>

下面是ExtendedSearch.resx:

代码语言:javascript
运行
复制
<?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>

我希望这能消除人们在GitHub上找不到它的任何未来问题。

票数 10
EN

Stack Overflow用户

发布于 2012-09-20 05:18:51

这是另一种方法。虽然我知道对最初的问题来说太晚了,但我希望它能帮助其他人。

  1. 创建一个name=value格式的纯文本文件,每行一个键/值对。在名为"strings.txt“的文件中,编写

在步骤1中,使用ResGen.exe对文本文件执行name2=world

  • Create操作来name1=hello资源文件。您可以在http://msdn.microsoft.com/en-us/library/ccec7sz1%28v=vs.80%29.aspx上了解有关ResGen的信息。ResGen将创建一个名为"strings.resources“的CLR二进制文件。把这个资源文件放在你的编译器能找到的地方。

  • 添加“-- resource :字符串资源”作为编译器选项。我在构建属性中的“其他标志”文本框中完成了此操作。您可以在http://msdn.microsoft.com/en-us/library/dd233171.aspx

  • 上找到更多信息,请在F#项目中编写以下内容

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

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2689446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档