WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Third Party Components
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Create An Assembly DLL On The Fly

 Keywords: Create Build Compile Assembly DLL DotNet .Net Microsoft.CSharp.CSharpCodeProvider System.CodeDom.Compiler.CompilerParameters .CS

For the curious, here is an example of how to create the ManagedWif.dll assembly on the fly using a WinBatch script and the FCL's c# compiler.
ObjectClrOption("version", "v2.0.50727")
strAssembly =  DirScript():"ManagedWifi.dll"
If !FileExist(strAssembly)

   ;; Compile assembly from source files.
   ObjectClrOption("use","System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")

   objCSharp = ObjectClrNew('Microsoft.CSharp.CSharpCodeProvider')
   objParams = ObjectClrNew('System.CodeDom.Compiler.CompilerParameters')
   objParams.ReferencedAssemblies.Add( "System.dll" )
   objParams.OutputAssembly  = strAssembly
   objParams.CompilerOptions = "/optimize"
   aSource = ArrDimension(3)
   aSource[0] = "C:\Projects\DotNet\managedwifi-1.1\Interop.cs"
   aSource[1] = "C:\Projects\DotNet\managedwifi-1.1\WlanApi.cs"
   aSource[2] = "C:\Projects\DotNet\managedwifi-1.1\Properties\AssemblyInfo.cs"
   objResult = objCSharp.CompileAssemblyFromFile(objParams, BSTR:aSource)

   ;; Check for compiler errors.
   If objResult.Errors.Count > 0
       ForEach ce In objResult.Errors
         Pause("Error", ce.ToString())
      Next
      Exit
    EndIf
EndIf
Exit

Article ID:   W17853
Filename:   Create an Assembly DLL On The Fly.txt
File Created: 2013:09:13:08:20:08
Last Updated: 2013:09:13:08:20:08