Installation
FSharp.Compiler.CodeDom supports installation via both NuGet and system-wide.
NuGet installation allows for basic use of the library within your application
or library. A system-wide installation enables any CodeDom-capable program or
library to make use of the library, but requires administrator access (on
Windows) or write permission to the Mono GAC and machine.config
file (on
Unix). A system-wide install can coexist with individual NuGet installs.
To perform a system-wide install on Windows, build the library from the command
line with build Release
. A MSI package will be produced in
Installer\Installer\bin\Release
. After installation, the library will be
available for use.
To perform a system-wide install on Unix, build the library from the command
line with build Release
. Navigate to SimpleInstaller/bin/Release
, and
then, as a user with permission to write to the Mono GAC directory (e.g.
/usr/lib/mono/gac
) and machine.config
file (e.g.
/etc/mono/4.5/machine.config
), run:
1: 2: |
|
Uninstallation
On Windows, uninstallation can be performed through Add/Remove Programs, PowerShell, etc.
On Unix, as a user with the aforementioned privileges:
1: 2: |
|
As an alternative to using SimpleInstaller, the FSharp.Compiler.CodeDom line
under <system.codedom>
can be manually deleted from machine.config
.
A note on CodeDom providers
CodeDom provides a mechanism that allows for programs which use CodeDom to
generate code for any language for which a provider is installed--the program
need not have any knowledge of that language or the existence of a provider.
Unfortunately, many programs (including ones from Microsoft!) are poorly written
and hard-code a list of supported providers, usually to only C# and VB,
destroying much of CodeDom's utility. Properly written programs should always
allow the user to specify an arbitrary string (corresponding to a language with
a system-registered provider) to be passed to
System.CodeDom.Compiler.CodeDomProvider.CreateProvider
. This way, there is no
need to directly reference assemblies or hard-code providers, as any provider
available to the system can be used.
Basic use of the provider (system-wide install)
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: |
|
Tutorial
First, reference the assembly (not needed if a system-wide install was done):
1:
|
|
Next, create an instance of the provider:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: |
|
Now, add some Code DOM constructs to a code unit:
1: 2: 3: 4: 5: 6: 7: |
|
Generate the code:
1: 2: 3: 4: 5: |
|
Full name: Tutorial.prov
inherit Component
member CompileAssemblyFromDom : options:CompilerParameters * [<ParamArray>] compilationUnits:CodeCompileUnit[] -> CompilerResults
member CompileAssemblyFromFile : options:CompilerParameters * [<ParamArray>] fileNames:string[] -> CompilerResults
member CompileAssemblyFromSource : options:CompilerParameters * [<ParamArray>] sources:string[] -> CompilerResults
member CreateCompiler : unit -> ICodeCompiler
member CreateEscapedIdentifier : value:string -> string
member CreateGenerator : unit -> ICodeGenerator + 2 overloads
member CreateParser : unit -> ICodeParser
member CreateValidIdentifier : value:string -> string
member FileExtension : string
member GenerateCodeFromCompileUnit : compileUnit:CodeCompileUnit * writer:TextWriter * options:CodeGeneratorOptions -> unit
...
Full name: System.CodeDom.Compiler.CodeDomProvider
Compiler.CodeDomProvider.CreateProvider(language: string, providerOptions: System.Collections.Generic.IDictionary<string,string>) : Compiler.CodeDomProvider
Full name: Tutorial.ccu
type CodeCompileUnit =
inherit CodeObject
new : unit -> CodeCompileUnit
member AssemblyCustomAttributes : CodeAttributeDeclarationCollection
member EndDirectives : CodeDirectiveCollection
member Namespaces : CodeNamespaceCollection
member ReferencedAssemblies : StringCollection
member StartDirectives : CodeDirectiveCollection
Full name: System.CodeDom.CodeCompileUnit
--------------------
CodeCompileUnit() : unit
Full name: Tutorial.nsp
type CodeNamespace =
inherit CodeObject
new : unit -> CodeNamespace + 1 overload
member Comments : CodeCommentStatementCollection
member Imports : CodeNamespaceImportCollection
member Name : string with get, set
member Types : CodeTypeDeclarationCollection
event PopulateComments : EventHandler
event PopulateImports : EventHandler
event PopulateTypes : EventHandler
Full name: System.CodeDom.CodeNamespace
--------------------
CodeNamespace() : unit
CodeNamespace(name: string) : unit
Full name: Tutorial.ty
type CodeTypeDeclaration =
inherit CodeTypeMember
new : unit -> CodeTypeDeclaration + 1 overload
member BaseTypes : CodeTypeReferenceCollection
member IsClass : bool with get, set
member IsEnum : bool with get, set
member IsInterface : bool with get, set
member IsPartial : bool with get, set
member IsStruct : bool with get, set
member Members : CodeTypeMemberCollection
member TypeAttributes : TypeAttributes with get, set
member TypeParameters : CodeTypeParameterCollection
...
Full name: System.CodeDom.CodeTypeDeclaration
--------------------
CodeTypeDeclaration() : unit
CodeTypeDeclaration(name: string) : unit
Full name: Tutorial.meth
type CodeEntryPointMethod =
inherit CodeMemberMethod
new : unit -> CodeEntryPointMethod
Full name: System.CodeDom.CodeEntryPointMethod
--------------------
CodeEntryPointMethod() : unit
Full name: Tutorial.options
type CodeGeneratorOptions =
new : unit -> CodeGeneratorOptions
member BlankLinesBetweenMembers : bool with get, set
member BracingStyle : string with get, set
member ElseOnClosing : bool with get, set
member IndentString : string with get, set
member Item : string -> obj with get, set
member VerbatimOrder : bool with get, set
Full name: System.CodeDom.Compiler.CodeGeneratorOptions
--------------------
Compiler.CodeGeneratorOptions() : unit
Full name: Tutorial.sw
type StringWriter =
inherit TextWriter
new : unit -> StringWriter + 3 overloads
member Close : unit -> unit
member Encoding : Encoding
member GetStringBuilder : unit -> StringBuilder
member ToString : unit -> string
member Write : value:char -> unit + 2 overloads
Full name: System.IO.StringWriter
--------------------
StringWriter() : unit
StringWriter(formatProvider: System.IFormatProvider) : unit
StringWriter(sb: System.Text.StringBuilder) : unit
StringWriter(sb: System.Text.StringBuilder, formatProvider: System.IFormatProvider) : unit
Full name: Tutorial.code
Full name: Tutorial.provider
namespace FSharp
--------------------
namespace Microsoft.FSharp
Full name: Tutorial.provider
type FSharpCodeProvider =
inherit CodeDomProvider
new : unit -> FSharpCodeProvider
Full name: FSharp.Compiler.CodeDom.FSharpCodeProvider
--------------------
new : unit -> FSharpCodeProvider
Full name: Tutorial.provider
type FSharpCleanCodeProvider =
inherit CodeDomProvider
new : unit -> FSharpCleanCodeProvider
override CreateCompiler : unit -> ICodeCompiler
override CreateGenerator : unit -> ICodeGenerator
override FileExtension : string
Full name: FSharp.Compiler.CodeDom.FSharpCleanCodeProvider
--------------------
new : unit -> FSharpCleanCodeProvider