8

Every time I click to create a view or partial file Visual Studio automatically creates an _Layout.cshtml and an _ViewStart.cshtml file.

I do not want my project to create a _ViewStart.cshtml or a _Layout.cshtml file.

However it does. I looked at modifying the t4 code template but that seems like it is more to do with code generation rather than file generation.

Is there anyway to stop this behaviour?

Exitos
  • 29,230
  • 38
  • 123
  • 178
  • Please, review your question. It doesn't make sense: '... when I create an _Partial.cshtml I do not want my project to create a ... _Partial.cshtml file.'. I can't understand what you mean, what you are trying to do, how you're doing it, what you want to get and what you are getting... Please, try to explain it in a better way. – JotaBe Mar 03 '14 at 09:40
  • Hi @JotaBe I have now ammended....apologies for not being clearer... – Exitos Mar 04 '14 at 03:53
  • 2
    Glad I'm not the only one who got annoyed by this. – Maksim Vi. Mar 19 '14 at 21:39

2 Answers2

4

In short: You can not stop it, it is "hardcoded".

For more details: it's a "Convention over configuration" principle. The whole idea is to have framework preparing as much as possible in order to speed-up development process. You still have a flexibility to remove line:

Layout = "~/Views/Shared/_Layout.cshtml";

from you view and set to to:

Layout = null;

BTW, there is similar discussion here, it's possible duplicate subject.

Community
  • 1
  • 1
Kenan Zahirovic
  • 1,587
  • 14
  • 24
2

This question was partially answered here. The main idea is if you deleted _Layout.cshtml and _ViewStart.cshtml files, and then you create a new view and the option Use a layout page is checked, the studio will try to find a default layout, i.e., _Layout.cshtml and since it is not present in your project it will create a new one automatically along with_ViewStart.cshtml file. So to avoid this automatic creation make sure to uncheck Use a layout page every time you create a new view.

Mykhailo Seniutovych
  • 3,527
  • 4
  • 28
  • 50