5

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.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Robert Fraser
  • 10,649
  • 8
  • 69
  • 93

2 Answers2

10

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.

Doug
  • 483
  • 4
  • 12
0

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

TomTom
  • 61,059
  • 10
  • 88
  • 148
  • Okay, thanks.... in that case, is there a way (other than removing the default namespace) to prevent that behavior? – Robert Fraser Mar 16 '10 at 12:14
  • 2
    No other way. Removing the default namespace is not so bad, and will have no effect on the rest of your existing code that already has a namespace surrounding it. Although it will affect anything that creates a URI that references anything in your app that isn't explicitly namespaced. – slugster Mar 16 '10 at 12:25
  • @Will - I'm not actually accessing the resource from within the assembly; the assembly is being processed by a separate tool that requires the resource have a specific name. – Robert Fraser Mar 16 '10 at 12:27
  • @slugster - It has an effect on ReSharper :-(. Ah well, thanks – Robert Fraser Mar 16 '10 at 12:27