I've written this simple function to automate the compilation of a single exe assembly with an embedded resource:
Public Shared Function CompileAssembly(ByVal codeProvider As CodeDomProvider,
ByVal isExecutable As Boolean,
ByVal targetFile As String,
Optional ByVal resources As IEnumerable(Of String) = Nothing,
Optional ByVal code As String = "") As CompilerResults
Dim cp As New CompilerParameters
With cp
' Generate an exe or a dll.
.GenerateExecutable = isExecutable
' Set the assembly file name to generate.
.OutputAssembly = targetFile
' Set compiler argument to optimize output.
.CompilerOptions = "/optimize"
' Specify the class that contains the main method of the executable.
If codeProvider.Supports(GeneratorSupport.EntryPointMethod) Then
.MainClass = "MainClass"
End If
' Set the embedded resource file of the assembly.
If codeProvider.Supports(GeneratorSupport.Resources) AndAlso resources IsNot Nothing Then
.EmbeddedResources.AddRange(resources.ToArray)
End If
End With
Return codeProvider.CompileAssemblyFromSource(cp, code)
End Function
The problem is that I need to compile a non-commandline application, a Class like this which I provide a method that should be executed when the app runs:
Dim sourceCode As String =
<a>
Public Class MainClass
Sub MainMethod()
' Do Something when the app is executed...
End Sub
End Class
</a>.Value
but I can't find the way to do it.
I only can compile console applications because the codeprovider seems that needs an entrypoint, so I only be able to compile this, which is not what I want:
Dim Sourcecode As String =
<a>
Module MainModule
Sub Main()
End Sub
End Module
</a>.Value
How I could do this for my needs?.
I just want to share my working CodeDomProvider compiler routine: