为什么我的resx文件为升级的NetStandard Project生成System.Drawing.Icon

时间:2018-01-02 21:34:43

标签: c# .net-standard .net-standard-2.0

我通过创建新的项目文件并将目标框架切换到netstandard20来修改现有的.net 461项目以使用netstandard 2.0

除了包含图标的资源文件外,一切似乎都有效。我将以下内容添加到我的csproj文件中以确保生成运行:

  <ItemGroup>
    <Compile Update="Properties\Resources.Designer.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Update="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>

但是,每次生成Designer.cs文件时,它都会引用System.Drawing.Icon,这对.Net标准项目无效。如何配置设计器文件以正确使用System.Byte[]作为我的图标资源?

1 个答案:

答案 0 :(得分:0)

Resource.resx文件具有用于XML中嵌入的生成的类型名称。您需要使用文本编辑器修改此文件,并将其指向使用System.byte[]而不是System.Drawing.Icon

例如,您的resource.resx文件中可能包含以下条目:

<data name="FooBar" type="System.Resources.ResXFileRef, System.Windows.Forms">
  <value>..\Resources\FooBar.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

您可以将输出类型更新为字节数组,如下所示:

<data name="FooBar" type="System.Resources.ResXFileRef, System.Windows.Forms">
  <value>..\Resources\FooBar.ico;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
相关问题