Sinisterly
Codedom - Make your own advanced builder - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework)
+--- Thread: Codedom - Make your own advanced builder (/Thread-Codedom-Make-your-own-advanced-builder)



Codedom - Make your own advanced builder - schockerjo - 09-22-2013

Hello,

this is my first tutorial on HC and my english isnt the best, so dont be so strictly Smile.

Lets begin:

What is CodeDom ?: CodedDom

We will use CodeDom to compile our stub code stored in a string, the big advantage is that you can edit the code easily.

I assume that you know, what Classes, Subs, Functions and so on are.

Builder:
First of all you will need the compiler.vb class:
Code:
Imports System.CodeDom.Compiler Public Class compiler Public Shared Sub Compile(ByVal Output As String, ByVal cSource As String) Dim Compiler As ICodeCompiler = New VBCodeProvider().CreateCompiler 'Creating compiler Dim Parameters As New CompilerParameters 'A type of variable, holding things like: path to save, imports and more Dim cResults As CompilerResults 'Used for checking if everything is fine Parameters.GenerateExecutable = True 'We want to make an EXE-File Parameters.OutputAssembly = Output 'Declare where to save the file Parameters.ReferencedAssemblies.Add("System.dll") 'We need that if we want to import something like: System.IO Parameters.ReferencedAssemblies.Add("System.Data.dll") Parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll") 'Adding basic references, you have to do this because you cant do it in the code. (Things like "System.IO" can be added in the code :) ). Parameters.CompilerOptions = "/optimize+ /platform:X86 /debug- /target:winexe" 'Basic parameters: read more here: http://msdn.microsoft.com/en-us/library/w95cx9k1.aspx cResults = Compiler.CompileAssemblyFromSource(Parameters, cSource) 'Compile the code with the Parameters Variable and the source given in compiler.Compile(pathtofile,My.Resources.Stub) If cResults.Errors.Count > 0 Then 'Checking for errors For Each CompilerError In cResults.Errors 'Looping through all of them, use CompilerError.errorText to get the error msgbox(CompilerError.errorText) Next ElseIf cResults.Errors.Count = 0 Then 'No errors End If End Sub End Class

You see, its not that much code.

Now add a document to the resources of the project.
With this text here:
Code:
Imports System.Net Imports System.IO Imports System.Collections 'Basic imports (feel free to change them :) ) Module Stub Sub main() End Sub End Module

Know add your code, and replace the variables(given by the user) with something like [FTP].

Code:
Imports System.Net Imports System.IO Imports System.Collections 'Basic imports (feel free to change them :) ) Module Stub Sub main() My.Computer.Network.DownloadFile([Dlink],[WhereToSave]) End Sub End Module

Know go to your Builder and add something like this:
Code:
Above the code: Imports ProjectName.compiler

Code:
Dim src As String = My.Resources.documentname src = src.Replace("[Dlink]", Downloadlink.Text) src = src.Replace("[WhereToSave]",save.text) compiler.Compile(pathtosaveEXE, src)

With this method you can easily add not just variables, complete functions, subs can be added with this.

Use this code wherever you want.

Peace :Cool:


RE: Codedom - Making your own advanced builder - 1llusion - 09-22-2013

Wow CodeDom builder whose code isn't messy! Nice tut, probably you could explain a bit more what each part of the code does Smile


RE: Codedom - Making your own advanced builder - schockerjo - 09-22-2013

Yes, I will do it.
But it will take time Smile .

Edit: Updated, hope you enjoy it Smile


RE: Codedom - Make your own advanced builder - OsBinHD - 09-27-2013

thanx mate nice tut Smile respect i will try it on evening


RE: Codedom - Make your own advanced builder - nnc36 - 09-27-2013

can i see Screen shoot what like the form that i have to made.
thc before


RE: Codedom - Make your own advanced builder - schockerjo - 09-27-2013

Shouldnt be that hard, but ok :

[Image: rnykhmdc941d.png]