How To: Change the name of embedded .resources

Another interesting question came across the internal Visual Studio conversion mailing list yesterday:

Say I have assembly foo.dll, and in .csproj file I have

<ItemGroup>
<EmbeddedResource Include="bar.resx" />
</ItemGroup>

Then, bar.resx will be built into foo.bar.resources in foo.dll. However, say I want notfoo.bar.resources. What’s the best way to do it?

The answer, it turns out, is a neat example of how MSBuild supports metadata on individual items. The metadata on an item travels with it through the build process, and tasks can use that metadata as necessary. In this case, the task that generates the resource is GenerateResourceTask, and it knows about the <LogicalName> metadata. Use the element like this:

<ItemGroup>
<EmbeddedResource Include="bar.resx">
<LogicalName>notfoo.bar.resources</LogicalName>
</EmbeddedResource>
</ItemGroup>

This will cause bar.resx to get generated into the notfoo.bar.resources file. For more details, check out the article on our wiki about GenerateResourceTask.

[ Author: Neil Enns ]