Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# web应用程序中System.Windows.Forms的资源和引用_C#_Asp.net_Resources_Resharper_Resx - Fatal编程技术网

C# web应用程序中System.Windows.Forms的资源和引用

C# web应用程序中System.Windows.Forms的资源和引用,c#,asp.net,resources,resharper,resx,C#,Asp.net,Resources,Resharper,Resx,我在ASP.NET MVC应用程序中使用了一个资源文件,当我分析项目的代码问题时,ReSharper警告我找不到System.Windows.Forms引用 我真的应该在web应用程序中引用System.Windows.Forms?为什么resx文件中需要它 在XML编辑器中打开resx文件时,我看到它引用了程序集: <resheader name="reader"> <value>System.Resources.ResXResourceReader, System

我在ASP.NET MVC应用程序中使用了一个资源文件,当我分析项目的代码问题时,ReSharper警告我找不到System.Windows.Forms引用

我真的应该在web应用程序中引用
System.Windows.Forms
?为什么resx文件中需要它

在XML编辑器中打开resx文件时,我看到它引用了程序集:

<resheader name="reader">
  <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
  <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="..." type="System.Resources.ResXFileRef, System.Windows.Forms">
  <value>...;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>

System.Resources.ResXResourceReader,System.Windows.Forms,版本=4.0.0.0,区域性=neutral,PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter,System.Windows.Forms,版本=4.0.0.0,区域性=neutral,PublicKeyToken=b77a5c561934e089
...;字符串,mscorlib,版本=4.0.0.0,区域性=neutral,PublicKeyToken=b77a5c561934e089;Windows-1252
我真的不喜欢我的web应用程序链接到任何与
System.Windows.Forms
相关的东西


为什么呢?有没有比使用这些resx文件更好的方法来管理web应用程序上的资源?

这里记录了资源文件格式:

.resources格式是一种二进制格式,允许将资源嵌入到runtime.dll或.exe中。可以使用mscorlib程序集中的类:ResourceReader和ResourceWriter来读写它

.ResX文件格式是一种基于XML的格式,可以使用System.Windows.Forms程序集中的类(ResXResourceReader和ResXResourceWriter)进行读写。 (XML模式实际上在创建新的ResX文件时放在文件中的注释中进行了解释)

资源应该嵌入到运行时可执行文件中。这就是为什么可以将.ResX格式视为.resources格式的“源文件格式”

现在,在这些格式中,您可以嵌入几乎任何类型的资源,但您必须告诉系统如何嵌入,因为存储在这些文件中的数据实际上是数据的序列化版本。 对于存储字符串,您不需要对外部反序列化器类有任何额外的依赖关系,但对于其他类型(如图标、位图等),您需要这样做。 Visual Studio编辑器使用您在文件中看到的System.Windows.Forms(反)序列化程序类。因此,您需要隐式加载System.Windows.Forms,以便反序列化这些非字符串数据

因此,如果您使用Visual Studio创建了非字符串资源,您将在System.Windows.Forms上有一个隐式引用,是的。 如果您不想这样做,请删除对这些非字符串资源的所有引用(您也可以非常轻松地手动调整文件),并使用其他方式存储资产(例如,构建操作中的“嵌入式资源”或网站中的普通“资产”目录)

注意:理论上,您也可以使用自己的类来存储自定义数据,如下所示:

以下示例显示保存在.resx文件中的Int32对象,以及 位图对象的开头,它保存二进制信息 从实际的.gif文件

<data name="i1" type="System.Int32, mscorlib">
  <value>20</value>
</data>

<data name="flag" type="System.Drawing.Bitmap, System.Drawing,   
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
mimetype="application/x-microsoft.net.object.bytearray.base64">
  <value>
    AAEAAAD/////AQAAAAAAAAAMAgAAADtTeX…
  </value>
</data>

20
aaaaad/////aqaaaaaaaagaaadtex…
据我所知,VisualStudio编辑器不支持这样的自定义类来编辑.ResX文件