2014-02-27 36 views
0

我的问题标题基本上是我问的。 是否有可能编译基于某些vb.net源代码的.exe文件?这个问题很奇怪,但我只是问,因为我想以某种方式实现 - 在GUI中创建一些东西 - 然后将其导出为.EXE文件。感谢基于源代码在vb.net中建立.exe文件?

回答

2

是的,这是可能的,请参考这个问题:How to compile a VB.NET console application's source code using VB.NET

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 
+0

谢谢你这么多,我一直在寻找这样的年龄:d –

相关问题