Hide this comment

Hi Stephan,

I've attempted to statically link C# assemblies into F# and found the process harrowing. It seems that --static-link fails when there is more than a single unmanaged resource in the dependent assemblies. I did get a combination of ILMerge and --standalone to create a standalone executable linking to a C# assembly.

Unfortunately general use of ILMerge with F# causes a strange namespace to be created with duplicate names defined A, B, C, D, E etc. This causes the resultant assembly not to load. I reported this to the author of ILMerge a while back and ask you to do the same if you run into the this problem.

ILMerge is actually very easy to use programmatically. With the new post-build step you could include this as a project and run it to merge your assemblies after they have been built. Here's an example bit of code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Tools.AssemblyMerge.Main


#light


#R "../lib/ILMerge.exe"


open System
open ILMerging


let proc = new FileInfo(Process.GetCurrentProcess().MainModule.FileName)
Environment.CurrentDirectory  <- proc.DirectoryName


let outputFile =  "../Tools.AssemblyMerge/XmlDiffPatchMerge.dll"
let inputAssemblies = [|"../lib/XmlDiffPatch.dll";  "../lib/XmlDiffPatch.View.dll" |] 


let mergeAssemblies () =
    let il = new ILMerge(TargetKind= ILMerge.Kind.Dll, OutputFile=outputFile)
    il.SetInputAssemblies inputAssemblies 
    try il.Merge(); write "<Message Content='Merge complete.'/>" 
    with e -> failwithf "<Error Content='Merge failed with %s'/>" e.Message


do mergeAssemblies ()

I do hope static linking and --standalone continues to improve toward v2.0.

regards,
Danny

btw - Great work with FParsec!! Looking forward to the next release...

By on 9/1/2008 7:54 AM ()Reply
Hide this comment

Hi Danny,

Thanks for your informative comments. As things are I'll probably just stick to the two DLLs solution until there's better support for merging assemblies.

Stephan

By on 9/1/2008 8:25 AM ()Reply
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper

Logging in...