Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to nest files by path segment in VS 2017 for ASP.NET Core project

I am trying to nest files by pathSegment in Visual Studio 2017 for ASP.NET Core project.

I added .filenesting.json file to solution folder with content:

{
    "help": "https://go.microsoft.com/fwlink/?linkid=866610",
    "root": true,   //Also tried with false

    "dependentFileProviders": {
        "add": {
            "pathSegment": {}
        }
    }
}

but it's not working even when restarting VS. I think it should work, based on this documentation.

Not sure if file nesting should be enabled or disabled.
Problem is I can not see solution settings in dropdown:

screenshot

but it is under edit:

screenshot 2

I also tried with custom setting (not solution) and it also doesn't work. What did I miss?

like image 647
Makla Avatar asked Sep 26 '18 06:09

Makla


People also ask

How do I nest files in Visual Studio?

The precedence for merging file nesting settings is: Visual Studio > Solution > Project. You can tell Visual Studio to ignore solution-specific and project-specific settings, even if the files exist on disk, by enabling the option Ignore solution and project settings under Tools > Options > ASP.NET Core > File Nesting.

How do I nest in Vscode?

After you update VS Code to v1. 64, file nesting is not enabled by default. Go ahead and do it by toggling the “File Nesting: Enabled” setting. If you do it while you have a project open, you might notice that the files package-lock.


1 Answers

I think the documentation is wrong here - that screenshot is missing the actual rules. I dug into it for Stack Overflow and hit the same thing...here's what actually works for your case in .filenesting.json:

{
  "help": "https://go.microsoft.com/fwlink/?linkid=866610",
  "root": true,
  "dependentFileProviders": {
    "add": {
      "pathSegment": {
        "add": {
          "Help.*": [ ".cs" ]
        }
      }
    }
  }
}

The only important diff (AFAIK) is the actual rule "add" itself.

like image 168
Nick Craver Avatar answered Sep 25 '22 14:09

Nick Craver