简体   繁体   中英

Creating Silverlight 3 applications with F#

Is there an easy way to create Silverlight 3 applications with F# (October CTP)? I have seen the F# for Silverlight , but that only works with the May CTP.

I am using Visual Studio Integrated Shell 2008.

It is possible to use the May CTP templates with the October CTP version of F#

Create your new project, then unload it and edit the hint path for the FSharp.Core.dll to point to the October CTP,

<HintPath>$(ProgramFiles)\fsharp-1.9.7.8\Silverlight\2.0\bin\FSharp.Core.dll</HintPath>

then reload the project and build.

You do have to package the .xap file manually by eg using the chiron tool (or just zipping and renaming)

The AppManifest.xaml file looks like

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            RuntimeVersion="3.0.40818.0" 
            EntryPointAssembly="astroclock-fs" 
            EntryPointType="astroclock.fs.MyApp">
  <Deployment.Parts>
    <AssemblyPart x:Name="astroclock-fs" Source="astroclock-fs.dll" />
    <AssemblyPart x:Name="FSharp.Core" Source="FSharp.Core.dll" />
  </Deployment.Parts>
</Deployment>

where you fill in your own assembly name and entrypoint instead of mine

Create a folder in $(ProjectDir) to hold all the files to be packaged and copy C:\\Program Files\\FSharp-1.9.7.8\\Silverlight\\2.0\\bin\\FSharp.Core.dll into it, along with the AppManifest.xaml above

Create an empty file null.py in the folder to keep chiron quiet if you are using that tool

Add the following post-build steps

cd $(ProjectDir)
copy /y $(OutDir)$(TargetFileName) [your directory with all the output] 
"C:\Program Files\IronPython 2.0\Silverlight\bin\chiron.exe" /d:[your directory with all the output] /z:app.xap

Create a test page to load app.xap

Build project

Load page in browser and enjoy

ADDED

You can make a permanent fix for the hint path needed to find FSharp.Core.dll by editing the template in C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\ProjectTemplatesCache\\FSharp\\Silverlight\\SilverlightLibrary3.zip\\SilverlightLibrary.fsproj (and probably the version of the file in C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\ProjectTemplates\\FSharp\\Silverlight\\SilverlightLibrary3.zip just to be certain).

And a working proof of concept (source and everything bundled into the xap) here .

看来我必须等待VS 2010

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM