.Net Standard 项目中的资源未添加到 DLL 中

问题描述 投票:0回答:2

添加到 .NET 标准项目的资源不会编译到 DLL 中。

我正在将 .NET Framework 项目移植到 .NET Standard。我的原始项目有一些资源,标记为“构建操作:资源”,这些资源正在被其他程序集消耗。

.NET 标准项目文件。


  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup> *** not sure why this is added by VS2019 **
    <None Remove="Resources\ErrorLarge.png" />
  </ItemGroup>

  <ItemGroup>
    <Resource Include="Resources\ErrorLarge.png" />
  </ItemGroup>

</Project>

DLL 内容和大小不会随着“Build Action”属性从“None”更改为“Resource”而改变。当然,我的消费者程序集会返回

IOException: Cannot locate resource 'resources/errorlarge.png'.
错误。

VS2019 - 16.2.4

c# visual-studio .net-standard .net-standard-2.0
2个回答
0
投票

听起来您想要在 CSProj 文件中使用

EmbeddedResource
,而不是
Resource

这似乎对于描述添加和读取它们很有用


0
投票

我现在在 .Net 7 项目中遇到了完全相同的问题。显然,资源仅在 WPF 项目中编译到 DLL 中。

我很想了解更多相关信息,但让它发挥作用的行是 csproj 文件中的以下内容:

<PropertyGroup>
    <TargetFramework>net7.0-windows</TargetFramework>
    <ImplicitUsings>disable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <OutputPath>..\bin</OutputPath>
    <GenerateDocumentationFile>True</GenerateDocumentationFile>
    <GenerateAssemblyInfo>False</GenerateAssemblyInfo>
    <IsPackable>False</IsPackable>

    // this line here
    <UseWPF>True</UseWPF>
</PropertyGroup>

将项目设置为使用 WPF 还需要我为目标框架指定平台,因此我将目标从

net7.0
更改为
net7.0-windows

© www.soinside.com 2019 - 2024. All rights reserved.