I had this cool idea. What if I could hide my NHibernate Entity.hbm.xml files behind their respective c# files in the Solution Explorer. This would tidy things up a bit as I’m getting a bit overloaded in my project at work.
It turns out that this is pretty easy to accomplish… visually. Here’s what we’re trying to accomplish:
Busting out the .csproj file I can edit the file to go from:
<ItemGroup>
<EmbeddedResource Include="Class1.hbm.xml" />
</ItemGroup>
To:
<ItemGroup>
<EmbeddedResource Include="Class1.hbm.xml">
<DependentUpon>Class1.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
I even found a macro that does it for you rather than having to hack the visual studio project file directly.
Unfortunately it suddenly broke all my unit tests. Turns out that when adding “dependent upon” it does more than just the visual but actually changes the name (and type?) of the file. Here’s what it looks like in Reflector before:

Here’s what it looks like after:

I spent an hour or so on the MSDN trying to figure out how to solve this problem, but I can’t seem to figure out how to do it. It looks like someone else had this EXACT idea and problem.
Anyone have any ideas on how to solve this?



[...] The problem: Hiding Your hbm.xml files in Visual Studio (or not) [...]
Pingback by Nesting NHibernate Mapping Files < Over It. — September 7, 2009 @ 11:07 pm