A Really Empty ASP.NET MVC 3 Project Template

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.

What others have said

Requesting Gravatar... Craig Jan 11, 2012 12:48 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
What about a really really empty template? Here it is .
Requesting Gravatar... Steve Sanderson Jan 11, 2012 12:51 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
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.
Requesting Gravatar... haacked Jan 11, 2012 12:56 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
Ha ha ha ha. You guys crack me up. :)
Requesting Gravatar... Restuta Jan 11, 2012 1:23 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
Thanks, I like the "really" concept. I would like to have "really shutdown" and "really reboot" on my machine also =)
Requesting Gravatar... Ameer Jan 11, 2012 2:16 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
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?
Requesting Gravatar... Paul Batum Jan 11, 2012 3:33 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
Steve's comment is hilarious :)

I still think this template is what the actual "empty" template that ships should be..
Requesting Gravatar... Marvin Jan 11, 2012 7:55 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
This has nothing to do with your article but your RSS references to http://haacked.com/Default.aspx which doesn't work ;)
Requesting Gravatar... Göran Andersson Daum Jan 11, 2012 9:01 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
Good job, thanks for this.
Requesting Gravatar... Jonas Eriksson Jan 11, 2012 9:22 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
Cool! Would be nice to see it being added to the VS Gallery http://visualstudiogallery.msdn.microsoft.com/
Requesting Gravatar... fschwiet Jan 11, 2012 10:13 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
I lol'd. Does your non-compete allow you to school your old team so hard?
Requesting Gravatar... Joshua McKinney Jan 11, 2012 1:51 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
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.)
Requesting Gravatar... Corey Jan 11, 2012 2:16 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
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.
Requesting Gravatar... AbelebA Jan 11, 2012 3:02 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
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
Requesting Gravatar... Alex Jan 11, 2012 4:05 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
Creating project... project cration failed. "Сan not find the file specified (Exeption from HRESULT: 0x80070002)"
Requesting Gravatar... Alex Jan 11, 2012 4:14 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
When I uninstal this tamplate, all MVC 3 projects disappears from creation project menu :(
Requesting Gravatar... Battaile Fauber Jan 11, 2012 6:05 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
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...
Requesting Gravatar... haacked Jan 11, 2012 6:22 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
@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.
Requesting Gravatar... Battaile Fauber Jan 11, 2012 6:27 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
@Phil
Theirs gives the exact same generic server error due to having no controller or default page as yours gives.
Requesting Gravatar... haacked Jan 11, 2012 6:32 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
@Battaile great point! I didn't read your comment carefully. You're talking about the default MVC 3 *EMPTY* template. You are correct sir. :)
Requesting Gravatar... Battaile Fauber Jan 11, 2012 6:38 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
Thanks again for putting this out there. Exactly what I was looking for and its already in use!
Requesting Gravatar... Leyu Sisay Jan 12, 2012 8:37 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
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.
Requesting Gravatar... Tugberk Jan 12, 2012 4:18 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
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.
Requesting Gravatar... Jawad Jan 16, 2012 5:17 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
COOL
Requesting Gravatar... Jason Jan 17, 2012 8:32 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
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\ReallyEmptyMvc3ProjectTemplate.zip: ReallyEmptyMvcWebApplicationProjectTemplate.cshtml.vstemplate
Requesting Gravatar... coolguy97 Jan 22, 2012 9:04 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
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\ReallyEmptyMvc3ProjectTemplate.zip: 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)
Requesting Gravatar... haacked Jan 23, 2012 7:16 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
@coolguy97 I uploaded a new one. Try it out.
Requesting Gravatar... coolguy97 Jan 28, 2012 11:22 AM
# re: A Really Empty ASP.NET MVC 3 Project Template
Thanks Phil,It works.
Requesting Gravatar... Jonathan Jan 28, 2012 11:25 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
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.
Requesting Gravatar... Lobstrosity Feb 07, 2012 5:01 PM
# Custom Icon?
Is it possible to specify a custom icon in the .pkgdef (or elsewhere) for display in the "New ASP.NET MVC 3 Project" dialog?
Requesting Gravatar... Lobstrosity Feb 07, 2012 6:23 PM
# re: Custom Icon?
I tried specifying the icon in the .vstemplate, hoping the new project dialog would pick up on that. But no such luck.
Requesting Gravatar... Adam Feb 17, 2012 3:15 PM
# re: A Really Empty ASP.NET MVC 3 Project Template
Your vsix download link 404s (extra "ProjectTemplate" in the filename). Here's the corrected vsix download link

What do you have to say?

(will show your gravatar)
Please add 3 and 1 and type the answer here: