基于源代码在vb.net中构建.exe?
我的题目基本上就是我要问的。基于源代码在vb.net中构建.exe?,vb.net,Vb.net,我的题目基本上就是我要问的。 是否可以基于某些vb.net源代码编译.exe?这个问题很奇怪,但我只是想问,因为我想以某种方式实现-在gui中创建一些东西-然后将其导出为.EXE文件。谢谢是的,这是可能的,请参考此问题: 非常感谢我找了很久了:D Friend Function CreateConsoleApplication(ByVal VBSourceCode As String, ByVal WhereToSave As String) As Boolean Try
是否可以基于某些vb.net源代码编译.exe?这个问题很奇怪,但我只是想问,因为我想以某种方式实现-在gui中创建一些东西-然后将其导出为.EXE文件。谢谢是的,这是可能的,请参考此问题:
非常感谢我找了很久了:D
Friend Function CreateConsoleApplication(ByVal VBSourceCode As String, ByVal WhereToSave As String) As Boolean
Try
VBSourceCode = "Module Module1" & vbCrLf & "Sub Main()" & vbCrLf & "Dim UserInfo As String = ""Name: User1""" & vbCrLf & "System.Console.WriteLine(UserInfo)" & vbCrLf & "System.Console.ReadLine()" & vbCrLf & "End Sub" & vbCrLf & "End Module"
WhereToSave = "E:\TestConsole.exe"
Dim provider As Microsoft.VisualBasic.VBCodeProvider
Dim compiler As System.CodeDom.Compiler.ICodeCompiler
Dim params As System.CodeDom.Compiler.CompilerParameters
Dim results As System.CodeDom.Compiler.CompilerResults
params = New System.CodeDom.Compiler.CompilerParameters
params.GenerateInMemory = False
params.TreatWarningsAsErrors = False
params.WarningLevel = 4
'Put any references you need here - even you own dll's, if you want to use one
Dim refs() As String = {"System.dll", "Microsoft.VisualBasic.dll"}
params.ReferencedAssemblies.AddRange(refs)
params.GenerateExecutable = True
params.OutputAssembly = WhereToSave
provider = New Microsoft.VisualBasic.VBCodeProvider
results = provider.CompileAssemblyFromSource(params, VBSourceCode)
Return True
Catch ex As Exception
MessageBox.Show(ex.ToString)
Return False
End Try
End Function