使用ICodeCompiler将文本文件编译为exe [英] Compiling a text file to exe with ICodeCompiler

查看:113
本文介绍了使用ICodeCompiler将文本文件编译为exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想知道如何才能完成这项工作......我有一个包含两个类的文本文件,但编译器一直处于失败状态...现在有点沮丧......一直在努力争取一个星期......请帮忙。



在文本文件中...如果您想查看我可以通过电子邮件发送的代码

1.公共舱位表格1

2.公共舱位设置



这是我走了多远



私函数编译(ByVal输出为字符串)As Boolean

Dim result As Boolean



Dim vbcode As VBCodeProvider = New VBCodeProvider

Dim compiler As ICodeCompiler = vbcode.CreateCompiler()

Dim compargs As New CompilerParameters()

compargs.GenerateInMemory = False

Dim references()As String = {" System.Windows.Forms.dll"," System.Drawing.dll"," Microsoft.VisualBasic.dll"," System.dll" ;}

compa rgs.CompilerOptions =" / target:winexe / m:Form1 / win32icon:" &安培; " C:\ install.ico"

compargs.GenerateExecutable = True

compargs.IncludeDebugInformation = False

compargs.OutputAssembly = output

compargs.TreatWarningsAsErrors = False



compargs.ReferencedAssemblies.AddRange(参考)



Dim res As CompilerResults

res = compiler.CompileAssemblyFromFile(compargs," C:\ TDIR \prg.txt")



如果res.Errors.Count> 0然后

结果=错误

否则

结果=真

结束如果

返回结果

结束函数

解决方案

从这里开始:使用CodeDom编译和运行VB.NET代码 [ ^ ]


< blockquote>喘息后我决定冷静下来......看了一下板球然后开始思考

我改变了整个文本文件,检查下面的代码......看哪......工作原理!我太棒了!





进口设置

进口系统

进口System.IO

Imports System.Text

Imports System.Drawing

进口System.Windows.Forms

进口System.ComponentModel

Imports System.CodeDom.Compiler

Imports System.Collections.Generic

Imports System.Runtime.Serialization.Formatters.Binary < br $>


公共类Form1

继承表格

Dim WithEvents myButton As Button



Public Sub New()



myButton = New Button()

dim [set] as New Settings( )

myButton.Text = [set] .MText

myButton.Top = 70

myButton.Left = 70



Me.controls.add(myButton)



结束次级



Private Sub myButtonClick(ByVal sender As Object,ByVal e As EventArgs)_

处理myButton.Click

MessageBox.Show(Hello World!)

End Sub



结束班级



< serializable> _

公共类设置



Public Sub New()

End Sub



Public m_text as String =BOOOOO



Public Property MText()As String

Get

返回m_text

结束获取

设置(值为字符串)

m_text = value

结束套票

结束物业



结束班


Hi there, I would like to find out how I can make this work... I have a Text file containing two classes, but the compiler keeps on failing... A bit frustrated now... Been battling for about a week... Please help.

IN TEXT FILE... If you would like to see the code I can send it via email
1. Public Class Form1
2. Public Class Settings

This is how far I got

Private Function Compile(ByVal output As String) As Boolean
Dim result As Boolean

Dim vbcode As VBCodeProvider = New VBCodeProvider
Dim compiler As ICodeCompiler = vbcode.CreateCompiler()
Dim compargs As New CompilerParameters()
compargs.GenerateInMemory = False
Dim references() As String = {"System.Windows.Forms.dll", "System.Drawing.dll", "Microsoft.VisualBasic.dll", "System.dll"}
compargs.CompilerOptions = "/target:winexe /m:Form1 /win32icon:" & "C:\install.ico"
compargs.GenerateExecutable = True
compargs.IncludeDebugInformation = False
compargs.OutputAssembly = output
compargs.TreatWarningsAsErrors = False

compargs.ReferencedAssemblies.AddRange(references)

Dim res As CompilerResults
res = compiler.CompileAssemblyFromFile(compargs, "C:\TDIR\prg.txt")

If res.Errors.Count > 0 Then
result = False
Else
result = True
End If
Return result
End Function

解决方案

Start here : Compile and Run VB.NET Code using the CodeDom[^]


After breathing heavily I decided to calm down... Watched a bit of cricket and then got to thinking
I changed the whole text file check the code below... Behold...IT WORKS! I am soooo stoked!


Imports Settings
Imports System
Imports System.IO
Imports System.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.CodeDom.Compiler
Imports System.Collections.Generic
Imports System.Runtime.Serialization.Formatters.Binary

Public Class Form1
Inherits Form
Dim WithEvents myButton As Button

Public Sub New()

myButton = New Button()
dim [set] as New Settings()
myButton.Text = [set].MText
myButton.Top = 70
myButton.Left = 70

Me.controls.add(myButton)

End Sub

Private Sub myButtonClick(ByVal sender As Object, ByVal e As EventArgs) _
Handles myButton.Click
MessageBox.Show("Hello World!")
End Sub

End Class

<serializable> _
Public Class Settings

Public Sub New()
End Sub

Public m_text as String = "BOOOOO"

Public Property MText() As String
Get
return m_text
End Get
Set(value As String)
m_text = value
End Set
End Property

End Class


这篇关于使用ICodeCompiler将文本文件编译为exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆