19.1.09

F# Silverlight

Here are my own steps to get an f# silverlight application working. You can get the code here. Thanks to Michael Giagnocavo and John Liao for most of this information.


UPDATE: I forgot to add the part about the references earlier, but had added it now.

  1. Create an f# library project.

  2. On the project settings "Build" tab, add the compiler flags "--standalone --noframework"

  3. Create an Application and a Page class, or whatever Silverlight classes you want.

  4. Add an AppManifest file like this (stolen from a c# silverlight apllication):

    <Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Deployment.Parts>
    </Deployment.Parts>
    </Deployment>

  5. Unload the project and edit the .fsproj file

  6. Add the following options to the first PropertyGroup at the top of the file (the one that has property groups for all configurations:

    <SilverlightApplication>true</SilverlightApplication>
    <XapOutputs>true</XapOutputs>
    <GenerateSilverlightManifest>true</GenerateSilverlightManifest>
    <XapFilename>__Your_App_Name__.xap</XapFilename>
    <SilverlightManifestTemplate>AppManifest.xml</SilverlightManifestTemplate>
    <SilverlightAppEntry>__Your_App_Class_Full_Typename__</SilverlightAppEntry>
    <TestPageFileName>TestPage.html</TestPageFileName>
    <CreateTestPage>true</CreateTestPage>
    <ValidateXaml>true</ValidateXaml>
    <ThrowErrorsInValidation>true</ThrowErrorsInValidation>

  7. Replace the references section with the following (note: you could do this without unloading the project, but doing it in the text editor seems way easier.):

    <Reference Include="mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
    <Name>mscorlib</Name>
    <AssemblyName>mscorlib.dll</AssemblyName>
    <HintPath>..\..\..\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\mscorlib.dll</HintPath>
    <Private>False</Private>
    </Reference>
    <Reference Include="System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
    <Name>System</Name>
    <AssemblyName>system.dll</AssemblyName>
    <HintPath>..\..\..\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\system.dll</HintPath>
    <Private>False</Private>
    </Reference>
    <Reference Include="System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
    <Name>System.Core</Name>
    <AssemblyName>System.Core.dll</AssemblyName>
    <HintPath>..\..\..\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Core.dll</HintPath>
    <Private>False</Private>
    </Reference>
    <Reference Include="System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
    <Name>System.Net</Name>
    <AssemblyName>System.Net.dll</AssemblyName>
    <HintPath>..\..\..\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Net.dll</HintPath>
    <Private>False</Private>
    </Reference>
    <Reference Include="System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
    <Name>System.Runtime.Serialization</Name>
    <AssemblyName>System.Runtime.Serialization.dll</AssemblyName>
    </Reference>
    <Reference Include="System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
    <Name>System.Windows</Name>
    <AssemblyName>System.Windows.dll</AssemblyName>
    <HintPath>..\..\..\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Windows.dll</HintPath>
    <Private>False</Private>
    </Reference>
    <Reference Include="System.Windows.Browser, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
    <Name>System.Windows.Browser</Name>
    <AssemblyName>System.Windows.Browser.dll</AssemblyName>
    <HintPath>..\..\..\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Windows.Browser.dll</HintPath>
    <Private>False</Private>
    </Reference>
    <Reference Include="System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
    <Name>System.Xml</Name>
    <AssemblyName>System.Xml.dll</AssemblyName>
    <HintPath>..\..\..\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Xml.dll</HintPath>
    <Private>False</Private>
    </Reference>


  8. Add this line:

    <Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.Common.targets" />
    just _after_ the FSharp Targets line:

    <Import Project="$(MSBuildExtensionsPath)\FSharp\1.0\Microsoft.FSharp.Targets" />

  9. Reload the project, build, and load the TestPage.html page in a browser to verify it works.

21.10.08

Using Beyond Compare as a Git Mergetool

At the October #altnetseattle meeting, we talked about git and Aaron Jensen mentioned a nice merge tool called p4merge, which I hadn't heard of before. I hadn't been able to get a merge tool to work right with msysgit before, so knowing Aaron was using p4merge with git led me to try again.

I actually still prefer beyond compare to p4merge - p4merge is nice and looks snazzy, but BC has all the right keystrokes and shows me just the right information when I am trying to do a merge.

To get it to work with git, I added this to my global git config ("C:\Program Files\git\etc\config"):




[merge]
tool = bc3 # This will be the default merge tool invoked by git mergetool.
[mergetool "bc3"]
cmd = C:/Users/cbilson/Desktop/BC3/bcomp.com \
"$PWD/$LOCAL" \
"$PWD/$REMOTE" \
"$PWD/$BASE" \
"$PWD/$MERGED"
keepBackup = false
trustExitCode = false


I had trouble getting it to run from "C:/Program Files/..." or even "C:/Program\ Files/..." so I did a portable install of BC and run it from there.

18.10.08

F# + Monorail

Inspired by Matthew Podwysocki's post on using F# to build an ASP.NET MVC application, I built a Monorail application with F#.



I think this is a good exercise for F#-pies (pronounced: "F" "sharpies") because it kind of forces you to figure out how F# works with the rest of .NET instead of fixating on the functional aspects.



I believe the basics were all done by this commit. I am adding some more stuff to it (a domain model, something besides "Hello World") for a kind of larger attempt at building a real application all in F#.

New Blog

Actually, I've had this blog for a while, just never posted. I don't actually blog very much, and now kind of prefer just using twitter, so the value of my old blog was less than the $200/year I was paying. Still, it's nice to have a place to post things longer than 140 characters. That's what this is.