How to deploy a .Net assmebly for COM use through CAB on Web Page
To create a .Net assembly which will be used by COM clients:
1. Create a VB.Net Class Library named “ClassLibraryVBActiveX”. Use the following code for the project:
Imports System.Runtime.InteropServices
<GuidAttribute("BC2E2273-E3D8-4AEA-8A4F-799574803D89"), ProgIdAttribute("ClassLibraryVBActiveX.Class1")> _
Public Class Class1
Public Function Hello() As String
Return "Hello World!"
End Function
End Class
Please keep a note of the GUID. We will use it later.
2. Right click the class library project in the Solution Explorer and select “Properties”. This will open the Property Pages of the class library project. Under the category “Configuration Properties” | “Build”, check the check box “Register for COM Interop”.
3. Build the class library project.
To create a Setup project for the class library:
4. Right-click the solution in the Solution Explorer and select “Add” | “New Project”. Select “Setup Project” and name it as “ActiveXInstaller”.
5. Add the “Primary output” of the class library to the Setup project.
6. Build the Setup project. We should see that “ClassLibraryVBActiveX.dll” and “ClassLibraryVBActiveX.tlb” have been built into the Setup project.
To build the CAB file for the Setup project:
7. Extract the ZIP attached and save the files to a temporary folder.
<Attachment is not available>
We have the following 5 files:
makecab.exe – The utility for building CABs. The utility can typically be found in “System32”.
Installer.inf – The Inf file for the CAB file. It has the following contents:
[Setup Hooks]
hook1=hook1
[hook1]
run= msiexec /i %EXTRACT_DIR%/ActiveXInstaller.msi /qn
[Version]
; This section is required for compatibility on both Windows 95 and Windows NT.
Signature="$CHICAGO$"
AdvancedInf=2.0
Here “run” specifies the command we would like to run after IE extracts the CAB. The command line will install the MSI “ActiveXInstaller.msi” under silent mode. You may refer to the following links for more details about the format of INF:
About INF File Architecture
http://msdn.microsoft.com/library/default.asp?url=/workshop/delivery/download/overview/infarchitecture.asp?frame=true
Cab.DDF – a text file with the following contents:
.OPTION EXPLICIT
.Set Cabinet=on
.Set Compress=on
.Set MaxDiskSize=CDROM
.Set ReservePerCabinetSize=6144
.Set DiskDirectoryTemplate="."
.Set CompressionType=MSZIP
.Set CompressionLevel=7
.Set CompressionMemory=21
.Set CabinetNameTemplate="ActiveX.CAB"
"Installer.inf"
"ActiveXInstaller.msi"
This file is a directive file for the “MakeCAB.exe” utility. “ActiveX.CAB” is the output name of the CAB. The last two lines indicate the two files we would like to include into the CAB.
Make.bat – a batch file that will run the following command to build the CAB:
MAKECAB.EXE /f "Cab.DDF"
TestPage.htm – a template HTML that will install the CAB:
<HTML>
<BODY>
<OBJECT ID="ClassLibraryVBActiveX"
CLASSID="CLSID:BC2E2273-E3D8-4AEA-8A4F-799574803D89"
CODEBASE="ActiveX.CAB#version=1,0,0,0">
</OBJECT>
</BODY>
</HTML>
Note that the GUID should match the GUID in our VB.Net code.
8. To use these files, please copy output MSI of the Setup project (e.g. “ActiveXInstaller.msi”) to the same folder as the files above. Then double-click “Make.bat” to build the CAB.
9. Copy the CAB as well as “TestPage.htm” to a web folder and test it.
Note that this approach also provides a way for the end user to uninstall the assembly. We can remove it by “Add/Remove Programs” applet.
To create a .Net assembly which will be used by COM clients:
1. Create a VB.Net Class Library named “ClassLibraryVBActiveX”. Use the following code for the project:
Imports System.Runtime.InteropServices
<GuidAttribute("BC2E2273-E3D8-4AEA-8A4F-799574803D89"), ProgIdAttribute("ClassLibraryVBActiveX.Class1")> _
Public Class Class1
Public Function Hello() As String
Return "Hello World!"
End Function
End Class
Please keep a note of the GUID. We will use it later.
2. Right click the class library project in the Solution Explorer and select “Properties”. This will open the Property Pages of the class library project. Under the category “Configuration Properties” | “Build”, check the check box “Register for COM Interop”.
3. Build the class library project.
To create a Setup project for the class library:
4. Right-click the solution in the Solution Explorer and select “Add” | “New Project”. Select “Setup Project” and name it as “ActiveXInstaller”.
5. Add the “Primary output” of the class library to the Setup project.
6. Build the Setup project. We should see that “ClassLibraryVBActiveX.dll” and “ClassLibraryVBActiveX.tlb” have been built into the Setup project.
To build the CAB file for the Setup project:
7. Extract the ZIP attached and save the files to a temporary folder.
<Attachment is not available>
We have the following 5 files:
makecab.exe – The utility for building CABs. The utility can typically be found in “System32”.
Installer.inf – The Inf file for the CAB file. It has the following contents:
[Setup Hooks]
hook1=hook1
[hook1]
run= msiexec /i %EXTRACT_DIR%/ActiveXInstaller.msi /qn
[Version]
; This section is required for compatibility on both Windows 95 and Windows NT.
Signature="$CHICAGO$"
AdvancedInf=2.0
Here “run” specifies the command we would like to run after IE extracts the CAB. The command line will install the MSI “ActiveXInstaller.msi” under silent mode. You may refer to the following links for more details about the format of INF:
About INF File Architecture
http://msdn.microsoft.com/library/default.asp?url=/workshop/delivery/download/overview/infarchitecture.asp?frame=true
Cab.DDF – a text file with the following contents:
.OPTION EXPLICIT
.Set Cabinet=on
.Set Compress=on
.Set MaxDiskSize=CDROM
.Set ReservePerCabinetSize=6144
.Set DiskDirectoryTemplate="."
.Set CompressionType=MSZIP
.Set CompressionLevel=7
.Set CompressionMemory=21
.Set CabinetNameTemplate="ActiveX.CAB"
"Installer.inf"
"ActiveXInstaller.msi"
This file is a directive file for the “MakeCAB.exe” utility. “ActiveX.CAB” is the output name of the CAB. The last two lines indicate the two files we would like to include into the CAB.
Make.bat – a batch file that will run the following command to build the CAB:
MAKECAB.EXE /f "Cab.DDF"
TestPage.htm – a template HTML that will install the CAB:
<HTML>
<BODY>
<OBJECT ID="ClassLibraryVBActiveX"
CLASSID="CLSID:BC2E2273-E3D8-4AEA-8A4F-799574803D89"
CODEBASE="ActiveX.CAB#version=1,0,0,0">
</OBJECT>
</BODY>
</HTML>
Note that the GUID should match the GUID in our VB.Net code.
8. To use these files, please copy output MSI of the Setup project (e.g. “ActiveXInstaller.msi”) to the same folder as the files above. Then double-click “Make.bat” to build the CAB.
9. Copy the CAB as well as “TestPage.htm” to a web folder and test it.
Note that this approach also provides a way for the end user to uninstall the assembly. We can remove it by “Add/Remove Programs” applet.