9

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?

3
  • 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. Commented Mar 3, 2014 at 9:40
  • Hi @JotaBe I have now ammended....apologies for not being clearer... Commented Mar 4, 2014 at 3:53
  • 2
    Glad I'm not the only one who got annoyed by this. Commented Mar 19, 2014 at 21:39

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.