开发者

Embed resource in a .NET assembly without an assembly prefix?

开发者 https://www.devze.com 2022-12-22 21:46 出处:网络
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 assemb开发者_如何学Cly-name-pref

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 assemb开发者_如何学Cly-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.)


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号