Hello all, I've been fooling around allot in .Net recently and stumbled across a problem that I can't quite wrap my head around.
I beleive that my code is correct and compiles my program without issues but with one catch.
Even though I've specified the compiler version to compile to v2.0 framework, it's compiling in v4.0
Does anyone have any ideas on how I can fix this?
I beleive that my code is correct and compiles my program without issues but with one catch.
Code
Public Sub Compile(ByVal Output As String, ByVal Source As String)
On Error Resume Next
Dim Compiler As ICodeCompiler = (New VBCodeProvider).CreateCompiler()
Dim Parameters As New CompilerParameters()
Dim cResults As CompilerResults
Parameters.GenerateExecutable = True
Parameters.OutputAssembly = Output
Parameters.CompilerOptions = ("/win32icon:" & (Chr(34) & StubIcon & Chr(34))("/target:winexe"))
Parameters.ReferencedAssemblies.Add("System.dll")
Dim Version = New Dictionary(Of String, String)
Version.Add("CompilerVersion", "v2.0")
cResults = Compiler.CompileAssemblyFromSource(Parameters, Source)
If cResults.Errors.Count > 0 Then
For Each CompilerError In cResults.Errors
MessageBox.Show("Error: " & CompilerError.ErrorText, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
Next
ElseIf cResults.Errors.Count = 0 Then
End If
End SubEven though I've specified the compiler version to compile to v2.0 framework, it's compiling in v4.0
Code
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly extern Microsoft.VisualBasic
{
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....:
.ver 10:0:0:0
}
.assembly extern System
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly test
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module test.exe
// MVID: {AF7D08A3-6D4D-4096-8865-D551ADA33023}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x08D80000Does anyone have any ideas on how I can fix this?

