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

When you embed a resource in a .NET assembly using Visual Studio, it has a prefix of the assembly name. However, assemblies may have embedded resources that are not prefixes with assembly name. The only way I can do this is to parse the assembly using ILDASM, then reassemble it by adding a new resource - which works, but ... do I really need to finish this sentence?

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

+4
source share
2 answers

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

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

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

Add a child LogicalName, as shown below.

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

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

It looks like this feature has been available since 2005 .

+7
source

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

+1
source

Source: https://habr.com/ru/post/1304251/


All Articles