How do I override Visual Studio's resource naming rules, to force resources to be named whatever I want?
If you're not happy with the
VisualStudioResourceNamingRules, and you want to choose your own manifest resource name for one or more of your resources, you have a couple of options which are described below. However, a word of warning ... if you change the resource naming rules for VS projects, then you may get strange behaviors when loading the project into the VS IDE. In particular, the IDE has assumptions about the naming scheme for a form's resources, and if you change the naming scheme, the forms designer will likely get confused and generate the wrong code.
Option 1: Override the ""CreateManifestResourceNames"" target
""There is a target defined in Microsoft.<language>.targets (where <language> is
CSharp/VisualBasic/VisualJSharp) called
CreateManifestResourceNames. This is the target that is responsible for taking the list of "EmbeddedResource" items from the project, and computing the manifest resource name for each. By overriding this target, you can choose your own algorithm for computing the manifest resource name. Simply add the overriding target in your project file after the <Import> as follows:""
<Project ...>
...
<Import Project="..."/>
...
<Target Name="CreateManifestResourceNames">
...
...
</Target>
</Project>
As of Beta 1, the requirements for this target, in order to correctly fit into the rest of the build process, are:
- ""Take as input @(ResxWithNoCulture), and produce @(ManifestResourceWithNoCultureName)""
- ""Take as input @(ResxWithCulture), and produce @(ManifestResourceWithCultureName)""
- ""Take as input @(NonResxWithNoCulture), and produce @(ManifestNonResxWithNoCulture)""
- ""Take as input @(NonResxWithCulture), and produce @(ManifestNonResxWithCulture)""
We may consider simplifying this for Beta 2.
Option 2: Add a <LogicalName> metadata to your ""EmbeddedResource"" items
""To change the manifest resource name for individual resources in your project file, you can simply add a piece of additional metadata called
LogicalName to the
EmbeddedResource item. Here's an example:""
<Project ...>
...
<ItemGroup> <EmbeddedResource Include="foo.resx">
<LogicalName>bing.bong.bang.resources</LogicalName> </EmbeddedResource> <ItemGroup>
</Project>
Note: ""This will only Beta 1, and beyond. This will not work with Pre-Beta 1 bits.""