Tuesday, December 11, 2012

Resources in Managed C++

I was trying to write an MSBuild file for a managed C++ project, using Windows SDK 7.1 (and not Visual Studio). Mostly the supplied .targets/.props files do the hard work for you (the documentation seems rather sketchy AFAICS.) One stumbling block was the resources, I kept getting an error:
System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "controller.Form1.resources" was correctly embedded or linked into assembly "controller" at compile time, or that all the satellite assemblies required are loadable and fully signed.

It turned out that the code was looking for resources named "controller.XXX.resources" whereas ResGen was creating them "XXX.resources". The solution was to use the RootNamespace element in the MSBuild file, i.e.

<PropertyGroup>
<RootNamespace>controller</RootNamespace>
</PropertyGroup>