代码之家  ›  专栏  ›  技术社区  ›  reinierpost

如何为子目录中的C#文件编写DependentUpon子句?

  •  8
  • reinierpost  · 技术社区  · 11 年前

    我们正在尝试使用C#应用程序进行编译和运行 二者都

    • Windows上的Visual Studio 10(带Microsoft编译器),以及
    • 在Linux上使用gmcs进行MonoDevelop

    然而 .csproj 文件(适用于Visual Studio):

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

    在使用MonoDevelop/gmc之前,必须按照以下方式进行更改 (如果不是,在运行时,resources.GetObject()将抛出 MissingManifestResourceException ):

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

    如何将其改写为双方都能接受的形式? (除了删除 DependentUpon 元素。)

    1 回复  |  直到 11 年前
        1
  •  4
  •   Community CDub    8 年前

    与此同时,我研究了几种应对这种情况的方法。

    例如, it is apparently possible 要添加 Condition 具有值的属性 $(VisualStudioVersion) != '' 以便使它们以是否正在使用Visual Studio为条件。

    然而,一时兴起(阅读后 this answer )我尝试了完全不同的方法:我替换了嵌套的命名空间

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

    使用虚线命名空间表示法:

    namespace Baz.Bar
    {
        [...]
    }
    

    这个 MissingManifestResourceException 已不复存在,即使有原始版本 DependentUpon 条款

    问题解决了,但我不知道为什么。