Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write DependentUpon clauses for C# files in subdirectories?

We are trying to get our C# application to compile and run with both

  • Visual Studio 10 (with the Microsoft compiler), on Windows, and
  • MonoDevelop with gmcs, on Linux

However, sections like this in the .csproj files (for Visual Studio):

<Compile Include="Foo\Bar.cs" />
<EmbeddedResource Include="Foo\Bar.resx">
    <DependentUpon>Bar.cs</DependentUpon>
</EmbeddedResource>

must be changed as follows before they will work with MonoDevelop/gmcs (if not, at runtime, resources.GetObject() will throw a MissingManifestResourceException):

<Compile Include="Foo\Bar.cs" />
<EmbeddedResource Include="Foo\Bar.resx">
    <DependentUpon>Foo\Bar.cs</DependentUpon>
</EmbeddedResource>

How to rewrite this into a form they will both accept? (Short of deleting the DependentUpon element, of course.)

like image 329
reinierpost Avatar asked Sep 26 '13 21:09

reinierpost


1 Answers

Meanwhile I have researched a couple of ways to deal with the situation.

For instance, it is apparently possible to add Condition attributes with the value $(VisualStudioVersion) != '' in order to make them conditional on whether Visual Studio is being used.

However, on a whim (after reading this answer) I tried something entirely different: I replaced my nested namespaces

namespace Baz
{
    namespace Bar
    {
        [...]
    }
}

with dotted namespace notation:

namespace Baz.Bar
{
    [...]
}

and voilà, the MissingManifestResourceException no longer exists, even with the original DependentUpon clause.

Problem solved, but I don't know why.

like image 188
reinierpost Avatar answered Oct 29 '22 14:10

reinierpost