Introduction
I will describe each step involving Reg-free approach that eliminates explicit registration of .NET Component when it is used by application built by something other than .NET Framework, i.e., C++, Powerbuilder Application, etc.
Background
The main theme of Reg-Free approach is to provide sufficient information to Client Application at launch time by using Microsoft Manifest technology.
Using the Code
The main components of Reg-free approach are listed below:
- .NET Class Library Project's Class
- Component Manifest file
- Resource file
- Make DLL
- Client Application manifest
1) .NET Class Library Project's Class
Make a class library project in the .NET framework and take two guid from online guid generator tool. Assign one guid at namespace & second at class.
Note: Don't build project. Otherwise an entry with this class id will be created on COM server and conflict with classid
of DLL you make by command later.
2) Component Manifest File
Create file with test.manifest extension and add the following settings:
="1.0"="UTF-8"="yes"
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
name="myOrganization.myDivision.myManagedComp"
version="1.2.3.4" />
publicKeyToken="8275b28176rcbbef"
/>
<clrClass
clsid="{65722BE6-3449-4628-ABD3-74B6864F9739}"
threadingModel="Both"
name="myManagedComp.testClass1">
</clrClass>
</assembly>
3) Resource File
Create file with .rc extension and add the following commands:
#include <windows.h>
#define MANIFEST_RESOURCE_ID 1
MANIFEST_RESOURCE_ID RT_MANIFEST test.manifest
Now compile this test.rc with the following command by using Visual Studio command prompt.
rc test.manifest
This will create test.rec
with embedded test.manifest
.
4) Make DLL
Open command Prompt, set directory to C:\Windows\Microsoft.NET\Framework\v2.0.50727, and run the following command:
C:\Windows\Microsoft.NET\Framework\v2.0.50727
vbc /t:library /out:C:\\test.dll /win32resource:C:\\test.res /rootnamespace:yournamespace Class1.vb
The above command will create .dll at the path you mentioned in command (in our case, path root directory is C:\\).
5) Client Application Manifest
Create another app.manifest file and it should look like this:
="1.0"="UTF-8"="yes"
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32"
name="myapp"
version="1.0.0.0"
processorArchitecture="x86"
/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32"
name="mynamespace.class"
version="1.0.0.0"
processorArchitecture="X86"
/>
</dependentAssembly>
</dependency>
</assembly>
At this stage, you have completed all steps. Now, it is time to use DLL component alongwith client application and application manifest. Place DLL, client application (.exe), and client application manifest at the same path.
Summary
When client application launches, by default, it checks .manifest file having the same name as launching app. If found, it reads dependency node in .manifest file and loads dependency by using name & version values. Internally, it looks inside COM server and search classid.
Drawback
Whenever relevant dependency DLLs are not correctly produced by reg-free approach, the client application will fail to access that dependent DLL and the whole app will not be able to launch. The solution to this drawback is to simply rename manifest or remove that dependency in manifest file.
Advantage
No need to explicitly register .NET DLL which will not be successfully registered when permissions are not assigned to system login-ed user.