Visual studio 2017 : nesting files in a class library project

后端 未结 2 517
日久生厌
日久生厌 2021-01-13 20:01

In web projects you have the option of nesting files

 + startup.cs
   +--startup.internals.cs
   +--startup.configuration.cs

Is there any

相关标签:
2条回答
  • 2021-01-13 20:16

    I believe you can do this in your csproj file.

    <Compile Include="startup.cs">
        <DependentUpon>startup.internals.xaml</DependentUpon>
        <DependentUpon>startup.configureation.xaml</DependentUpon>
    </Compile>
    
    0 讨论(0)
  • 2021-01-13 20:35

    To answer your Updates : Partially solved:

    Something similar to this issue. DependentUpon is the correct element to use to achieve the nesting that you want.

    But, your value cannot be expression that includes wildcards. It must be a single file that is under the same folder or a sub-folder. If your file exists in a sub-folder, you must specify the file via a relative path. So the content of your ItemGroup should be like this:

    <Compile Include="Folder_A\Folder_A1\startup.cs" />
    <Compile Include="Folder_A\Folder_A1\startup.configuration.cs">
      <DependentUpon>startup.cs</DependentUpon>
    </Compile>
    <Compile Include="Folder_A\Folder_A1\startup.internals.cs">
      <DependentUpon>startup.cs</DependentUpon>
    </Compile>
    

    And after my check, I think you need to use the Include attribute instead of Update if you are building a .NET FX class library project.

    Update: The Update attribute is available only for .NET Core projects according to this doc.

    And if in a .NET Core project, like what you indicated in a comment, maybe Update is more suitable:

    <Compile Update="Folder_A\Folder_A1\startup.internals.cs">
      <DependentUpon>startup.cs</DependentUpon>
    </Compile>
    
    0 讨论(0)
提交回复
热议问题