reinierpost
reinierpost

Reputation: 8591

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

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

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.)

Upvotes: 8

Views: 4093

Answers (1)

reinierpost
reinierpost

Reputation: 8591

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.

Upvotes: 4

Related Questions