Advertisement
Guest User

CodeDomUtil (VB and C# compiler features) - By Elektro

a guest
Sep 19th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 91.72 KB | None | 0 0
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Modified : 19-September-2015
  4. ' ***********************************************************************
  5. ' <copyright file="CodeDomUtil.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Public Members Summary "
  11.  
  12. #Region " Child Classes "
  13.  
  14. ' CodeDomUtil.Compiler
  15. ' CodeDomUtil.Compiler.Warning
  16. ' CodeDomUtil.Compiler.Error
  17. ' CodeDomUtil.Compiler.CompilerWorkDoneEventArgs
  18.  
  19. ' CodedomUtil.CompilerSettings
  20. ' CodeDomUtil.CompilerVersions
  21. ' CodeDomUtil.SubsystemVersions
  22.  
  23. ' CodeDomUtil.VisualBasicCompiler : Inherits Compiler
  24. ' CodeDomUtil.CSharpCompiler : Inherits Compiler
  25.  
  26. #End Region
  27.  
  28. #Region " Variables / Constants / Read-Only "
  29.  
  30. ' CodeDomUtil.Templates.TemplateVbConsoleApp
  31. ' CodeDomUtil.Templates.TemplateVbWinFormsApp
  32. ' CodeDomUtil.Templates.TemplateVbLib
  33. ' CodeDomUtil.Templates.TemplateCsConsoleApp
  34. ' CodeDomUtil.Templates.TemplateCsWinFormsApp
  35. ' CodeDomUtil.Templates.TemplateCsLib
  36.  
  37. ' CodeDomUtil.CompilerVersions.V1 As String
  38. ' CodeDomUtil.CompilerVersions.V2 As String
  39. ' CodeDomUtil.CompilerVersions.V3 As String
  40. ' CodeDomUtil.CompilerVersions.V3_5 As String
  41. ' CodeDomUtil.CompilerVersions.V4 As String
  42.  
  43. ' CodeDomUtil.SubsystemVersions.Windows2000
  44. ' CodeDomUtil.SubsystemVersions.WindowsXP
  45. ' CodeDomUtil.SubsystemVersions.WindowsServer2003
  46. ' CodeDomUtil.SubsystemVersions.WindowsVista
  47. ' CodeDomUtil.SubsystemVersions.Windows7
  48. ' CodeDomUtil.SubsystemVersions.WindowsServer2008
  49. ' CodeDomUtil.SubsystemVersions.Windows8
  50. ' CodeDomUtil.SubsystemVersions.Windows8_1
  51. ' CodeDomUtil.SubsystemVersions.Windows10
  52.  
  53. #End Region
  54.  
  55. #Region " Properties "
  56.  
  57. ' CodeDomUtil.CompilerSettings.CodeProvider As CodeDomProvider
  58. ' CodeDomUtil.CompilerSettings.GenerateDebugInformation As Boolean
  59. ' CodeDomUtil.CompilerSettings.GenerateWarnings As Boolean
  60. ' CodeDomUtil.CompilerSettings.GenerateXmlDocumentation As Boolean
  61. ' CodeDomUtil.CompilerSettings.HighEntropyEnabled As Boolean
  62. ' CodeDomUtil.CompilerSettings.IntegerOverflowChecksEnabled As Boolean
  63. ' CodeDomUtil.CompilerSettings.LibraryPaths As List(Of String)
  64. ' CodeDomUtil.CompilerSettings.OptimizationsEnabled As Boolean
  65. ' CodeDomUtil.CompilerSettings.OutputLanguage As CultureInfo
  66. ' CodeDomUtil.CompilerSettings.Platform As CodeDomUtil.Platform
  67. ' CodeDomUtil.CompilerSettings.SubsystemVersion As String
  68. ' CodeDomUtil.CompilerSettings.TempFileCollection As TempFileCollection
  69. ' CodeDomUtil.CompilerSettings.TreatWarningsAsErrors As Boolean
  70. ' CodeDomUtil.CompilerSettings.Verbose As Boolean
  71. ' CodeDomUtil.CompilerSettings.VerboseSyntax As Boolean
  72. ' CodeDomUtil.CompilerSettings.WarningLevel As WarningLevelEnum
  73.  
  74. ' CodeDomUtil.Compiler.CompilerWorkDoneEventArgs.CodeDomProvider As CodeDomProvider
  75. ' CodeDomUtil.Compiler.CompilerWorkDoneEventArgs.CompileErrors As IEnumerable(Of Compiler.Error)
  76. ' CodeDomUtil.Compiler.CompilerWorkDoneEventArgs.CompilerParameters As CompilerParameters
  77. ' CodeDomUtil.Compiler.CompilerWorkDoneEventArgs.CompilerWarnings As IEnumerable(Of Compiler.Warning)
  78. ' CodeDomUtil.Compiler.CompilerWorkDoneEventArgs.SourceCode As String
  79. ' CodeDomUtil.Compiler.CompilerWorkDoneEventArgs.SourceFilePath As String
  80. ' CodeDomUtil.Compiler.CompilerWorkDoneEventArgs.TargetFilePath As String
  81. ' CodeDomUtil.Compiler.CompilerWorkDoneEventArgs.TempDirectoryPath As String
  82.  
  83. #End Region
  84.  
  85. #Region " Enumerations "
  86.  
  87. ' CodeDomUtil.NetAssembly As Integer
  88. ' CodeDomUtil.WarningLevelEnum As Integer
  89. ' CodeDomUtil.Platform As Integer
  90.  
  91. #End Region
  92.  
  93. #Region " Events "
  94.  
  95. ' CodeDomUtil.Compiler.CompilerWorkDone(Object, CodeDomUtil.Compiler.CompilerWorkDoneEventArgs)
  96. ' CodeDomUtil.VisualBasicCompiler.CompilerWorkDone(Object, CodeDomUtil.Compiler.CompilerWorkDoneEventArgs)
  97. ' CodeDomUtil.CSharpCompiler.CompilerWorkDone(Object, CodeDomUtil.Compiler.CompilerWorkDoneEventArgs)
  98.  
  99. #End Region
  100.  
  101. #Region " Methods "
  102.  
  103. ' CodeDomUtil.Compiler.CompileFromString(CodeDomUtil.NetAssembly, String, String, String, Opt:IEnumerable(Of String), Opt:IEnumerable(Of String), Opt:String)
  104. ' CodeDomUtil.Compiler.CompileFromFile(CodeDomUtil.NetAssembly, String, String, String, Opt:IEnumerable(Of String), Opt:IEnumerable(Of String), Opt:String)
  105.  
  106. ' CodeDomUtil.VisualBasicCompiler.CompileFromString(CodeDomUtil.NetAssembly, String, String, String, Opt:IEnumerable(Of String), Opt:IEnumerable(Of String), Opt:String)
  107. ' CodeDomUtil.VisualBasicCompiler.CompileFromFile(CodeDomUtil.NetAssembly, String, String, String, Opt:IEnumerable(Of String), Opt:IEnumerable(Of String), Opt:String)
  108.  
  109. ' CodeDomUtil.CSharpCompiler.CompileFromString(CodeDomUtil.NetAssembly, String, String, String, Opt:IEnumerable(Of String), Opt:IEnumerable(Of String), Opt:String)
  110. ' CodeDomUtil.CSharpCompiler.CompileFromFile(CodeDomUtil.NetAssembly, String, String, String, Opt:IEnumerable(Of String), Opt:IEnumerable(Of String), Opt:String)
  111.  
  112. #End Region
  113.  
  114. #End Region
  115.  
  116. #Region " Option Statements "
  117.  
  118. Option Strict On
  119. Option Explicit On
  120. Option Infer Off
  121.  
  122. #End Region
  123.  
  124. #Region " Imports "
  125.  
  126. Imports Microsoft.CSharp
  127. Imports Microsoft.VisualBasic
  128. Imports System
  129. Imports System.Collections.Generic
  130. Imports System.IO
  131. Imports System.CodeDom.Compiler
  132. Imports System.Linq
  133.  
  134. #End Region
  135.  
  136. #Region " CodeDom Util "
  137.  
  138. ''' ----------------------------------------------------------------------------------------------------
  139. ''' <summary>
  140. ''' Contains related CodeDom utilities to compile .Net assemblies.
  141. ''' </summary>
  142. ''' ----------------------------------------------------------------------------------------------------
  143. Public NotInheritable Class CodeDomUtil
  144.  
  145. #Region " Enumerations "
  146.  
  147.     ''' ----------------------------------------------------------------------------------------------------
  148.     ''' <summary>
  149.     ''' Specifies a <see cref="CompilerParameters"></see> target assembly.
  150.     ''' </summary>
  151.     ''' ----------------------------------------------------------------------------------------------------
  152.     Public Enum NetAssembly As Integer
  153.  
  154.         ''' ----------------------------------------------------------------------------------------------------
  155.         ''' <summary>
  156.         ''' An executable console application or Command line interface (CLI).
  157.         ''' The output file is created with an extension of .exe.
  158.         ''' </summary>
  159.         ''' ----------------------------------------------------------------------------------------------------
  160.         Console = 0
  161.  
  162.         ''' ----------------------------------------------------------------------------------------------------
  163.         ''' <summary>
  164.         ''' An executable Windows-based application or Graphical user interface (GUI).
  165.         ''' The output file is created with an extension of .exe.
  166.         ''' </summary>
  167.         ''' ----------------------------------------------------------------------------------------------------
  168.         WinExe = 1
  169.  
  170.         ''' ----------------------------------------------------------------------------------------------------
  171.         ''' <summary>
  172.         ''' An executable Windows-based application that must be run in an app container.
  173.         ''' This setting is designed to be used for Windows 8.x Store applications.
  174.         ''' The output file is created with an extension of .exe.
  175.         ''' </summary>
  176.         ''' ----------------------------------------------------------------------------------------------------
  177.         WinExeContainer = 2
  178.  
  179.         ''' ----------------------------------------------------------------------------------------------------
  180.         ''' <summary>
  181.         ''' An intermediate file that you can convert to a Windows Runtime binary (.winmd) file.
  182.         ''' The .winmd file can be consumed by JavaScript and C++ programs, in addition to managed language programs.
  183.         ''' The output file name takes the name of the input file.
  184.         ''' </summary>
  185.         ''' ----------------------------------------------------------------------------------------------------
  186.         WinMdObj = 3
  187.  
  188.         ''' ----------------------------------------------------------------------------------------------------
  189.         ''' <summary>
  190.         ''' A Dynamic-link library.
  191.         ''' The output file is created with an extension of .dll.
  192.         ''' </summary>
  193.         ''' ----------------------------------------------------------------------------------------------------
  194.         DynamicLinkLibrary = 4
  195.  
  196.         ''' ----------------------------------------------------------------------------------------------------
  197.         ''' <summary>
  198.         ''' A module that can be added to an assembly.
  199.         ''' The output file is created with an extension of .netmodule.
  200.         ''' </summary>
  201.         ''' ----------------------------------------------------------------------------------------------------
  202.         [Module] = 5
  203.  
  204.     End Enum
  205.  
  206.     ''' ----------------------------------------------------------------------------------------------------
  207.     ''' <summary>
  208.     ''' Specifies the level at which the compiler should start displaying warnings.
  209.     ''' </summary>
  210.     ''' ----------------------------------------------------------------------------------------------------
  211.     Public Enum WarningLevelEnum As Integer
  212.  
  213.         ''' ----------------------------------------------------------------------------------------------------
  214.         ''' <summary>
  215.         '''  Turns off emission of all warning messages.
  216.         ''' </summary>
  217.         ''' ----------------------------------------------------------------------------------------------------
  218.         None = 0
  219.  
  220.         ''' ----------------------------------------------------------------------------------------------------
  221.         ''' <summary>
  222.         ''' Displays severe warning messages.
  223.         ''' </summary>
  224.         ''' ----------------------------------------------------------------------------------------------------
  225.         Level1 = 1
  226.  
  227.         ''' ----------------------------------------------------------------------------------------------------
  228.         ''' <summary>
  229.         ''' Displays level 1 warnings plus certain, less-severe warnings,
  230.         ''' such as warnings about hiding class members.
  231.         ''' </summary>
  232.         ''' ----------------------------------------------------------------------------------------------------
  233.         Level2 = 2
  234.  
  235.         ''' ----------------------------------------------------------------------------------------------------
  236.         ''' <summary>
  237.         ''' Displays level 2 warnings plus certain, less-severe warnings,
  238.         ''' such as warnings about expressions that always evaluate to true or false.
  239.         ''' </summary>
  240.         ''' ----------------------------------------------------------------------------------------------------
  241.         Level3 = 3
  242.  
  243.         ''' ----------------------------------------------------------------------------------------------------
  244.         ''' <summary>
  245.         ''' Displays all level 3 warnings plus informational warnings.
  246.         ''' This is the default warning level at the command line.
  247.         ''' </summary>
  248.         ''' ----------------------------------------------------------------------------------------------------
  249.         Level4 = 4
  250.  
  251.     End Enum
  252.  
  253.     ''' ----------------------------------------------------------------------------------------------------
  254.     ''' <summary>
  255.     ''' Specifies a platform version of common language runtime (CLR).
  256.     ''' </summary>
  257.     ''' ----------------------------------------------------------------------------------------------------
  258.     Public Enum Platform As Integer
  259.  
  260.         ''' <summary>
  261.         ''' An assembly to run on any platform.
  262.         ''' The application will run as a 32-bit application on 32-bit versions of Windows and as a 64-bit application on 64-bit versions of Windows.
  263.         ''' This flag is the default value.
  264.         ''' </summary>
  265.         AnyCpu = 0
  266.  
  267.         ''' <summary>
  268.         ''' An assembly to run on any platform.
  269.         ''' The assembly will run as a 32-bit application on both 32-bit and 64-bit versions of Windows.
  270.         ''' This flag is valid only for executables (.EXE) and requires .NET Framework 4.5.
  271.         ''' </summary>
  272.         AnyCpu32bitPreferred = 1
  273.  
  274.         ''' <summary>
  275.         ''' An assembly to be run by the 32-bit, x86-compatible CLR.
  276.         ''' </summary>
  277.         X86 = 2
  278.  
  279.         ''' <summary>
  280.         ''' An assembly to be run by the 64-bit CLR on a computer that supports the AMD64 or EM64T instruction set.
  281.         ''' </summary>
  282.         X64 = 3
  283.  
  284.         ''' <summary>
  285.         ''' An assembly to be run by the 64-bit CLR on a computer with an Itanium processor.
  286.         ''' </summary>
  287.         Itanium = 4
  288.  
  289.         ''' <summary>
  290.         ''' An assembly to be run on a computer with an ARM (Advanced RISC Machine) processor.
  291.         ''' </summary>
  292.         Arm = 5
  293.  
  294.     End Enum
  295.  
  296. #End Region
  297.  
  298. #Region " Constructors "
  299.  
  300.     ''' <summary>
  301.     ''' Prevents a default instance of the <see cref="CodeDomUtil"/> class from being created.
  302.     ''' </summary>
  303.     Private Sub New()
  304.     End Sub
  305.  
  306. #End Region
  307.  
  308. #Region " Child Classes "
  309.  
  310. #Region " Templates "
  311.  
  312.     ''' ----------------------------------------------------------------------------------------------------
  313.     ''' <summary>
  314.     ''' Defines default application templates.
  315.     ''' </summary>
  316.     ''' ----------------------------------------------------------------------------------------------------
  317.     Public Class Templates
  318.  
  319. #Region " Constants / Read-Onlys "
  320.  
  321.         ''' ----------------------------------------------------------------------------------------------------
  322.         ''' <summary>
  323.         ''' A sourcecode template of a console application written in Visual Basic.Net.
  324.         ''' </summary>
  325.         ''' ----------------------------------------------------------------------------------------------------
  326.         Public Shared ReadOnly TemplateVbConsoleApp As String =
  327.     <a><![CDATA[
  328. Imports System
  329.  
  330. Namespace MainNamespace
  331.  
  332.     Module MainModule
  333.        
  334.         ''' <summary>
  335.         ''' The main entry point for the application.
  336.         ''' </summary>
  337.         Sub Main()
  338.             Console.WriteLine("VisualBasic.Net ConsoleApp Template.")
  339.         End Sub
  340.  
  341.     End Module
  342.  
  343. End Namespace
  344. ]]></a>.Value
  345.  
  346.         ''' ----------------------------------------------------------------------------------------------------
  347.         ''' <summary>
  348.         ''' A sourcecode template of a WindowsForms application written in Visual Basic.Net.
  349.         ''' </summary>
  350.         ''' ----------------------------------------------------------------------------------------------------
  351.         Public Shared ReadOnly TemplateVbWinFormsApp As String =
  352.     <a><![CDATA[
  353. Imports System
  354. Imports System.Windows.Forms
  355.  
  356. Namespace MainNamespace
  357.  
  358.     Public NotInheritable Class MainClass : Inherits Form
  359.  
  360.         Public Sub New()
  361.             Me.StartPosition = FormStartPosition.CenterScreen
  362.         End Sub
  363.  
  364.         Private Sub Form1_Shown(ByVal sender As Object, ByVal e As EventArgs) _
  365.         Handles MyBase.Shown
  366.  
  367.             MessageBox.Show("VisualBasic.Net WinForms Template.")
  368.  
  369.         End Sub
  370.  
  371.     End Class
  372.  
  373. End Namespace
  374. ]]></a>.Value
  375.  
  376.         ''' ----------------------------------------------------------------------------------------------------
  377.         ''' <summary>
  378.         ''' A sourcecode template of a library written in Visual Basic.Net.
  379.         ''' </summary>
  380.         ''' ----------------------------------------------------------------------------------------------------
  381.         Public Shared ReadOnly TemplateVbLib As String =
  382.     <a><![CDATA[
  383. Imports System
  384.  
  385. Namespace MainNamespace
  386.  
  387.     Public NotInheritable Class MainClass
  388.  
  389.         Private Sub New()
  390.         End Sub
  391.  
  392.         Public Shared Function MyFunction(ByVal value As Object) As Object
  393.             Return value
  394.         End Function
  395.  
  396.     End Class
  397.  
  398. End Namespace
  399. ]]></a>.Value
  400.  
  401.         ''' ----------------------------------------------------------------------------------------------------
  402.         ''' <summary>
  403.         ''' A sourcecode template of a console application written in C#.
  404.         ''' </summary>
  405.         ''' ----------------------------------------------------------------------------------------------------
  406.         Public Shared ReadOnly TemplateCsConsoleApp As String =
  407.     <a><![CDATA[
  408. using System;
  409.  
  410. namespace MainNamespace
  411. {
  412.     class MainClass
  413.     {
  414.         static void Main(string[] args)
  415.         {
  416.             Console.WriteLine("C# ConsoleApp Template.");
  417.         }
  418.     }
  419. }
  420. ]]></a>.Value
  421.  
  422.         ''' ----------------------------------------------------------------------------------------------------
  423.         ''' <summary>
  424.         ''' A sourcecode template of a WindowsForms application written in C#.
  425.         ''' </summary>
  426.         ''' ----------------------------------------------------------------------------------------------------
  427.         Public Shared ReadOnly TemplateCsWinFormsApp As String =
  428.     <a><![CDATA[
  429. using System;
  430. using System.Windows.Forms;
  431.  
  432. namespace MainNamespace
  433. {
  434.     public partial class MainClass : Form
  435.     {
  436.  
  437.         /// <summary>
  438.         /// The main entry point for the application.
  439.         /// </summary>
  440.         [STAThread]
  441.         static void Main()
  442.         {
  443.             Application.EnableVisualStyles();
  444.             Application.SetCompatibleTextRenderingDefault(false);
  445.             Application.Run(new MainClass());
  446.         }
  447.  
  448.         public MainClass()
  449.         {
  450.             Shown += Form1_Shown;
  451.             this.StartPosition = FormStartPosition.CenterScreen;
  452.         }
  453.  
  454.         private void Form1_Shown(object sender, EventArgs e)
  455.         {
  456.             MessageBox.Show("C# WinForms Template.");
  457.         }
  458.        
  459.     }
  460. }
  461. ]]></a>.Value
  462.  
  463.         ''' ----------------------------------------------------------------------------------------------------
  464.         ''' <summary>
  465.         ''' A sourcecode template of a library written in C#.
  466.         ''' </summary>
  467.         ''' ----------------------------------------------------------------------------------------------------
  468.         Public Shared ReadOnly TemplateCsLib As String =
  469.     <a><![CDATA[
  470. using System;
  471.  
  472. namespace MainNamespace
  473. {
  474.  
  475.     public sealed class MainClass
  476.     {
  477.  
  478.         private MainClass()
  479.         {}
  480.  
  481.         public static object MyFunction(object value)
  482.         {
  483.             return value;
  484.         }
  485.  
  486.     }
  487.  
  488. }
  489. ]]></a>.Value
  490.  
  491. #End Region
  492.  
  493.     End Class
  494.  
  495. #End Region
  496.  
  497. #Region " Compiler Versions "
  498.  
  499.     ''' ----------------------------------------------------------------------------------------------------
  500.     ''' <summary>
  501.     ''' Exposes .NetFx compiler versions.
  502.     ''' </summary>
  503.     ''' ----------------------------------------------------------------------------------------------------
  504.     Public NotInheritable Class CompilerVersions
  505.  
  506. #Region " Constants "
  507.  
  508.         ''' <summary>
  509.         ''' The .NetFx compiler version 1.
  510.         ''' </summary>
  511.         Public Const V1 As String = "1.0"
  512.  
  513.         ''' <summary>
  514.         ''' The .NetFx compiler version 2.
  515.         ''' </summary>
  516.         Public Const V2 As String = "2.0"
  517.  
  518.         ''' <summary>
  519.         ''' The .NetFx compiler version 3.
  520.         ''' </summary>
  521.         Public Const V3 As String = "3.0"
  522.  
  523.         ''' <summary>
  524.         ''' The .NetFx compiler version 3.5.
  525.         ''' </summary>
  526.         Public Const V3_5 As String = "3.5"
  527.  
  528.         ''' <summary>
  529.         ''' The .NetFx compiler version 4.
  530.         ''' </summary>
  531.         Public Const V4 As String = "4.0"
  532.  
  533. #End Region
  534.  
  535. #Region " Constructors "
  536.  
  537.         ''' <summary>
  538.         ''' Prevents a default instance of the <see cref="CompilerVersions"/> class from being created.
  539.         ''' </summary>
  540.         Private Sub New()
  541.         End Sub
  542.  
  543. #End Region
  544.  
  545.     End Class
  546.  
  547. #End Region
  548.  
  549. #Region " Subsystem Versions "
  550.  
  551.     ''' ----------------------------------------------------------------------------------------------------
  552.     ''' <summary>
  553.     ''' Exposes Windows subsystem versions.
  554.     ''' </summary>
  555.     ''' ----------------------------------------------------------------------------------------------------
  556.     Public NotInheritable Class SubsystemVersions
  557.  
  558. #Region " Constants "
  559.  
  560.         ''' <summary>
  561.         ''' Windows 2000 operating system.
  562.         ''' </summary>
  563.         Public Const Windows2000 As String = "5.00"
  564.  
  565.         ''' <summary>
  566.         ''' Windows 2000 operating system.
  567.         ''' </summary>
  568.         Public Const WindowsXP As String = "5.01"
  569.  
  570.         ''' <summary>
  571.         ''' Windows 2000 operating system.
  572.         ''' </summary>
  573.         Public Const WindowsServer2003 As String = "5.02"
  574.  
  575.         ''' <summary>
  576.         ''' Windows 2000 operating system.
  577.         ''' </summary>
  578.         Public Const WindowsVista As String = "6.00"
  579.  
  580.         ''' <summary>
  581.         ''' Windows 2000 operating system.
  582.         ''' </summary>
  583.         Public Const Windows7 As String = "6.01"
  584.  
  585.         ''' <summary>
  586.         ''' Windows 2000 operating system.
  587.         ''' </summary>
  588.         Public Const WindowsServer2008 As String = SubsystemVersions.Windows7
  589.  
  590.         ''' <summary>
  591.         ''' Windows 8 operating system.
  592.         ''' </summary>
  593.         Public Const Windows8 As String = "6.02"
  594.  
  595.         ''' <summary>
  596.         ''' Windows 8.1 operating system.
  597.         ''' </summary>
  598.         Public Const Windows8_1 As String = SubsystemVersions.Windows8
  599.  
  600.         ''' <summary>
  601.         ''' Windows 2000 operating system.
  602.         ''' </summary>
  603.         Public Const Windows10 As String = "10.00"
  604.  
  605. #End Region
  606.  
  607. #Region " Constructors "
  608.  
  609.         ''' <summary>
  610.         ''' Prevents a default instance of the <see cref="SubsystemVersions"/> class from being created.
  611.         ''' </summary>
  612.         Private Sub New()
  613.         End Sub
  614.  
  615. #End Region
  616.  
  617.     End Class
  618.  
  619. #End Region
  620.  
  621. #Region " CompilerSettings "
  622.  
  623.     ''' ----------------------------------------------------------------------------------------------------
  624.     ''' <summary>
  625.     ''' Defines the settings of a <see cref="CodeDomUtil.Compiler"/>
  626.     ''' </summary>
  627.     ''' ----------------------------------------------------------------------------------------------------
  628.     Public Class CompilerSettings
  629.  
  630. #Region " Properties "
  631.  
  632.         ''' ----------------------------------------------------------------------------------------------------
  633.         ''' <summary>
  634.         ''' Gets or sets the code provider.
  635.         ''' </summary>
  636.         ''' ----------------------------------------------------------------------------------------------------
  637.         ''' <value>
  638.         ''' The code provider.
  639.         ''' </value>
  640.         ''' ----------------------------------------------------------------------------------------------------
  641.         Public Property CodeProvider As CodeDomProvider
  642.  
  643.         ''' ----------------------------------------------------------------------------------------------------
  644.         ''' <summary>
  645.         ''' Gets or sets the level at which the compiler should start displaying warnings.
  646.         ''' </summary>
  647.         ''' ----------------------------------------------------------------------------------------------------
  648.         ''' <value>
  649.         ''' The level at which the compiler should start displaying warnings.
  650.         ''' </value>
  651.         ''' ----------------------------------------------------------------------------------------------------
  652.         Public Property WarningLevel As WarningLevelEnum = CodeDomUtil.WarningLevelEnum.Level3
  653.  
  654.         ''' ----------------------------------------------------------------------------------------------------
  655.         ''' <summary>
  656.         ''' Gets or sets a value instructs the compiler to treat warnings as errors.
  657.         ''' </summary>
  658.         ''' ----------------------------------------------------------------------------------------------------
  659.         ''' <value>
  660.         ''' <c>True</c> if warnings are treated as errors; otherwise, <c>False</c>.
  661.         ''' </value>
  662.         ''' ----------------------------------------------------------------------------------------------------
  663.         Public Property TreatWarningsAsErrors As Boolean = False
  664.  
  665.         ''' ----------------------------------------------------------------------------------------------------
  666.         ''' <summary>
  667.         ''' Gets or sets a value that instructs the compiler to generate debug information file (pdb).
  668.         ''' </summary>
  669.         ''' ----------------------------------------------------------------------------------------------------
  670.         ''' <value>
  671.         ''' <c>True</c> if debug information is enabled; otherwise, <c>False</c>.
  672.         ''' </value>
  673.         ''' ----------------------------------------------------------------------------------------------------
  674.         Public Property GenerateDebugInformation As Boolean = False
  675.  
  676.         ''' ----------------------------------------------------------------------------------------------------
  677.         ''' <summary>
  678.         ''' Gets or sets a value that instructs the compiler to generate Xml documentation file
  679.         ''' </summary>
  680.         ''' ----------------------------------------------------------------------------------------------------
  681.         ''' <value>
  682.         ''' <c>True</c> if Xml documentation is enabled; otherwise, <c>False</c>.
  683.         ''' </value>
  684.         ''' ----------------------------------------------------------------------------------------------------
  685.         Public Property GenerateXmlDocumentation As Boolean = False
  686.  
  687.         ''' ----------------------------------------------------------------------------------------------------
  688.         ''' <summary>
  689.         ''' Gets or sets a value that instructs the compiler to produce verbose status and error messages.
  690.         ''' </summary>
  691.         ''' ----------------------------------------------------------------------------------------------------
  692.         ''' <value>
  693.         ''' <c>True</c> if verbose enabled; otherwise, <c>False</c>.
  694.         ''' </value>
  695.         ''' ----------------------------------------------------------------------------------------------------
  696.         Public Property Verbose As Boolean = False
  697.  
  698.         ''' ----------------------------------------------------------------------------------------------------
  699.         ''' <summary>
  700.         ''' Gets or sets a value that instructs the compiler from displaying code for syntax-related errors and warnings.
  701.         ''' </summary>
  702.         ''' ----------------------------------------------------------------------------------------------------
  703.         ''' <value>
  704.         ''' <c>True</c> if syntax-verbose enabled; otherwise, <c>False</c>.
  705.         ''' </value>
  706.         ''' ----------------------------------------------------------------------------------------------------
  707.         Public Property VerboseSyntax As Boolean = False
  708.  
  709.         ''' ----------------------------------------------------------------------------------------------------
  710.         ''' <summary>
  711.         ''' Gets or sets the language that the compiler will use to display the output messages.
  712.         ''' This option is only avaliable for C# compiler.
  713.         ''' </summary>
  714.         ''' ----------------------------------------------------------------------------------------------------
  715.         ''' <value>
  716.         ''' The language that the compiler will use to display the output messages.
  717.         ''' </value>
  718.         ''' ----------------------------------------------------------------------------------------------------
  719.         Public Property OutputLanguage As CultureInfo
  720.  
  721.         ''' ----------------------------------------------------------------------------------------------------
  722.         ''' <summary>
  723.         ''' Gets or sets a value that enables or disables compiler optimizations.
  724.         ''' </summary>
  725.         ''' ----------------------------------------------------------------------------------------------------
  726.         ''' <value>
  727.         ''' <c>True</c> if compiler optimizations are enabled; otherwise, <c>False</c>.
  728.         ''' </value>
  729.         ''' ----------------------------------------------------------------------------------------------------
  730.         Public Property OptimizationsEnabled As Boolean = True
  731.  
  732.         ''' ----------------------------------------------------------------------------------------------------
  733.         ''' <summary>
  734.         ''' Gets or sets a value that instructs the compiler to be able to generate warnings.
  735.         ''' </summary>
  736.         ''' ----------------------------------------------------------------------------------------------------
  737.         ''' <value>
  738.         ''' <c>True</c> if warnings are enabled; otherwise, <c>False</c>.
  739.         ''' </value>
  740.         ''' ----------------------------------------------------------------------------------------------------
  741.         Public Property GenerateWarnings As Boolean = True
  742.  
  743.         ''' ----------------------------------------------------------------------------------------------------
  744.         ''' <summary>
  745.         ''' Gets or sets a value that indicates whether a 64-bit executable or an executable that's marked by the
  746.         ''' <see cref="CodeDomUtil.Platform.AnyCpu"/> compiler option supports high entropy Address Space Layout Randomization (ASLR).
  747.         ''' </summary>
  748.         ''' ----------------------------------------------------------------------------------------------------
  749.         ''' <value>
  750.         ''' <c>True</c> if high entropy is enabled; otherwise, <c>False</c>.
  751.         ''' </value>
  752.         ''' ----------------------------------------------------------------------------------------------------
  753.         Public Property HighEntropyEnabled As Boolean = True
  754.  
  755.         ''' ----------------------------------------------------------------------------------------------------
  756.         ''' <summary>
  757.         ''' Gets or sets a value that turns overflow-error checking for integer operations on or off.
  758.         ''' </summary>
  759.         ''' ----------------------------------------------------------------------------------------------------
  760.         ''' <value>
  761.         ''' <c>True</c> if integer overflow checks are enabled; otherwise, <c>False</c>.
  762.         ''' </value>
  763.         ''' ----------------------------------------------------------------------------------------------------
  764.         Public Property IntegerOverflowChecksEnabled As Boolean = False
  765.  
  766.         ''' ----------------------------------------------------------------------------------------------------
  767.         ''' <summary>
  768.         ''' Gets or sets a value that specifies the minimum version of the subsystem on which the generated executable file can run,
  769.         ''' thereby determining the versions of Windows on which the executable file can run.
  770.         ''' Most commonly, this option ensures that the executable file can leverage particular security features that aren’t available
  771.         ''' with older versions of Windows.
  772.         ''' </summary>
  773.         ''' ----------------------------------------------------------------------------------------------------
  774.         ''' <value>
  775.         ''' The subsystem on which the generated executable file can run.
  776.         ''' </value>
  777.         ''' ----------------------------------------------------------------------------------------------------
  778.         Public Property SubsystemVersion As String = CodeDomUtil.SubsystemVersions.Windows2000
  779.  
  780.         ''' ----------------------------------------------------------------------------------------------------
  781.         ''' <summary>
  782.         ''' Gets or sets a value that specifies which platform version of common language runtime (CLR) can run the output file.
  783.         ''' </summary>
  784.         ''' ----------------------------------------------------------------------------------------------------
  785.         ''' <value>
  786.         ''' The platform version of common language runtime (CLR) which can run the output file.
  787.         ''' </value>
  788.         ''' ----------------------------------------------------------------------------------------------------
  789.         Public Property Platform As CodeDomUtil.Platform = CodeDomUtil.Platform.AnyCpu
  790.  
  791.         ''' ----------------------------------------------------------------------------------------------------
  792.         ''' <summary>
  793.         ''' Gets or sets a value that specifies additional directories in which to search for assembly references.
  794.         ''' </summary>
  795.         ''' ----------------------------------------------------------------------------------------------------
  796.         ''' <value>
  797.         ''' A value that specifies additional directories in which to search for assembly references
  798.         ''' </value>
  799.         ''' ----------------------------------------------------------------------------------------------------
  800.         Public Property LibraryPaths As List(Of String)
  801.  
  802.         ''' ----------------------------------------------------------------------------------------------------
  803.         ''' <summary>
  804.         ''' Gets or sets the temporary files collection where the compiler stores the temporary files generated during a build.
  805.         ''' </summary>
  806.         ''' ----------------------------------------------------------------------------------------------------
  807.         ''' <value>
  808.         ''' The temporary files collection where the compiler stores the temporary files generated during a build.
  809.         ''' </value>
  810.         ''' ----------------------------------------------------------------------------------------------------
  811.         Public Property TempFileCollection As TempFileCollection
  812.  
  813. #End Region
  814.  
  815. #Region " Constructors "
  816.  
  817.         ''' ----------------------------------------------------------------------------------------------------
  818.         ''' <summary>
  819.         ''' Initializes a new instance of the <see cref="CompilerSettings"/> class.
  820.         ''' </summary>
  821.         ''' ----------------------------------------------------------------------------------------------------
  822.         Public Sub New()
  823.  
  824.             Me.LibraryPaths = New List(Of String)
  825.             Me.OutputLanguage = New CultureInfo("en-US")
  826.             Me.TempFileCollection = New TempFileCollection(tempdir:=Path.GetTempPath(), keepFiles:=True)
  827.  
  828.         End Sub
  829.  
  830. #End Region
  831.  
  832.     End Class
  833.  
  834. #End Region
  835.  
  836. #Region " Compiler "
  837.  
  838.     ''' ----------------------------------------------------------------------------------------------------
  839.     ''' <summary>
  840.     ''' Encapsulates a CodeDom provider compiler.
  841.     ''' </summary>
  842.     ''' ----------------------------------------------------------------------------------------------------
  843.     Public Class Compiler
  844.  
  845. #Region " Properties "
  846.  
  847.         ''' ----------------------------------------------------------------------------------------------------
  848.         ''' <summary>
  849.         ''' Gets or sets the the settings of this <see cref="CodeDomUtil.Compiler"/>.
  850.         ''' </summary>
  851.         ''' ----------------------------------------------------------------------------------------------------
  852.         ''' <value>
  853.         ''' The settings of this <see cref="CodeDomUtil.Compiler"/>
  854.         ''' </value>.
  855.         ''' ----------------------------------------------------------------------------------------------------
  856.         Public Overridable Property Compilersettings As CompilerSettings
  857.  
  858. #End Region
  859.  
  860. #Region " Events "
  861.  
  862.         ''' ----------------------------------------------------------------------------------------------------
  863.         ''' <summary>
  864.         ''' Occurs when the compiler finishes.
  865.         ''' </summary>
  866.         ''' ----------------------------------------------------------------------------------------------------
  867.         Public Event CompilerWorkDone As EventHandler(Of CompilerWorkDoneEventArgs)
  868.  
  869. #Region " CompilerWorkDone Args. "
  870.  
  871.         ''' ----------------------------------------------------------------------------------------------------
  872.         ''' <summary>
  873.         ''' Defines the event-data of a <see cref="CompilerWorkDone"/> event.
  874.         ''' </summary>
  875.         ''' ----------------------------------------------------------------------------------------------------
  876.         Public NotInheritable Class CompilerWorkDoneEventArgs : Inherits EventArgs
  877.  
  878. #Region " Properties "
  879.  
  880.             ''' ----------------------------------------------------------------------------------------------------
  881.             ''' <summary>
  882.             ''' Gets the <see cref="CodeDomProvider"/>.
  883.             ''' </summary>
  884.             ''' ----------------------------------------------------------------------------------------------------
  885.             ''' <value>
  886.             ''' The <see cref="CodeDomProvider"/>.
  887.             ''' </value>
  888.             ''' ----------------------------------------------------------------------------------------------------
  889.             Public ReadOnly Property CodeDomProvider As CodeDomProvider
  890.                 Get
  891.                     Return Me.codeDomProviderB
  892.                 End Get
  893.             End Property
  894.             ''' ----------------------------------------------------------------------------------------------------
  895.             ''' <summary>
  896.             ''' ( Backing Field )
  897.             ''' The <see cref="CodeDomProvider"/>.
  898.             ''' </summary>
  899.             ''' ----------------------------------------------------------------------------------------------------
  900.             Private ReadOnly codeDomProviderB As CodeDomProvider
  901.  
  902.             ''' ----------------------------------------------------------------------------------------------------
  903.             ''' <summary>
  904.             ''' Gets the compiler parameters used to build the target file.
  905.             ''' </summary>
  906.             ''' ----------------------------------------------------------------------------------------------------
  907.             ''' <value>
  908.             ''' The compiler parameters used to build the target file.
  909.             ''' </value>
  910.             ''' ----------------------------------------------------------------------------------------------------
  911.             Public ReadOnly Property CompilerParameters As CompilerParameters
  912.                 Get
  913.                     Return Me.compilerParametersB
  914.                 End Get
  915.             End Property
  916.             ''' ----------------------------------------------------------------------------------------------------
  917.             ''' <summary>
  918.             ''' ( Backing Field )
  919.             ''' The compiler parameters used to build the target file.
  920.             ''' </summary>
  921.             ''' ----------------------------------------------------------------------------------------------------
  922.             Private ReadOnly compilerParametersB As CompilerParameters
  923.  
  924.             ''' ----------------------------------------------------------------------------------------------------
  925.             ''' <summary>
  926.             ''' Gets the compiler warnings.
  927.             ''' </summary>
  928.             ''' ----------------------------------------------------------------------------------------------------
  929.             ''' <value>
  930.             ''' The compiler warnings.
  931.             ''' </value>
  932.             ''' ----------------------------------------------------------------------------------------------------
  933.             Public ReadOnly Property CompilerWarnings As IEnumerable(Of Compiler.Warning)
  934.                 Get
  935.                     Return Me.compilerWarningsB
  936.                 End Get
  937.             End Property
  938.             ''' ----------------------------------------------------------------------------------------------------
  939.             ''' <summary>
  940.             ''' ( Backing Field )
  941.             ''' The compiler warnings.
  942.             ''' </summary>
  943.             ''' ----------------------------------------------------------------------------------------------------
  944.             Private ReadOnly compilerWarningsB As IEnumerable(Of Compiler.Warning)
  945.  
  946.             ''' ----------------------------------------------------------------------------------------------------
  947.             ''' <summary>
  948.             ''' Gets the compiler errors.
  949.             ''' </summary>
  950.             ''' ----------------------------------------------------------------------------------------------------
  951.             ''' <value>
  952.             ''' The compiler errors.
  953.             ''' </value>
  954.             ''' ----------------------------------------------------------------------------------------------------
  955.             Public ReadOnly Property CompileErrors As IEnumerable(Of Compiler.Error)
  956.                 Get
  957.                     Return Me.compileErrorsB
  958.                 End Get
  959.             End Property
  960.             ''' ----------------------------------------------------------------------------------------------------
  961.             ''' <summary>
  962.             ''' ( Backing Field )
  963.             ''' The compiler errors.
  964.             ''' </summary>
  965.             ''' ----------------------------------------------------------------------------------------------------
  966.             Private ReadOnly compileErrorsB As IEnumerable(Of Compiler.Error)
  967.  
  968.             ''' ----------------------------------------------------------------------------------------------------
  969.             ''' <summary>
  970.             ''' Gets the source code string. Only when a string is used to compile.
  971.             ''' </summary>
  972.             ''' ----------------------------------------------------------------------------------------------------
  973.             ''' <value>
  974.             ''' The source code string. Only when a string is used to compile.
  975.             ''' </value>
  976.             ''' ----------------------------------------------------------------------------------------------------
  977.             Public ReadOnly Property SourceCode As String
  978.                 Get
  979.                     Return Me.sourceCodeB
  980.                 End Get
  981.             End Property
  982.             ''' ----------------------------------------------------------------------------------------------------
  983.             ''' <summary>
  984.             ''' ( Backing Field )
  985.             ''' The source code string.
  986.             ''' </summary>
  987.             ''' ----------------------------------------------------------------------------------------------------
  988.             Private ReadOnly sourceCodeB As String
  989.  
  990.             ''' ----------------------------------------------------------------------------------------------------
  991.             ''' <summary>
  992.             ''' Gets the source filepath. Only when a file is used to compile.
  993.             ''' </summary>
  994.             ''' ----------------------------------------------------------------------------------------------------
  995.             ''' <value>
  996.             ''' The source filepath. Only when a file is used to compile.
  997.             ''' </value>
  998.             ''' ----------------------------------------------------------------------------------------------------
  999.             Public ReadOnly Property SourceFilePath As String
  1000.                 Get
  1001.                     Return Me.sourceFilePathB
  1002.                 End Get
  1003.             End Property
  1004.             ''' ----------------------------------------------------------------------------------------------------
  1005.             ''' <summary>
  1006.             ''' ( Backing Field )
  1007.             ''' The source filepath. Only when a file is used to compile.
  1008.             ''' </summary>
  1009.             ''' ----------------------------------------------------------------------------------------------------
  1010.             Private ReadOnly sourceFilePathB As String
  1011.  
  1012.             ''' ----------------------------------------------------------------------------------------------------
  1013.             ''' <summary>
  1014.             ''' Gets the target .Net assembly filepath.
  1015.             ''' </summary>
  1016.             ''' ----------------------------------------------------------------------------------------------------
  1017.             ''' <value>
  1018.             ''' The target .Net assembly filepath.
  1019.             ''' </value>
  1020.             ''' ----------------------------------------------------------------------------------------------------
  1021.             Public ReadOnly Property TargetFilePath As String
  1022.                 Get
  1023.                     Return Me.targetFilePathB
  1024.                 End Get
  1025.             End Property
  1026.             ''' ----------------------------------------------------------------------------------------------------
  1027.             ''' <summary>
  1028.             ''' ( Backing Field )
  1029.             ''' The target .Net assembly filepath.
  1030.             ''' </summary>
  1031.             ''' ----------------------------------------------------------------------------------------------------
  1032.             Private ReadOnly targetFilePathB As String
  1033.  
  1034.             ''' ----------------------------------------------------------------------------------------------------
  1035.             ''' <summary>
  1036.             ''' Gets the temporary files path used for the compiler.
  1037.             ''' </summary>
  1038.             ''' ----------------------------------------------------------------------------------------------------
  1039.             ''' <value>
  1040.             ''' The temporary files path used for the compiler.
  1041.             ''' </value>
  1042.             ''' ----------------------------------------------------------------------------------------------------
  1043.             Public ReadOnly Property TempDirectoryPath As String
  1044.                 Get
  1045.                     Return Me.tempDirectoryPathB
  1046.                 End Get
  1047.             End Property
  1048.             ''' ----------------------------------------------------------------------------------------------------
  1049.             ''' <summary>
  1050.             ''' ( Backing Field )
  1051.             ''' The temporary files path used for the compiler.
  1052.             ''' </summary>
  1053.             ''' ----------------------------------------------------------------------------------------------------
  1054.             Private ReadOnly tempDirectoryPathB As String
  1055.  
  1056. #End Region
  1057.  
  1058. #Region " Constructors "
  1059.  
  1060.             ''' ----------------------------------------------------------------------------------------------------
  1061.             ''' <summary>
  1062.             ''' Initializes a new instance of the <see cref="CompilerWorkDoneEventArgs"/> class.
  1063.             ''' </summary>
  1064.             ''' ----------------------------------------------------------------------------------------------------
  1065.             ''' <param name="codeDomProvider">
  1066.             ''' The CodeDom provider.
  1067.             ''' </param>
  1068.             '''
  1069.             ''' <param name="compilerParameters">
  1070.             ''' The compiler parameters used to build the target file.
  1071.             ''' </param>
  1072.             '''
  1073.             ''' <param name="compilerWarnings">
  1074.             ''' The compiler warnings.
  1075.             ''' </param>
  1076.             '''
  1077.             ''' <param name="compileErrors">
  1078.             ''' The compile errors.
  1079.             ''' </param>
  1080.             '''
  1081.             ''' <param name="sourceCode">
  1082.             ''' The source code string (if any).
  1083.             ''' </param>
  1084.             '''
  1085.             ''' <param name="sourceFilePath">
  1086.             ''' The source file path (if any).
  1087.             ''' </param>
  1088.             '''
  1089.             ''' <param name="targetFilePath">
  1090.             ''' The target .Net assembly filepath.
  1091.             ''' </param>
  1092.             '''
  1093.             ''' <param name="tempDirectoryPath">
  1094.             ''' The temporary files path used for the compiler.
  1095.             ''' </param>
  1096.             ''' ----------------------------------------------------------------------------------------------------
  1097.             <DebuggerStepThrough>
  1098.             <DebuggerHidden>
  1099.             Public Sub New(ByVal codeDomProvider As CodeDomProvider,
  1100.                            ByVal compilerParameters As CompilerParameters,
  1101.                            ByVal compilerWarnings As IEnumerable(Of Compiler.Warning),
  1102.                            ByVal compileErrors As IEnumerable(Of Compiler.Error),
  1103.                            ByVal sourceCode As String,
  1104.                            ByVal sourceFilePath As String,
  1105.                            ByVal targetFilePath As String,
  1106.                            ByVal tempDirectoryPath As String)
  1107.  
  1108.                 Me.codeDomProviderB = codeDomProvider
  1109.                 Me.compilerParametersB = compilerParameters
  1110.                 Me.compilerWarningsB = compilerWarnings
  1111.                 Me.compileErrorsB = compileErrors
  1112.                 Me.sourceCodeB = sourceCode
  1113.                 Me.sourceFilePathB = sourceFilePath
  1114.                 Me.targetFilePathB = targetFilePath
  1115.                 Me.tempDirectoryPathB = tempDirectoryPath
  1116.  
  1117.             End Sub
  1118.  
  1119.             ''' ----------------------------------------------------------------------------------------------------
  1120.             ''' <summary>
  1121.             ''' Prevents a default instance of the <see cref="CompilerWorkDoneEventArgs"/> class from being created.
  1122.             ''' </summary>
  1123.             ''' ----------------------------------------------------------------------------------------------------
  1124.             Private Sub New()
  1125.             End Sub
  1126.  
  1127. #End Region
  1128.  
  1129.         End Class
  1130.  
  1131. #End Region
  1132.  
  1133. #End Region
  1134.  
  1135. #Region " Constructors "
  1136.  
  1137.         ''' <summary>
  1138.         ''' Initializes a new instance of the <see cref="Compiler"/> class.
  1139.         ''' </summary>
  1140.         <DebuggerStepThrough>
  1141.         <DebuggerHidden>
  1142.         Public Sub New()
  1143.  
  1144.             Me.Compilersettings = New CompilerSettings
  1145.  
  1146.         End Sub
  1147.  
  1148. #End Region
  1149.  
  1150. #Region " Public Methods "
  1151.  
  1152.         ''' ----------------------------------------------------------------------------------------------------
  1153.         ''' <summary>
  1154.         ''' Compiles a .Net assembly from the specified source code string.
  1155.         ''' </summary>
  1156.         ''' ----------------------------------------------------------------------------------------------------
  1157.         ''' <param name="netAssembly">
  1158.         ''' The target kind of .Net assembly.
  1159.         ''' </param>
  1160.         '''
  1161.         ''' <param name="targetFile">
  1162.         ''' The target local file to create.
  1163.         ''' </param>
  1164.         '''
  1165.         ''' <param name="sourceCode">
  1166.         ''' The input source code to compile.
  1167.         ''' </param>
  1168.         '''
  1169.         ''' <param name="mainMemberName">
  1170.         ''' The member name of the main entry point.
  1171.         ''' </param>
  1172.         '''
  1173.         ''' <param name="referencedAssemblies">
  1174.         ''' The referenced assemblies.
  1175.         ''' </param>
  1176.         '''
  1177.         ''' <param name="resources">
  1178.         ''' The managed .Net resources.
  1179.         ''' </param>
  1180.         '''
  1181.         ''' <param name="iconFile">
  1182.         ''' The icon used to set the appereance of the executable file.
  1183.         ''' </param>
  1184.         ''' ----------------------------------------------------------------------------------------------------
  1185.         ''' <exception cref="Exception">
  1186.         ''' The current CodeDomProvider does not support resource embedding.
  1187.         ''' </exception>
  1188.         ''' ----------------------------------------------------------------------------------------------------
  1189.         <DebuggerStepThrough>
  1190.         <DebuggerHidden>
  1191.         Public Overridable Sub CompileFromString(ByVal netAssembly As NetAssembly,
  1192.                                                  ByVal targetFile As String,
  1193.                                                  ByVal sourceCode As String,
  1194.                                                  ByVal mainMemberName As String,
  1195.                                                  Optional ByVal referencedAssemblies As IEnumerable(Of String) = Nothing,
  1196.                                                  Optional ByVal resources As IEnumerable(Of String) = Nothing,
  1197.                                                  Optional ByVal iconFile As String = "")
  1198.  
  1199.             Dim cProvider As CodeDomProvider = Me.Compilersettings.CodeProvider
  1200.             Dim cParams As New CompilerParameters
  1201.             Dim cResult As CompilerResults
  1202.  
  1203.             Me.InitializeCompilerSettings(cProvider, cParams, netAssembly,
  1204.                                           targetFile, mainMemberName,
  1205.                                           referencedAssemblies, resources, iconFile)
  1206.  
  1207.             cResult = cProvider.CompileAssemblyFromSource(cParams, sourceCode)
  1208.  
  1209.             Me.FireCompilerWorkDone(Me, cProvider, cParams, cResult,
  1210.                                     targetFile, sourceCode:=sourceCode)
  1211.  
  1212.         End Sub
  1213.  
  1214.         ''' ----------------------------------------------------------------------------------------------------
  1215.         ''' <summary>
  1216.         ''' Compiles a .Net assembly from the specified source code file.
  1217.         ''' </summary>
  1218.         ''' ----------------------------------------------------------------------------------------------------
  1219.         ''' <param name="netAssembly">
  1220.         ''' The target kind of .Net assembly.
  1221.         ''' </param>
  1222.         '''
  1223.         ''' <param name="targetFile">
  1224.         ''' The target local file to create.
  1225.         ''' </param>
  1226.         '''
  1227.         ''' <param name="sourceFile">
  1228.         ''' The input source file to compile.
  1229.         ''' </param>
  1230.         '''
  1231.         ''' <param name="mainMemberName">
  1232.         ''' The member name of the main entry point.
  1233.         ''' </param>
  1234.         '''
  1235.         ''' <param name="referencedAssemblies">
  1236.         ''' The referenced assemblies.
  1237.         ''' </param>
  1238.         '''
  1239.         ''' <param name="resources">
  1240.         ''' The managed .Net resources.
  1241.         ''' </param>
  1242.         '''
  1243.         ''' <param name="iconFile">
  1244.         ''' The icon used to set the appereance of the executable file.
  1245.         ''' </param>
  1246.         ''' ----------------------------------------------------------------------------------------------------
  1247.         ''' <exception cref="Exception">
  1248.         ''' The current CodeDomProvider does not support resource embedding.
  1249.         ''' </exception>
  1250.         ''' ----------------------------------------------------------------------------------------------------
  1251.         <DebuggerStepThrough>
  1252.         <DebuggerHidden>
  1253.         Public Overridable Sub CompileFromFile(ByVal netAssembly As NetAssembly,
  1254.                                                ByVal targetFile As String,
  1255.                                                ByVal sourceFile As String,
  1256.                                                ByVal mainMemberName As String,
  1257.                                                Optional ByVal referencedAssemblies As IEnumerable(Of String) = Nothing,
  1258.                                                Optional ByVal resources As IEnumerable(Of String) = Nothing,
  1259.                                                Optional ByVal iconFile As String = "")
  1260.  
  1261.             Dim cProvider As CodeDomProvider = Me.Compilersettings.CodeProvider
  1262.             Dim cParams As New CompilerParameters
  1263.             Dim cResult As CompilerResults
  1264.  
  1265.             Me.InitializeCompilerSettings(cProvider, cParams, netAssembly,
  1266.                                           targetFile, mainMemberName,
  1267.                                           referencedAssemblies, resources, iconFile)
  1268.  
  1269.             cResult = cProvider.CompileAssemblyFromFile(cParams, sourceFile)
  1270.  
  1271.             Me.FireCompilerWorkDone(Me, cProvider, cParams, cResult,
  1272.                                     targetFile, sourceFile:=sourceFile)
  1273.  
  1274.         End Sub
  1275.  
  1276. #End Region
  1277.  
  1278. #Region " Private Methods "
  1279.  
  1280.         ''' ----------------------------------------------------------------------------------------------------
  1281.         ''' <summary>
  1282.         ''' Gets a compiler options string in specific language syntax.
  1283.         ''' </summary>
  1284.         ''' ----------------------------------------------------------------------------------------------------
  1285.         ''' <param name="targetAssembly">
  1286.         ''' The target kind of .Net assembly.
  1287.         ''' </param>
  1288.         '''
  1289.         ''' <param name="compilerSettings">
  1290.         ''' The <see cref="CodeDomUtil.CompilerSettings"/> instance that encapsulates the compiler options.
  1291.         ''' </param>
  1292.         '''
  1293.         ''' <param name="iconFile">
  1294.         ''' The icon used to set the appereance of the executable file.
  1295.         ''' </param>
  1296.         ''' ----------------------------------------------------------------------------------------------------
  1297.         ''' <returns>
  1298.         ''' A <see cref="String"/> that contains the compiler options in specific language syntax.
  1299.         ''' </returns>
  1300.         ''' ----------------------------------------------------------------------------------------------------
  1301.         <DebuggerStepThrough>
  1302.         <DebuggerHidden>
  1303.         Protected Overridable Function GetCompilerOptions(ByVal targetAssembly As NetAssembly,
  1304.                                                           ByVal compilerSettings As CompilerSettings,
  1305.                                                           Optional ByVal iconFile As String = "") As String
  1306.  
  1307.             Dim compilerParams As New List(Of String)
  1308.  
  1309.  
  1310.             ' VB: http://msdn.microsoft.com/en-us/library/31xs5fhx.aspx
  1311.             ' C#: http://msdn.microsoft.com/en-us/library/6h25dztx.aspx
  1312.             Select Case targetAssembly
  1313.  
  1314.                 Case NetAssembly.Console
  1315.                     compilerParams.Add("/target:exe")
  1316.  
  1317.                 Case NetAssembly.WinExe
  1318.                     compilerParams.Add("/target:winexe")
  1319.  
  1320.                 Case NetAssembly.WinExeContainer
  1321.                     compilerParams.Add("/target:appcontainerexe")
  1322.  
  1323.                 Case NetAssembly.WinMdObj
  1324.                     compilerParams.Add("/target:winmdobj")
  1325.  
  1326.                 Case NetAssembly.DynamicLinkLibrary
  1327.                     compilerParams.Add("/target:library")
  1328.  
  1329.                 Case NetAssembly.Module
  1330.                     compilerParams.Add("/target:module")
  1331.  
  1332.                 Case Else
  1333.  
  1334.             End Select
  1335.  
  1336.             ' VB: http://msdn.microsoft.com/en-us/library/8ck8e1y2.aspx
  1337.             ' C#: http://msdn.microsoft.com/en-us/library/t0hfscdc.aspx
  1338.             compilerParams.Add(String.Format("/platform:{0}", compilerSettings.Platform.ToString.ToLower))
  1339.  
  1340.             ' VB: http://msdn.microsoft.com/en-us/library/etx40x86.aspx
  1341.             ' C#: http://msdn.microsoft.com/en-us/library/8cw0bt21.aspx
  1342.             If Me.Compilersettings.GenerateDebugInformation Then
  1343.                 compilerParams.Add("/debug:pdbonly")
  1344.             End If
  1345.  
  1346.             ' VB: http://msdn.microsoft.com/en-us/library/f64ezf9b.aspx
  1347.             ' C#: http://msdn.microsoft.com/en-us/library/3260k4x7.aspx
  1348.             Select Case True
  1349.  
  1350.                 Case TypeOf compilerSettings.CodeProvider Is CSharpCodeProvider
  1351.                     If compilerSettings.IntegerOverflowChecksEnabled Then
  1352.                         compilerParams.Add("/doc:")
  1353.                     End If
  1354.  
  1355.                 Case TypeOf compilerSettings.CodeProvider Is VBCodeProvider
  1356.                     If Me.Compilersettings.GenerateXmlDocumentation Then
  1357.                         compilerParams.Add("/doc+")
  1358.                     Else
  1359.                         compilerParams.Add("/doc-")
  1360.                     End If
  1361.  
  1362.             End Select
  1363.  
  1364.             ' VB: http://msdn.microsoft.com/en-us/library/hh500470.aspx
  1365.             ' C#: http://msdn.microsoft.com/en-us/library/hh156527.aspx
  1366.             If compilerSettings.HighEntropyEnabled Then
  1367.                 compilerParams.Add("/highentropyva+")
  1368.             Else
  1369.                 compilerParams.Add("/highentropyva-")
  1370.             End If
  1371.  
  1372.             ' VB: http://msdn.microsoft.com/en-us/library/key2x70f.aspx
  1373.             ' C#: http://msdn.microsoft.com/en-us/library/h25wtyxf.aspx
  1374.             Select Case True
  1375.  
  1376.                 Case TypeOf compilerSettings.CodeProvider Is CSharpCodeProvider
  1377.                     If compilerSettings.IntegerOverflowChecksEnabled Then
  1378.                         compilerParams.Add("/checked+")
  1379.                     Else
  1380.                         compilerParams.Add("/checked-")
  1381.                     End If
  1382.  
  1383.                 Case TypeOf compilerSettings.CodeProvider Is VBCodeProvider
  1384.                     If compilerSettings.IntegerOverflowChecksEnabled Then
  1385.                         compilerParams.Add("/removeintchecks+")
  1386.                     Else
  1387.                         compilerParams.Add("/removeintchecks-")
  1388.                     End If
  1389.  
  1390.             End Select
  1391.  
  1392.             ' VB: http://msdn.microsoft.com/en-us/library/yf8493s5.aspx
  1393.             ' C#: http://msdn.microsoft.com/en-us/library/t0hfscdc.aspx
  1394.             If compilerSettings.OptimizationsEnabled Then
  1395.                 compilerParams.Add("/optimize+")
  1396.             Else
  1397.                 compilerParams.Add("/optimize-")
  1398.             End If
  1399.  
  1400.             ' VB: http://msdn.microsoft.com/en-us/library/jj127108.aspx
  1401.             ' C#: http://msdn.microsoft.com/en-us/library/hh965708.aspx
  1402.             compilerParams.Add(String.Format("/subsystemversion:{0}", compilerSettings.SubsystemVersion))
  1403.  
  1404.             ' VB: http://msdn.microsoft.com/en-us/library/c86sssa5.aspx
  1405.             ' C#: http://msdn.microsoft.com/en-us/library/7f28x9z3.aspx
  1406.             If Not compilerSettings.GenerateWarnings Then
  1407.                 compilerParams.Add("/nowarn")
  1408.             End If
  1409.  
  1410.             ' VB: http://msdn.microsoft.com/en-us/library/2xz9dxe5.aspx
  1411.             ' C#: http://msdn.microsoft.com/en-us/library/406xhdz3.aspx
  1412.             If Me.Compilersettings.TreatWarningsAsErrors Then
  1413.                 compilerParams.Add("/warnaserror+")
  1414.             Else
  1415.                 compilerParams.Add("/warnaserror-")
  1416.             End If
  1417.  
  1418.             ' VB: http://msdn.microsoft.com/en-us/library/yafz4da8.aspx
  1419.             If TypeOf compilerSettings.CodeProvider Is VBCodeProvider Then
  1420.                 If compilerSettings.Verbose Then
  1421.                     compilerParams.Add("/verbose+")
  1422.                 Else
  1423.                     compilerParams.Add("/verbose-")
  1424.                 End If
  1425.             End If
  1426.  
  1427.             ' VB: http://msdn.microsoft.com/en-us/library/ay1354fe.aspx
  1428.             If (Not compilerSettings.VerboseSyntax) AndAlso (TypeOf compilerSettings.CodeProvider Is VBCodeProvider) Then
  1429.                 compilerParams.Add("/quiet")
  1430.             End If
  1431.  
  1432.             ' C#: https://msdn.microsoft.com/en-us/library/hh506932.aspx
  1433.             If (TypeOf compilerSettings.CodeProvider Is CSharpCodeProvider) Then
  1434.                 compilerParams.Add(String.Format("/preferreduilang:{0}", compilerSettings.OutputLanguage.Name))
  1435.             End If
  1436.  
  1437.             ' VB: http://msdn.microsoft.com/en-us/library/683be552.aspx
  1438.             ' C#: http://msdn.microsoft.com/en-us/library/2aaxe43f.aspx
  1439.             If Not String.IsNullOrEmpty(iconFile) Then
  1440.                 compilerParams.Add(String.Format("/win32icon:""{0}""", iconFile))
  1441.             End If
  1442.  
  1443.             ' VB: http://msdn.microsoft.com/en-us/library/4sw42s7k.aspx
  1444.             ' C#: http://msdn.microsoft.com/en-us/library/s5bac5fx.aspx
  1445.             If compilerSettings.LibraryPaths.Any Then
  1446.  
  1447.                 Select Case True
  1448.                     Case TypeOf compilerSettings.CodeProvider Is CSharpCodeProvider
  1449.                         compilerParams.Add(String.Format("/lib:{0}",
  1450.                                                          String.Join(";", From dirPath As String In compilerSettings.LibraryPaths
  1451.                                                                           Select String.Format("""{0}""", dirPath))))
  1452.  
  1453.                     Case TypeOf compilerSettings.CodeProvider Is VBCodeProvider
  1454.                         compilerParams.Add(String.Format("/libpath:{0}",
  1455.                                                          String.Join(";", From dirPath As String In compilerSettings.LibraryPaths
  1456.                                                                           Select String.Format("""{0}""", dirPath))))
  1457.  
  1458.                 End Select
  1459.  
  1460.             End If
  1461.  
  1462.             Return String.Join(" ", compilerParams)
  1463.  
  1464.         End Function
  1465.  
  1466.         ''' ----------------------------------------------------------------------------------------------------
  1467.         ''' <summary>
  1468.         ''' Initializes the compiler settings.
  1469.         ''' </summary>
  1470.         ''' ----------------------------------------------------------------------------------------------------
  1471.         ''' <param name="cProvider">
  1472.         ''' The <see cref="CodeDomProvider"/> instance.
  1473.         ''' </param>
  1474.         '''
  1475.         ''' <param name="cParams">
  1476.         ''' The <see cref="CompilerParameters"/> instance.
  1477.         ''' </param>
  1478.         '''
  1479.         ''' <param name="netAssembly">
  1480.         ''' The target kind of .Net assembly.
  1481.         ''' </param>
  1482.         '''
  1483.         ''' <param name="targetFile">
  1484.         ''' The target local file to create.
  1485.         ''' </param>
  1486.         '''
  1487.         ''' <param name="mainMemberName">
  1488.         ''' The member name of the main entry point.
  1489.         ''' </param>
  1490.         '''
  1491.         ''' <param name="referencedAssemblies">
  1492.         ''' The referenced assemblies.
  1493.         ''' </param>
  1494.         '''
  1495.         ''' <param name="resources">
  1496.         ''' The managed .Net resources.
  1497.         ''' </param>
  1498.         '''
  1499.         ''' <param name="iconFile">
  1500.         ''' The icon used to set the appereance of the executable file.
  1501.         ''' </param>
  1502.         ''' ----------------------------------------------------------------------------------------------------
  1503.         ''' <exception cref="Exception">
  1504.         ''' The current CodeDomProvider does not support resource embedding
  1505.         ''' </exception>
  1506.         ''' ----------------------------------------------------------------------------------------------------
  1507.         <DebuggerStepThrough>
  1508.         <DebuggerHidden>
  1509.         Protected Overridable Sub InitializeCompilerSettings(ByRef cProvider As CodeDomProvider,
  1510.                                                              ByRef cParams As CompilerParameters,
  1511.                                                              ByVal netAssembly As NetAssembly,
  1512.                                                              ByVal targetFile As String,
  1513.                                                              ByVal mainMemberName As String,
  1514.                                                              Optional ByVal referencedAssemblies As IEnumerable(Of String) = Nothing,
  1515.                                                              Optional ByVal resources As IEnumerable(Of String) = Nothing,
  1516.                                                              Optional ByVal iconFile As String = "")
  1517.  
  1518.             ' Renew TempFileCollection.
  1519.             If Me.Compilersettings.TempFileCollection.KeepFiles Then
  1520.                 Me.Compilersettings.TempFileCollection = New TempFileCollection(tempdir:=Me.Compilersettings.TempFileCollection.TempDir, keepFiles:=Me.Compilersettings.TempFileCollection.KeepFiles)
  1521.             End If
  1522.  
  1523.             ' Set a default assembly reference.
  1524.             If (referencedAssemblies Is Nothing) OrElse (Not referencedAssemblies.Any) Then
  1525.                 referencedAssemblies = {"System.dll"}
  1526.             End If
  1527.  
  1528.             ' Set compiler parameters.
  1529.             cParams.CompilerOptions = Me.GetCompilerOptions(netAssembly, Me.Compilersettings, iconFile)
  1530.             With cParams
  1531.  
  1532.                 Select Case netAssembly
  1533.  
  1534.                     Case CodeDomUtil.NetAssembly.Console, CodeDomUtil.NetAssembly.WinExe, CodeDomUtil.NetAssembly.WinExeContainer
  1535.                         .GenerateExecutable = True
  1536.  
  1537.                     Case CodeDomUtil.NetAssembly.DynamicLinkLibrary, CodeDomUtil.NetAssembly.Module, CodeDomUtil.NetAssembly.WinMdObj
  1538.                         .GenerateExecutable = False
  1539.  
  1540.                     Case Else
  1541.                         ' Throw New NotImplementedException("Bad NetAssembly value.")
  1542.  
  1543.                 End Select
  1544.  
  1545.                 .GenerateInMemory = False ' Save the assembly as a physical file.
  1546.                 .OutputAssembly = targetFile
  1547.                 .ReferencedAssemblies.AddRange(referencedAssemblies.ToArray)
  1548.                 .TempFiles = Me.Compilersettings.TempFileCollection
  1549.                 .WarningLevel = Me.Compilersettings.WarningLevel
  1550.             End With
  1551.  
  1552.             ' Set the embedded resource file of the assembly.
  1553.             If cProvider.Supports(GeneratorSupport.Resources) AndAlso (resources IsNot Nothing) Then
  1554.                 cParams.EmbeddedResources.AddRange(resources.ToArray)
  1555.  
  1556.             ElseIf (Not cProvider.Supports(GeneratorSupport.Resources)) AndAlso (resources IsNot Nothing) Then
  1557.                 Throw New Exception(message:="The current CodeDomProvider does not support resource embedding.")
  1558.  
  1559.             End If
  1560.  
  1561.             ' Specify the class/module that contains the main method of the source code.
  1562.             If cProvider.Supports(GeneratorSupport.EntryPointMethod) Then
  1563.                 cParams.MainClass = mainMemberName
  1564.             End If
  1565.  
  1566.         End Sub
  1567.  
  1568.         ''' ----------------------------------------------------------------------------------------------------
  1569.         ''' <summary>
  1570.         ''' Fires the <see cref="CompilerWorkDone"/> event with the specified event data.
  1571.         ''' </summary>
  1572.         ''' ----------------------------------------------------------------------------------------------------
  1573.         ''' <param name="sender">
  1574.         ''' The source of the event.
  1575.         ''' </param>
  1576.         '''
  1577.         ''' <param name="cProvider">
  1578.         ''' The <see cref="CodeDomProvider"/> instance.
  1579.         ''' </param>
  1580.         '''
  1581.         ''' <param name="cParams">
  1582.         ''' The <see cref="CompilerParameters"/> instance.
  1583.         ''' </param>
  1584.         '''
  1585.         ''' <param name="cResult">
  1586.         ''' The <see cref="CompilerResults"/> instance.
  1587.         ''' </param>
  1588.         '''
  1589.         ''' <param name="targetFile">
  1590.         ''' The target .Net assembly file.
  1591.         ''' </param>
  1592.         '''
  1593.         ''' <param name="sourceCode">
  1594.         ''' The source code (if any).
  1595.         ''' </param>
  1596.         '''
  1597.         ''' <param name="sourceFile">
  1598.         ''' The source file (if any).
  1599.         ''' </param>
  1600.         ''' ----------------------------------------------------------------------------------------------------
  1601.         Protected Overridable Sub FireCompilerWorkDone(ByVal sender As Object,
  1602.                                                        ByVal cProvider As CodeDomProvider,
  1603.                                                        ByVal cParams As CompilerParameters,
  1604.                                                        ByVal cResult As CompilerResults,
  1605.                                                        ByVal targetFile As String,
  1606.                                                        Optional ByVal sourceCode As String = "",
  1607.                                                        Optional ByVal sourceFile As String = "")
  1608.  
  1609.             If Me.CompilerWorkDoneEvent IsNot Nothing Then
  1610.  
  1611.                 Dim compilerWarnings As IEnumerable(Of Compiler.Warning) =
  1612.                     From ce As CompilerError In cResult.Errors.Cast(Of CompilerError)()
  1613.                     Where ce.IsWarning
  1614.                     Select New Compiler.Warning(ce)
  1615.  
  1616.                 Dim compileErrors As IEnumerable(Of Compiler.Error) =
  1617.                     From ce As CompilerError In cResult.Errors.Cast(Of CompilerError)()
  1618.                     Where Not ce.IsWarning
  1619.                     Select New Compiler.Error(ce)
  1620.  
  1621.                 Dim eventData As New CompilerWorkDoneEventArgs(codeDomProvider:=cProvider,
  1622.                                                                compilerParameters:=cParams,
  1623.                                                                compilerWarnings:=compilerWarnings,
  1624.                                                                compileErrors:=compileErrors,
  1625.                                                                sourceCode:=sourceCode,
  1626.                                                                sourceFilePath:=sourceFile,
  1627.                                                                targetFilePath:=targetFile,
  1628.                                                                tempDirectoryPath:=cParams.TempFiles.TempDir)
  1629.  
  1630.                 RaiseEvent CompilerWorkDone(sender, eventData)
  1631.  
  1632.             End If
  1633.  
  1634.         End Sub
  1635.  
  1636. #End Region
  1637.  
  1638. #Region " Child Classes "
  1639.  
  1640. #Region " Warning "
  1641.  
  1642.         ''' ----------------------------------------------------------------------------------------------------
  1643.         ''' <summary>
  1644.         ''' Represents a compiler warning.
  1645.         ''' </summary>
  1646.         ''' ----------------------------------------------------------------------------------------------------
  1647.         Public Class Warning : Inherits CompilerError
  1648.  
  1649. #Region " Hidden Base Members "
  1650.  
  1651.             ''' ----------------------------------------------------------------------------------------------------
  1652.             ''' <summary>
  1653.             ''' Gets or sets a value that indicates whether the error is a warning.
  1654.             ''' </summary>
  1655.             ''' ----------------------------------------------------------------------------------------------------
  1656.             ''' <value>
  1657.             ''' <c>tTrue</c> if this instance is warning; otherwise, <c>False</c>.
  1658.             ''' </value>
  1659.             ''' ----------------------------------------------------------------------------------------------------
  1660.             <EditorBrowsable(EditorBrowsableState.Never)>
  1661.             Friend Overridable Shadows ReadOnly Property IsWarning As Boolean
  1662.                 Get
  1663.                     Return MyBase.IsWarning
  1664.                 End Get
  1665.             End Property
  1666.  
  1667. #End Region
  1668.  
  1669. #Region " Constructors "
  1670.  
  1671.             ''' ----------------------------------------------------------------------------------------------------
  1672.             ''' <summary>
  1673.             ''' Initializes a new instance of the <see cref="Warning"/> class.
  1674.             ''' </summary>
  1675.             ''' ----------------------------------------------------------------------------------------------------
  1676.             ''' <param name="ce">
  1677.             ''' A <see cref="CodeDom.Compiler.CompilerError"/> instance that contains the warning data.
  1678.             ''' </param>
  1679.             ''' ----------------------------------------------------------------------------------------------------
  1680.             Public Sub New(ByVal ce As CompilerError)
  1681.                 MyBase.New(ce.FileName, ce.Line, ce.Column, ce.ErrorNumber, ce.ErrorText)
  1682.             End Sub
  1683.  
  1684. #End Region
  1685.  
  1686.         End Class
  1687.  
  1688. #End Region
  1689.  
  1690. #Region " Error "
  1691.  
  1692.         ''' ----------------------------------------------------------------------------------------------------
  1693.         ''' <summary>
  1694.         ''' Represents a compiler error.
  1695.         ''' </summary>
  1696.         ''' ----------------------------------------------------------------------------------------------------
  1697.         Public Class [Error] : Inherits CompilerError
  1698.  
  1699. #Region " Hidden Base Members "
  1700.  
  1701.             ''' ----------------------------------------------------------------------------------------------------
  1702.             ''' <summary>
  1703.             ''' Gets or sets a value that indicates whether the error is a warning.
  1704.             ''' </summary>
  1705.             ''' ----------------------------------------------------------------------------------------------------
  1706.             ''' <value>
  1707.             ''' <c>tTrue</c> if this instance is warning; otherwise, <c>False</c>.
  1708.             ''' </value>
  1709.             ''' ----------------------------------------------------------------------------------------------------
  1710.             <EditorBrowsable(EditorBrowsableState.Never)>
  1711.             Friend Overridable Shadows ReadOnly Property IsWarning As Boolean
  1712.                 Get
  1713.                     Return MyBase.IsWarning
  1714.                 End Get
  1715.             End Property
  1716.  
  1717. #End Region
  1718.  
  1719. #Region " Constructors "
  1720.  
  1721.             ''' ----------------------------------------------------------------------------------------------------
  1722.             ''' <summary>
  1723.             ''' Initializes a new instance of the <see cref="[Error]"/> class.
  1724.             ''' </summary>
  1725.             ''' ----------------------------------------------------------------------------------------------------
  1726.             ''' <param name="ce">
  1727.             ''' A <see cref="CodeDom.Compiler.CompilerError"/> instance that contains the error data.
  1728.             ''' </param>
  1729.             ''' ----------------------------------------------------------------------------------------------------
  1730.             Public Sub New(ByVal ce As CompilerError)
  1731.                 MyBase.New(ce.FileName, ce.Line, ce.Column, ce.ErrorNumber, ce.ErrorText)
  1732.             End Sub
  1733.  
  1734. #End Region
  1735.  
  1736.         End Class
  1737.  
  1738. #End Region
  1739.  
  1740. #End Region
  1741.  
  1742.     End Class
  1743.  
  1744. #End Region
  1745.  
  1746. #Region " Visual Basic Compiler "
  1747.  
  1748.     ''' ----------------------------------------------------------------------------------------------------
  1749.     ''' <summary>
  1750.     ''' Provides Visual Basic code compiler features.
  1751.     ''' </summary>
  1752.     ''' ----------------------------------------------------------------------------------------------------
  1753.     ''' <example> This is a code example that demonstrates how to use the VisualBasicCompiler.
  1754.     ''' <code>
  1755.     ''' Public NotInheritable Class Form1 : Inherits Form
  1756.     '''
  1757.     '''     ''' ----------------------------------------------------------------------------------------------------
  1758.     '''     ''' <summary>
  1759.     '''     ''' The VisualBasic.Net compiler instance.
  1760.     '''     ''' </summary>
  1761.     '''     ''' ----------------------------------------------------------------------------------------------------
  1762.     '''     Dim WithEvents vbCompiler As CodeDomUtil.Compiler =
  1763.     '''         New CodeDomUtil.VisualBasicCompiler(CodeDomUtil.CompilerVersions.V4)
  1764.     '''
  1765.     '''     Private Sub Form1_Shown() Handles MyBase.Shown
  1766.     '''
  1767.     '''         With Me.vbCompiler.Compilersettings
  1768.     '''             .GenerateDebugInformation = True
  1769.     '''             .GenerateWarnings = True
  1770.     '''             .GenerateXmlDocumentation = True
  1771.     '''             .HighEntropyEnabled = True
  1772.     '''             .IntegerOverflowChecksEnabled = False
  1773.     '''             .OptimizationsEnabled = True
  1774.     '''             .Platform = CodeDomUtil.Platform.AnyCpu
  1775.     '''             .SubsystemVersion = CodeDomUtil.SubsystemVersions.WindowsXP
  1776.     '''             .TreatWarningsAsErrors = False
  1777.     '''             .Verbose = True
  1778.     '''             .VerboseSyntax = False
  1779.     '''             .WarningLevel = CodeDomUtil.WarningLevelEnum.Level3
  1780.     '''             .LibraryPaths.Add(IO.Directory.GetCurrentDirectory)
  1781.     '''         End With
  1782.     '''
  1783.     '''         Dim referencedAssemblies As New List(Of String)
  1784.     '''         referencedAssemblies.AddRange({"System.dll", "System.Windows.Forms.dll"})
  1785.     '''
  1786.     '''         ' Compile a VB Console App from string.
  1787.     '''         vbCompiler.CompileFromString(netAssembly:=CodeDomUtil.NetAssembly.Console,
  1788.     '''                                      targetFile:="C:\VB Default Console App.exe",
  1789.     '''                                      sourceCode:=CodeDomUtil.Templates.TemplateVbConsoleApp,
  1790.     '''                                      mainMemberName:="MainNamespace.MainModule",
  1791.     '''                                      referencedAssemblies:=referencedAssemblies,
  1792.     '''                                      resources:=Nothing,
  1793.     '''                                      iconFile:=Nothing)
  1794.     '''
  1795.     '''         ' Compile a VB WinForms App from string.
  1796.     '''         vbCompiler.CompileFromString(netAssembly:=CodeDomUtil.NetAssembly.WinExe,
  1797.     '''                                      targetFile:="C:\VB Default WinForms App.exe",
  1798.     '''                                      sourceCode:=CodeDomUtil.Templates.TemplateVbWinFormsApp,
  1799.     '''                                      mainMemberName:="MainNamespace.MainClass",
  1800.     '''                                      referencedAssemblies:=referencedAssemblies,
  1801.     '''                                      resources:=Nothing,
  1802.     '''                                      iconFile:=Nothing)
  1803.     '''
  1804.     '''         ' Compile a VB library from string.
  1805.     '''         vbCompiler.CompileFromString(netAssembly:=CodeDomUtil.NetAssembly.DynamicLinkLibrary,
  1806.     '''                                      targetFile:="C:\VB Default Library.dll",
  1807.     '''                                      sourceCode:=CodeDomUtil.Templates.TemplateVbLib,
  1808.     '''                                      mainMemberName:="MainNamespace.MainClass",
  1809.     '''                                      referencedAssemblies:=referencedAssemblies,
  1810.     '''                                      resources:=Nothing,
  1811.     '''                                      iconFile:=Nothing)
  1812.     '''
  1813.     '''         ' Compile a VB local file that contains the sourcecode.
  1814.     '''         vbCompiler.CompileFromFile(netAssembly:=CodeDomUtil.NetAssembly.WinExe,
  1815.     '''                                    targetFile:="C:\VB Custom App.exe",
  1816.     '''                                    sourceFile:="C:\SourceCode.vb",
  1817.     '''                                    mainMemberName:="MainNamespace.MainClass",
  1818.     '''                                    referencedAssemblies:=referencedAssemblies,
  1819.     '''                                    resources:=Nothing,
  1820.     '''                                    iconFile:=Nothing)
  1821.     '''
  1822.     '''     End Sub
  1823.     '''
  1824.     '''     ''' ----------------------------------------------------------------------------------------------------
  1825.     '''     ''' <summary>
  1826.     '''     ''' Handles the <see cref="CodeDomUtil.Compiler.CompilerWorkDone"/> event of the vbCompiler instance.
  1827.     '''     ''' </summary>
  1828.     '''     ''' ----------------------------------------------------------------------------------------------------
  1829.     '''     ''' <param name="sender">
  1830.     '''     ''' The source of the event.
  1831.     '''     ''' </param>
  1832.     '''     '''
  1833.     '''     ''' <param name="e">
  1834.     '''     ''' The <see cref="CodeDomUtil.Compiler.CompilerWorkDoneEventArgs"/> instance containing the event data.
  1835.     '''     ''' </param>
  1836.     '''     ''' ----------------------------------------------------------------------------------------------------
  1837.     '''     Public Sub VbCompiler_CompilerWorkDone(ByVal sender As Object, ByVal e As CodeDomUtil.Compiler.CompilerWorkDoneEventArgs) _
  1838.     '''     Handles vbCompiler.CompilerWorkDone
  1839.     '''
  1840.     '''         Console.WriteLine(String.Format("Compiler: {0}", e.CodeDomProvider.ToString))
  1841.     '''         Console.WriteLine(String.Format("Parameters: {0}", e.CompilerParameters.CompilerOptions))
  1842.     '''
  1843.     '''         For Each war As CodeDomUtil.Compiler.Warning In e.CompilerWarnings
  1844.     '''             Console.WriteLine(String.Format("{0}| Warning: {1}", war.ErrorNumber, war.ErrorText))
  1845.     '''         Next war
  1846.     '''
  1847.     '''         For Each err As CodeDomUtil.Compiler.Error In e.CompileErrors
  1848.     '''             Console.WriteLine(String.Format("{0}| Error: {1}", err.ErrorNumber, err.ErrorText))
  1849.     '''         Next err
  1850.     '''
  1851.     '''         If Not e.CompileErrors.Any Then
  1852.     '''             Console.WriteLine(String.Format("Compilation Successful: {0}", e.TargetFilePath))
  1853.     '''         End If
  1854.     '''
  1855.     '''         Console.WriteLine()
  1856.     '''
  1857.     '''     End Sub
  1858.     '''
  1859.     ''' End Class
  1860.     ''' </code>
  1861.     ''' </example>
  1862.     Public NotInheritable Class VisualBasicCompiler : Inherits Compiler
  1863.  
  1864. #Region " Constructors "
  1865.  
  1866.         ''' ----------------------------------------------------------------------------------------------------
  1867.         ''' <summary>
  1868.         ''' Initializes a new instance of the <see cref="VisualBasicCompiler"/> class.
  1869.         ''' </summary>
  1870.         ''' ----------------------------------------------------------------------------------------------------
  1871.         ''' <param name="version">
  1872.         ''' The .NetFx compiler version.
  1873.         ''' </param>
  1874.         ''' ----------------------------------------------------------------------------------------------------
  1875.         <DebuggerStepThrough>
  1876.         <DebuggerHidden>
  1877.         Public Sub New(Optional version As String = "")
  1878.  
  1879.             Dim providerOptions As New Dictionary(Of String, String)()
  1880.  
  1881.             If Not String.IsNullOrEmpty(version) Then
  1882.                 providerOptions.Add("CompilerVersion", String.Format("v{0}", version))
  1883.             End If
  1884.  
  1885.             MyBase.Compilersettings.CodeProvider = New VBCodeProvider(providerOptions)
  1886.  
  1887.         End Sub
  1888.  
  1889. #End Region
  1890.  
  1891.  
  1892.     End Class
  1893.  
  1894. #End Region
  1895.  
  1896. #Region " CSharp Compiler "
  1897.  
  1898.     ''' ----------------------------------------------------------------------------------------------------
  1899.     ''' <summary>
  1900.     ''' Provides CSharp code compiler features.
  1901.     ''' </summary>
  1902.     ''' ----------------------------------------------------------------------------------------------------
  1903.     ''' <example> This is a code example that demonstrates how to use the CSharpCompiler.
  1904.     ''' <code>
  1905.     ''' Public NotInheritable Class Form1 : Inherits Form
  1906.     '''
  1907.     '''     ''' ----------------------------------------------------------------------------------------------------
  1908.     '''     ''' <summary>
  1909.     '''     ''' The C# compiler instance.
  1910.     '''     ''' </summary>
  1911.     '''     ''' ----------------------------------------------------------------------------------------------------
  1912.     '''     Dim WithEvents csCompiler As CodeDomUtil.Compiler =
  1913.     '''         New CodeDomUtil.CSharpCompiler(CodeDomUtil.CompilerVersions.V4)
  1914.     '''
  1915.     '''     Private Sub Form1_Shown() Handles MyBase.Shown
  1916.     '''
  1917.     '''         With Me.csCompiler.Compilersettings
  1918.     '''             .GenerateDebugInformation = True
  1919.     '''             .GenerateWarnings = True
  1920.     '''             .GenerateXmlDocumentation = True
  1921.     '''             .HighEntropyEnabled = True
  1922.     '''             .IntegerOverflowChecksEnabled = False
  1923.     '''             .OptimizationsEnabled = True
  1924.     '''             .OutputLanguage = New CultureInfo("en-US")
  1925.     '''             .Platform = CodeDomUtil.Platform.AnyCpu
  1926.     '''             .SubsystemVersion = CodeDomUtil.SubsystemVersions.WindowsXP
  1927.     '''             .TreatWarningsAsErrors = False
  1928.     '''             .Verbose = True
  1929.     '''             .VerboseSyntax = False
  1930.     '''             .WarningLevel = CodeDomUtil.WarningLevelEnum.Level3
  1931.     '''             .LibraryPaths.Add(IO.Directory.GetCurrentDirectory)
  1932.     '''         End With
  1933.     '''
  1934.     '''         Dim referencedAssemblies As New List(Of String)
  1935.     '''         referencedAssemblies.AddRange({"System.dll", "System.Windows.Forms.dll"})
  1936.     '''
  1937.     '''         ' Compile a C# Console App from string.
  1938.     '''         csCompiler.CompileFromString(netAssembly:=CodeDomUtil.NetAssembly.Console,
  1939.     '''                                      targetFile:="C:\CS Default Console App.exe",
  1940.     '''                                      sourceCode:=CodeDomUtil.Templates.TemplateCsConsoleApp,
  1941.     '''                                      mainMemberName:="MainNamespace.MainClass",
  1942.     '''                                      referencedAssemblies:=referencedAssemblies,
  1943.     '''                                      resources:=Nothing,
  1944.     '''                                      iconFile:=Nothing)
  1945.     '''
  1946.     '''         ' Compile a C# WinForms App from string.
  1947.     '''         csCompiler.CompileFromString(netAssembly:=CodeDomUtil.NetAssembly.WinExe,
  1948.     '''                                      targetFile:="C:\CS Default WinForms App.exe",
  1949.     '''                                      sourceCode:=CodeDomUtil.Templates.TemplateCsWinFormsApp,
  1950.     '''                                      mainMemberName:="MainNamespace.MainClass",
  1951.     '''                                      referencedAssemblies:=referencedAssemblies,
  1952.     '''                                      resources:=Nothing,
  1953.     '''                                      iconFile:=Nothing)
  1954.     '''
  1955.     '''         ' Compile a C# library from string.
  1956.     '''         csCompiler.CompileFromString(netAssembly:=CodeDomUtil.NetAssembly.DynamicLinkLibrary,
  1957.     '''                                      targetFile:="C:\CS Default Library.dll",
  1958.     '''                                      sourceCode:=CodeDomUtil.Templates.TemplateCsLib,
  1959.     '''                                      mainMemberName:="MainNamespace.MainClass",
  1960.     '''                                      referencedAssemblies:=referencedAssemblies,
  1961.     '''                                      resources:=Nothing,
  1962.     '''                                      iconFile:=Nothing)
  1963.     '''
  1964.     '''         ' Compile a C# local file that contains the sourcecode.
  1965.     '''         csCompiler.CompileFromFile(netAssembly:=CodeDomUtil.NetAssembly.WinExe,
  1966.     '''                                    targetFile:="C:\CS Custom App.exe",
  1967.     '''                                    sourceFile:="C:\SourceCode.cs",
  1968.     '''                                    mainMemberName:="MainNamespace.MainClass",
  1969.     '''                                    referencedAssemblies:=referencedAssemblies,
  1970.     '''                                    resources:=Nothing,
  1971.     '''                                    iconFile:=Nothing)
  1972.     '''
  1973.     '''     End Sub
  1974.     '''
  1975.     '''     ''' ----------------------------------------------------------------------------------------------------
  1976.     '''     ''' <summary>
  1977.     '''     ''' Handles the <see cref="CodeDomUtil.Compiler.CompilerWorkDone"/> event of the csCompiler instance.
  1978.     '''     ''' </summary>
  1979.     '''     ''' ----------------------------------------------------------------------------------------------------
  1980.     '''     ''' <param name="sender">
  1981.     '''     ''' The source of the event.
  1982.     '''     ''' </param>
  1983.     '''     '''
  1984.     '''     ''' <param name="e">
  1985.     '''     ''' The <see cref="CodeDomUtil.Compiler.CompilerWorkDoneEventArgs"/> instance containing the event data.
  1986.     '''     ''' </param>
  1987.     '''     ''' ----------------------------------------------------------------------------------------------------
  1988.     '''     Public Sub CsCompiler_CompilerWorkDone(ByVal sender As Object, ByVal e As CodeDomUtil.Compiler.CompilerWorkDoneEventArgs) _
  1989.     '''     Handles csCompiler.CompilerWorkDone
  1990.     '''
  1991.     '''         Console.WriteLine(String.Format("Compiler: {0}", e.CodeDomProvider.ToString))
  1992.     '''         Console.WriteLine(String.Format("Parameters: {0}", e.CompilerParameters.CompilerOptions))
  1993.     '''
  1994.     '''         For Each war As CodeDomUtil.Compiler.Warning In e.CompilerWarnings
  1995.     '''             Console.WriteLine(String.Format("{0}| Warning: {1}", war.ErrorNumber, war.ErrorText))
  1996.     '''         Next war
  1997.     '''
  1998.     '''         For Each err As CodeDomUtil.Compiler.Error In e.CompileErrors
  1999.     '''             Console.WriteLine(String.Format("{0}| Error: {1}", err.ErrorNumber, err.ErrorText))
  2000.     '''         Next err
  2001.     '''
  2002.     '''         If Not e.CompileErrors.Any Then
  2003.     '''             Console.WriteLine(String.Format("Compilation Successful: {0}", e.TargetFilePath))
  2004.     '''         End If
  2005.     '''
  2006.     '''         Console.WriteLine()
  2007.     '''
  2008.     '''     End Sub
  2009.     '''
  2010.     ''' End Class
  2011.     ''' </code>
  2012.     ''' </example>
  2013.     Public NotInheritable Class CSharpCompiler : Inherits Compiler
  2014.  
  2015. #Region " Constructors "
  2016.  
  2017.         ''' ----------------------------------------------------------------------------------------------------
  2018.         ''' <summary>
  2019.         ''' Initializes a new instance of the <see cref="CSharpCompiler"/> class.
  2020.         ''' </summary>
  2021.         ''' ----------------------------------------------------------------------------------------------------
  2022.         ''' <param name="version">
  2023.         ''' The .NetFx compiler version.
  2024.         ''' </param>
  2025.         ''' ----------------------------------------------------------------------------------------------------
  2026.         <DebuggerStepThrough>
  2027.         <DebuggerHidden>
  2028.         Public Sub New(Optional version As String = "")
  2029.  
  2030.             Dim providerOptions As New Dictionary(Of String, String)()
  2031.  
  2032.             If Not String.IsNullOrEmpty(version) Then
  2033.                 providerOptions.Add("CompilerVersion", String.Format("v{0}", version))
  2034.             End If
  2035.  
  2036.             MyBase.Compilersettings.CodeProvider = New CSharpCodeProvider(providerOptions)
  2037.  
  2038.         End Sub
  2039.  
  2040. #End Region
  2041.  
  2042.     End Class
  2043.  
  2044. #End Region
  2045.  
  2046. #End Region
  2047.  
  2048. End Class
  2049.  
  2050. #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement