Wednesday, November 9, 2011

New F# Windows Phone Library Project Template

There is a new F# Windows Phone Library project template now available on Visual Studio Gallery. This project template allows you to add a new F# library project to a Windows Phone solution rather than having to start with one of the solution templates that is initialized with both a C# and F# project.

As an example, you could easily build the F# and C# Win Phone App (Silverlight) solution by doing the following:

1. Create a new C# Windows Phone Application (Silverlight).
2. Add a new F# Windows Phone Library project to the solution.
3. Add a new XML file to the F# project named MainPage.xaml.
4. Add content to the MainPage.xaml file as shown here (also change the Build Action option to Resource and the Copy to Output Directory option to Copy always).
5. Add the code from here to the File1.fs file.
6. Delete the MainPage.xaml and associated code-behind file from the C# project.
7. Change the App.xaml.cs code in the C# project to what is shown here (Note: You'll likely need to change the namespace).
8. Change the App.xaml code in the C# project to what is shown here (Note: You'll likely need to change the namespace).
9. Edit the properties of the C# project and change the Startup object drop down to the *.AppHost object.
10. Edit the WMAppManifest.xml file and change:


<DefaultTask  Name ="_default" NavigationPage="MainPage.xaml"/>

to 

<DefaultTask  Name ="_default"/>

11. Finally, add a reference to the F# project, build, and test.

3 comments:

  1. Hi Daniel,

    I'm having major trouble with this, and with the template from the gallery. My Build errors are that the WindowsPhoneApp.dll can't be found. I haven't touched the code, files or anything! Just downloaded and built. I got the same error trying your solution above. Help!

    ReplyDelete
  2. Hi Sonya, I'm happy to help! I'll need to gather some info to start the troubleshooting process. Shoot me an email (dmohl at yahoo.com) and we'll work to get this up and running for you.

    ReplyDelete
  3. I have no words for this great post such a awe-some information i got gathered. Thanks to Author.
    WINDOWS PHONE 7 DEVELOPMENT| SEO tools

    ReplyDelete