Last night Julie Lerman was asking for something like this … I hope this helps you out Julie.
This should save some time if you are using MVC 3 applications with Azure web roles.
The approach I took was to adapt the existing MVC 2 Cloud Service Item Template to MVC 3 and it seems to work fine – except you have to add the test project manually (which I did some work on to – more on that below).
I created the following Item Templates and MVC Test Project Template(linked for you to download the ones you want):
NOTE: All are currently C#
After you follow the steps below you’ll get a dialog with the new web roles available, when you create a new Cloud project – like shown here:
Step 0: Get the files
Download the templates you need from my site:
Step 1: Put the Item Templates where VS will use them
Copy the zip files you downloaded to the following directory: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CloudService\NETFramework4\Web Role\Visual C#
My directory has all the templates and looks like this afterwards:
Step 2: Put the Test Project Template where VS will use it
Copy the MvcWebApplicationTestProjectTemplatev3.0.cs.zip file to the following directory:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\CSharp\Test\1033
My test directory has the following contents after I copy the zip into it:
Step 3: (Optional) Delete the ItemTemplate and ProjectTemplate cache
The step may be optional, but I did it – feel free to try and skip it, If you find the templates are not showing up in the dialog, you can come back and do Steps 3 and 4 at that time.
Find the ItemsTemplatesCache directory (C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache) and delete all the contents in it.
Find the ProjectTemplatesCache directory (C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplatesCache) and delete all the contents in it.
Step 4: Rebuild Visual Studio’s template cache
Open a VS Command Prompt (found under Visual Studio 10 –> Visual Studio Tools on you start menu).
Run the command: devenv.exe /installvstemplates
This will take awhile – on my machine it takes between 10 and 15 minutes.
About the Test Project
After adding the templates as outlined above, you’ll be able to create a web role using the different MVC 3.0 project templates – however you don’t get the chance to add a test project. That is the reason for step 2 above.
After you have created the web role, you get a Solution Explorer that looks something like the image to the left.
In order to add a test project you need to do the following:
- Right click on the Solution node
- Choose Add –> New Project…
- In the template listing on the left, choose Visual C# –> Test
- This will give you the option to add an ASP.NET MVC3 Test Project
Once the Test Project is added, you will need to add a reference to your MVC project and fix the namespaces in the Controller Tests (if you keep them).
I hope this saves someone some time, let me know if you have any problems with it.
UPDATE: In the comments Mick mentioned the templates were missing some copy local settings. Those have now been added. If anyone else notices anything missing, please let me know and I'll get it fixed.