A Really Empty ASP.NET MVC 3 Project Template

asp.net, asp.net mvc 0 comments suggest edit

In the ASP.NET MVC 3 Uservoice site, one of the most voted up items is a suggestion to include an empty project template. No, a really empty project template.

You see, ASP.NET MVC 3 includes an “empty” project template, but it’s not empty enough for many people. So in this post, I’ll give you a much emptier one. It’s not completely empty. If you really wanted it completely empty, just choose the ASP.NET Empty Web Application template.

The Results

I’ll show you the results first, and then talk about how I made it. After installing my project template, every time you create a new ASP.NET MVC 3 project, you’ll see a new entry named “Really Empty”

mvc3-empty-proj-template

Select that and you end up with the following directory structure.

mvc3-proj-template-expanded

I removed just about everything. I kept the Views directory because the Web.config file that’s required is not obvious and there’s special logic related to the Views directory. I also kept the Controllers directory, since that’s where the tooling is going to put controllers anyways. I also kept the Global.asax and Web.config files which are typically necessary for an ASP.NET MVC project.

I debated removing the AssemblyInfo.cs file, but decided to trim it down and keep it.

Building Custom Project Templates

I wrote about building a custom ASP.NET MVC 3 project template a long time ago. However, I’ve improved on what I did quite a bit. Now, I have a single install.cmd file you can run and it’ll determine whether you’re on x64 or x86 and run the correct registry script. The install.cmd and uninstall.cmd batch files are there for convenience and call into a PowerShell script that does the real work.

UPDATE 1/12/2012: Thanks to Tim Heuer, we have an even better installation experience. He refactored the project to output a VSIX file. All you need to do is double click the extension file to install the project template. I’ve uploaded the extension file to GitHub here.

I tried uploading it to the gallery, but it wouldn’t let me. I’ll follow up on that.

History

If you’re wondering why the product team hasn’t included this all along, it’s for a lot of reasons. There was (at least when I was there) internal debate about how empty to make it. For example, when you create a new project with my empty template, and hit F5, you get an error. Not a great experience for most people.

Honestly, I’m all for it, but there are many other higher priority items for the team to work on. So I figured I’d do it myself and put it up on GitHub.

Installation

Installation is really simple. If you like to build things from source, grab the source from my GitHub repository and run the build.cmd batch file. Then double click the resulting VSIX file. Be sure to read the README for more details.

If you don’t yet know how to use Git to grab a repository, don’t worry, just navigate to the downloads page and download the VSIX file I’ve conveniently uploaded.

Contribute!

Hey, if you think you can help me make this better, please go fork it and send me a pull request. Let me know if I include too little or too much.

I’ve already posted a few things that could use improvement in the README. If you’d like to help make this better, consider one of the following. :)

  • Make script auto-detect whether VS is running or not and do the right thing
  • Test this on an x86 machine
  • Write an installer for this

Let me know if you find this useful.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

35 responses

  1. Avatar for Craig
    Craig January 10th, 2012

    What about a really really empty template? Here it is .

  2. Avatar for Steve Sanderson
    Steve Sanderson January 10th, 2012

    Very cool! I've been asking for this for ages :)
    All it needs is a few hints to give the developer an idea about how to get started. Could you consider adding the following?
    - A controller for handling login, registration, etc
    - An example model schema, perhaps based on EF
    - Sample unit tests
    - A folder structure for organising images
    - An abstraction over common design patterns, such as those listed in Fowler's PoEAA
    I think that's all that's really needed in the most basic cases.

  3. Avatar for haacked
    haacked January 10th, 2012

    Ha ha ha ha. You guys crack me up. :)

  4. Avatar for Restuta
    Restuta January 10th, 2012

    Thanks, I like the "really" concept. I would like to have "really shutdown" and "really reboot" on my machine also =)

  5. Avatar for Ameer
    Ameer January 10th, 2012

    Love steve's comment :). Nancyfx has a very cool strategy based on nuget where they've componentized their solution into smaller pieces. People can add basic authentication, for instance, by adding Nancy.Authentication.Basic etc. The WindowsAzure.Storage nugets do something similar and even provides samples. I wonder if coupling this "really empty" template with Nuget add-ins could be useful?

  6. Avatar for Paul Batum
    Paul Batum January 11th, 2012

    Steve's comment is hilarious :)
    I still think this template is what the actual "empty" template that ships should be..

  7. Avatar for Marvin
    Marvin January 11th, 2012

    This has nothing to do with your article but your RSS references to http://haacked.com/Default.aspx which doesn't work ;)

  8. Avatar for Göran Andersson Daum
    Göran Andersson Daum January 11th, 2012

    Good job, thanks for this.

  9. Avatar for Jonas Eriksson
    Jonas Eriksson January 11th, 2012

    Cool! Would be nice to see it being added to the VS Gallery http://visualstudiogallery.msdn.microsoft.com/

  10. Avatar for fschwiet
    fschwiet January 11th, 2012

    I lol'd. Does your non-compete allow you to school your old team so hard?

  11. Avatar for Joshua McKinney
    Joshua McKinney January 11th, 2012

    While we're on the topic is there a way of updating the normal empty template with the latest versions of Nuget packages so that I don't have to update them on each new project? Are there any cons to just updating the template verse creating a new template with these updates (like ability to install template hotfixes etc.)

  12. Avatar for Corey
    Corey January 11th, 2012

    If you want to improve the new project template, make one that pulls from a git repository instead of relying on the ones under the user profile.

  13. Avatar for AbelebA
    AbelebA January 11th, 2012

    Nice,
    I always end up deleting stuff that I'm not going to use then spend some time going through the errors and fixing them one at a time. This is a good example of KISS and YAGNI

  14. Avatar for Alex
    Alex January 11th, 2012

    Creating project... project cration failed. "Сan not find the file specified (Exeption from HRESULT: 0x80070002)"

  15. Avatar for Alex
    Alex January 11th, 2012

    When I uninstal this tamplate, all MVC 3 projects disappears from creation project menu :(

  16. Avatar for Battaile Fauber
    Battaile Fauber January 11th, 2012

    Great timing, was just talking to a friend this morning about creating something like this for my own use.
    "For example, when you create a new project with my empty template, and hit F5, you get an error."
    The default MVC3 empty project gives you a server error when you hit f5, so...

  17. Avatar for haacked
    haacked January 11th, 2012

    @Joshua you might be able to hack the normal empty project template to use the latest versions. But you'll need to do that periodically.
    @Corey LOVE that idea! That might require building an add-in. My knowledge of the internal workings of VS isn't that advanced yet, but could be a fun side project in the future.
    @Alex sorry to hear that. That first error probably indicates the file wasn't copied correctly to your project template location. Do you still have a bunch of zip files there? It's in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\CSharp\Web\1033 on my machine. Could you log an issue here: github.com/.../issues with more details. What kind of OS and VS are you running, etc.
    @Battaile well that error is a 404 due to the favicon.ico. But the browser still loads a page with useful information. In my template, you get nothing.

  18. Avatar for Battaile Fauber
    Battaile Fauber January 11th, 2012

    @Phil
    Theirs gives the exact same generic server error due to having no controller or default page as yours gives.

  19. Avatar for haacked
    haacked January 11th, 2012

    @Battaile great point! I didn't read your comment carefully. You're talking about the default MVC 3 *EMPTY* template. You are correct sir. :)

  20. Avatar for Battaile Fauber
    Battaile Fauber January 11th, 2012

    Thanks again for putting this out there. Exactly what I was looking for and its already in use!

  21. Avatar for Leyu Sisay
    Leyu Sisay January 12th, 2012

    Has nothing with this post, but the gravatar images you are displaying are size 50x50 while the CSS size is 80x80 and that's distorting the images.

  22. Avatar for Tugberk
    Tugberk January 12th, 2012

    Steve Sanderson's comment made me cry, it was awesome :D I nominate this as the innovation of 2012 for the lazy .net devs like me which has been bagging MVC team to create this but cannot do it himself.

  23. Avatar for Jawad
    Jawad January 16th, 2012

    COOL

  24. Avatar for Jason
    Jason January 17th, 2012

    Upon installing the vsix-file, I encounter a System.IO.PathTooLongException on XP SP3. The path causing the error:
    C:\Documents and Settings\jason\Local Settings\Application Data\Microsoft\VisualStudio\10.0\Extensions\Phil Haack\ReallyEmptyMvc3ProjectTemplate\3.1\ProjectTemplates\CSharp\Web\ReallyEmptyMvc3ProjectTempl...: ReallyEmptyMvcWebApplicationProjectTemplate.cshtml.vstemplate

  25. Avatar for coolguy97
    coolguy97 January 22nd, 2012

    Me too go the Same error on Windows Xp SP3 2010 VWDExpress Edition
    Log:
    Install Error : System.IO.PathTooLongException: C:\Documents and Settings\coolguy97\Local Settings\Application Data\Microsoft\VWDExpress\10.0\Extensions\Phil Haack\ReallyEmptyMvc3ProjectTemplate\3.1\ProjectTemplates\CSharp\Web\ReallyEmptyMvc3ProjectTempl...: ReallyEmptyMvcWebApplicationProjectTemplate.cshtml.vstemplate
    at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.BeginInstall(IInstallableExtension installableExtension, Boolean perMachine, AsyncOperation asyncOp)
    at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallWorker(IInstallableExtension extension, Boolean perMachine, AsyncOperation asyncOp)

  26. Avatar for haacked
    haacked January 23rd, 2012

    @coolguy97 I uploaded a new one. Try it out.

  27. Avatar for coolguy97
    coolguy97 January 28th, 2012

    Thanks Phil,It works.

  28. Avatar for Jonathan
    Jonathan January 28th, 2012

    Thanks! This has always been frustrating for me. When I say empty I don't want jquery and css and all this other crap... If I need it, I'll add it.

  29. Avatar for Lobstrosity
    Lobstrosity February 7th, 2012

    Is it possible to specify a custom icon in the .pkgdef (or elsewhere) for display in the "New ASP.NET MVC 3 Project" dialog?

  30. Avatar for Lobstrosity
    Lobstrosity February 7th, 2012

    I tried specifying the icon in the .vstemplate, hoping the new project dialog would pick up on that. But no such luck.

  31. Avatar for Adam
    Adam February 17th, 2012

    Your vsix download link 404s (extra "ProjectTemplate" in the filename). Here's the corrected vsix download link

  32. Avatar for jamshid
    jamshid March 3rd, 2012

    Hi
    How me use web semantic(rdf-owl)in your web application by asp.net mvc3 ?

  33. Avatar for Elearning
    Elearning April 19th, 2012

    I'm a noob - so pardon the question: could you explain in detail what you took out and why? An answer will give me a heads up on what everything is and what it is used for. Thanks in advance.

  34. Avatar for gerry lowry
    gerry lowry August 30th, 2012

    @ haacked
    (a) thank you, much appreciated.
    (b) a version for ASP.NET MVC 4 would be timely.
    (c) i''m guessing that Steve Sanderson is either pulling your leg or attempting to trick you into ghost writing a chapter of his next ASP.NET MVC 4 tome. regardless, imho, what would be useful would be injecting some comments to provide direction to persons new to ASP.NET MVC 3/4 ... if those comments are already present, please forgive me because this is the first time i've read *this* entry ... normally, i simply use the full template and alter/delete what i do not require.
    @ Elearning
    (d) try creating one project per ASP.NET MVC 3/4 project type and then spend as much time as you require in Solutions Explorer comparing the various generated project skeletions as well as the file internals, comparing differences and similarities ... compare also the references, et cetera ... imho, it's worth your time ... i've just started to do this myself ... there are many interesting things that you will notice. Example: ASP.NET MVC 4 adds "BundleConfig.RegisterBundles(BundleTable.Bundles);" to Application_Start() in the Basic template but not in the Empty template.
    regards ~~ gerry

  35. Avatar for Shawn Featherly
    Shawn Featherly August 14th, 2016

    I know this template and blog post is old, but I stumbled upon it. Just wanted to share this kind of "really empty" template is now part of visual studio 2015. Found this blog post on doing it for MVC5: http://www.techjunkieblog.c...