14

How do I manage/control the nesting of TypeScript files in Visual Studio?

I am getting a mix of nested & not nested files, I'm not sure how/why, as shown below.

Nested & non-nested files

Sean
  • 14,359
  • 13
  • 74
  • 124
  • Have you manually added your JavaScript files? Normally they are not included in the project as they are build artefacts like DLLs. – Fenton Jul 28 '15 at 08:10
  • @SteveFenton I think I must have when recreating the project. Makes sense. How about getting the typesript to nest under the html, though - any ideas? – Sean Jul 28 '15 at 12:09

1 Answers1

13

The default for JavaScript files in a TypeScript project is to exclude them rather than nest them - but there are several ways you can nest them if you prefer.

You can hack the registry... or hand-crank your project file's XML... but the easier option is to let Mads Kristensen do it for you with his File Nesting Extension.

You right-click on the .js file and select "Nest File". It will then show a dialog for you to choose the file to nest under (and usually guesses the right answer).

Fenton
  • 241,084
  • 71
  • 387
  • 401
  • The File Nesting Extension does not work ASP.NET 5 Projects. Is there also a possiblity for file nesting? – Matthias Mar 04 '16 at 13:40
  • 7
    So, how can I ***prevent*** Visual Studio from nesting files? – felixfbecker Apr 02 '16 at 22:59
  • @felixfbecker the same plugin allows you to manually un-nest files... it simply changes the entries in the project file (which would be a real pain to edit manually). This would require you too select the file and "un-nest" manually though - it doesn't apply automatically. In most cases, nesting is preferred, especially where the nested files are ones you wouldn't hand-edit (like files generated by the compiler or other code generation tools). – Fenton Apr 03 '16 at 13:40
  • 2
    @Sohnee Without any plugin installed, Visual Studio nests all JS files under HTML files with the same name. Even the plugin doesn't allow me to unnest them. It is extremely annoying: http://s21.postimg.org/lssu76vnb/Unbenannt.png Any idea how I can prevent that? – felixfbecker Apr 03 '16 at 16:38
  • I've never come across that - my folder structure has all my JS files in a separate folder and that doesn't happen to me - that would be a pretty major change for you though (although you could still use a convention to maintain the link between script paths and HTML paths). – Fenton Apr 03 '16 at 16:45