在没有程序集前缀的 .NET 程序集中嵌入资源?

发布于 2024-08-25 06:52:30 字数 236 浏览 5 评论 0原文

当您使用 Visual Studio 将资源嵌入到 .NET 程序集中时,它会以程序集名称为前缀。但是,程序集可以嵌入不以程序集名称为前缀的资源。我能看到做到这一点的唯一方法是使用 ILDASM 拆卸程序集,然后重新组装它,添加新资源 - 这可行,但是......我真的需要完成这句话吗?

(桌面 .NET Framework 3.5、Visual Studio 2008 SP1、C#、Windows 7 Enterprise x64。)

When you embed a resource into a .NET assembly using Visual Studio, it is prefixed with the assembly name. However, assemblies can have embedded resources that are not assembly-name-prefixed. The only way I can see to do this is to disassemble the assembly using ILDASM, then re-assemble it, adding the new resource -- which works, but... do I really need to finish that sentence?

(Desktop .NET Framework 3.5, Visual Studio 2008 SP1, C#, Windows 7 Enterprise x64.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不语却知心 2024-09-01 06:52:30

其实有办法,但是需要手动编辑.csproj。

在 .csproj 文件中,找到 EmbeddedResource 元素,如下所示:

<EmbeddedResource Include="Resources\MyImage.png" />

添加 LogicalName 子元素,如下所示。

<EmbeddedResource Include="Resources\MyImage.png">
  <LogicalName>MyImage.png</LogicalName>
</EmbeddedResource>

进行此更改后,可以将资源获取为“MyImage.png” - 省略默认命名空间和文件夹名称。

看来此功能自 2005 年起

Actually, there is a way, but you need to edit the .csproj manually.

In the .csproj file, find the EmbeddedResource element, which will look like the following:

<EmbeddedResource Include="Resources\MyImage.png" />

Add a LogicalName child element, as shown below.

<EmbeddedResource Include="Resources\MyImage.png">
  <LogicalName>MyImage.png</LogicalName>
</EmbeddedResource>

After making this change, the resource can be fetched as "MyImage.png" - the default namespace and folder name are omitted.

It looks like this capability has been available since 2005.

何以笙箫默 2024-09-01 06:52:30

不是程序集名称 - 命名空间;)默认命名空间,IIRC。前缀是默认命名空间;)

Not assembly name - namespace ;) Default namespace, IIRC. The prefix is the default namespace ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文