Saturday, November 30, 2013

Adding New Items to a Pure F# ASP.NET MVC/Web API Project

UPDATE 12/15/2013:
-----------------------

The F# community has been working hard on ways to make this process easier. To that end, here are the new and improved instructions:

Option 1: Visual Studio Project Template Option:

The easiest option is to simply install the latest version of either the F# MVC 5 template or the F# Nancy template. These templates now include a custom NuGet package that contains an Install.ps1 file that will automatically add the needed registry entries.

Option 2: PowerShell Option:

If you prefer to run the PowerShell file manually, you can do the following:

1. Launch PowerShell (you may need to run PowerShell as administrator).
2. Download the AddRegistryEntries.ps1 file and execute it with the command ./AddRegstryEntries.ps1

Option 3: Batch File Option:

If you don't want to use PowerShell, there is also a batch file option.

1. Download the AddRegistryEntries.bat file.
2. Run the batch file as administrator.

You should now be able to see the items shown in step #5 of the original post. Don't forget to checkout the F# Web Item Templates as well.

-----------------------

A few months ago Mark Seemann put together a great post on how to create a pure F# ASP.NET Web API project. One of the biggest disadvantages mentioned in that post is that once the necessary changes are made to the ProjectTypeGuids element in the fsproj file, the Add New Item wizard no longer displays items. After much trial and error, I've found a fix for this issue.

Note: While the change mentioned here is pretty mild, the standard registry edit disclaimer still applies. It's recommended that you backup your registry before making changes as incorrect changes/additions/deletions can have serious and unexpected consequences.

Here are the steps for VS2013 (for VS2012 the steps should be similar, but with a slightly different registry path).

1. Edit the registry (e.g. run regedit.exe).

2. Locate HKEY_LOCAL_MACHINE or HKEY_LOCAL_USER then \SOFTWARE\Microsoft\VisualStudio\ then 12.0 or 12.0_Config then \Projects\

3. Find {349C5851-65DF-11DA-9384-00065B846F21}. If there is more than one, find the one with LanguageTemplates as the child. 

4. Add a new String Value entry to the LanguageTemplates node with a key and value of {F2A71F9B-5D33-465A-A702-920D77279786}.


5. Test it out by closing all instances of VS, creating a pure F# ASP.NET MVC or Web API project, and trying to add a new item. You should now see all of the usual F# item templates.


If you want to try this out without having to manually create a pure F# ASP.NET MVC or Web API project, here's a sneak peak of one of the F# Nancy templates that Ryan Riley and I are working on. Look for the full collection of F# Nancy templates in the next few weeks. You can get involved with the Nancy templates by contributing to https://github.com/fsharp/FSharpCommunityTemplates/tree/master/VisualStudio/Nancy.Templates.

5 comments:

  1. can't find {349C5850-65DF-11DA-9384-00065B846F21} :(

    ReplyDelete
  2. try {349C5851-....

    ReplyDelete
  3. Yes I've got this and had tried but it didn't helped on my messy environment (seems like) so for now I gave up of trying it...

    ReplyDelete
  4. I've updated the post to include a script to simplify the process. This script includes additional registry paths that were not covered in the original post. Hopefully this will resolve the issue for you.

    ReplyDelete
  5. I cannot seem to run it under the azure emulator. I get the following error message
    "the web role in question doesn't seem to be a web application type project"

    ReplyDelete