共用方式為


How to embed resources using a different namespace in a C# project

Have you ever wanted to embed a resource in your managed assembly but didn't like the default name that Visual Studio decided to give it? For example, if you have a C# project with the RootNamespace="MyCompany.MyNamespace" and have a bitmap called "MyBitmap.bmp" in your C# project, then when the project compiles, you end up with "MyCompany.MyNamespace.MyBitmap.bmp" in your assembly resources. Well, what if you wanted it named just "MyBitmap.bmp"?

The trick is to manually tweak your .csproj file and add the <LogicalName> element as a child of the <EmbeddedResource> element:

 <EmbeddedResource Include="MyBitmap.bmp">
  <LogicalName>MyBitmap.bmp</LogicalName>
</EmbeddedResource>

Now your resource will be embedded with the name you give it instead of having it autogenerated.