Skip to content

Commit a5b6fd8

Browse files
RegFree COM example (#914)
* RegFree COM example
1 parent 3d80b42 commit a5b6fd8

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

core/extensions/COMServerDemo/COMClient/COMClient.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp3.0</TargetFramework>
6+
7+
<!-- The application manifest is only needed for RegFree COM scenarios -->
8+
<ApplicationManifest Condition="'$(RegFree)' == 'True'">COMClient.manifest</ApplicationManifest>
69
</PropertyGroup>
710

811
<ItemGroup>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- https://docs.microsoft.com/windows/desktop/sbscs/assembly-manifests -->
3+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
4+
<assemblyIdentity
5+
type="win32"
6+
name="COMClient"
7+
version="1.0.0.0" />
8+
9+
<dependency>
10+
<dependentAssembly>
11+
<!-- RegFree COM matching the registration of the generated managed COM server -->
12+
<assemblyIdentity
13+
type="win32"
14+
name="COMServer.X"
15+
version="1.0.0.0"/>
16+
</dependentAssembly>
17+
</dependency>
18+
19+
</assembly>

core/extensions/COMServerDemo/COMServer/COMServer.csproj

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55
COM servers must define a framework to use in situations where a CLR instance is not already present in the process.
66
Note that since the COM server may be activated in a process where the CLR must be activated, both the projects
77
*.runtimeconfig.json and *.deps.json files must be bundled with the server itself.
8-
8+
99
In the following example, the following files are needed to deploy the COM server:
1010
COMServer.comhost.dll
1111
COMServer.dll
1212
COMServer.deps.json
1313
COMServer.runtimeconfig.json
14+
15+
In a RegFree COM scenario, the following file must also be deployed:
16+
COMServer.X.manifest
1417
-->
1518
<TargetFramework>netcoreapp3.0</TargetFramework>
16-
19+
1720
<!-- Indicate the assembly is providing a COM server -->
1821
<UseComHost>True</UseComHost>
22+
23+
<!-- Generate a RegFree COM manifest -->
24+
<EnableRegFreeCom Condition="'$(RegFree)' == 'True'">True</EnableRegFreeCom>
1925
</PropertyGroup>
2026

2127
<ItemGroup>
@@ -24,11 +30,40 @@
2430
</ItemGroup>
2531

2632
<Target Name="ServerUsage"
33+
Condition="'$(RegFree)' != 'True'"
2734
AfterTargets="Build">
2835
<Message Importance="High" Text="%0a************************************%0a*** $(MSBuildProjectName) usage instructions ***%0a************************************" />
2936
<Message Importance="High" Text="The server must be COM registered in order to activate.%0aThe following commands must be executed from an elevated command prompt." />
3037
<Message Importance="High" Text="Register:%0a regsvr32.exe &quot;$(ProjectDir)$(OutputPath)$(ComHostFileName)&quot;" />
3138
<Message Importance="High" Text="Unregister:%0a regsvr32.exe /u &quot;$(ProjectDir)$(OutputPath)$(ComHostFileName)&quot;" />
3239
</Target>
3340

41+
<Target Name="ServerUsage_RegFree"
42+
Condition="'$(RegFree)' == 'True'"
43+
AfterTargets="Build">
44+
<Message Importance="High" Text="%0a************************************%0a*** $(MSBuildProjectName) usage instructions ***%0a************************************" />
45+
<Message Importance="High" Text="A RegFree COM manifest has been created for the server.%0aThe manifest '@(RegFreeComManifest->'%(Filename)%(Extension)')' must be included during server deployment.%0aThe COMServer project will copy all required outputs to the COMClient output directory." />
46+
47+
<ItemGroup>
48+
<ServerOutput Include="$(OutputPath)*.dll" />
49+
<ServerOutput Include="$(OutputPath)*.runtimeconfig.json" />
50+
<ServerOutput Include="$(OutputPath)*.deps.json" />
51+
<ServerOutput Include="$(OutputPath)*.manifest" />
52+
</ItemGroup>
53+
54+
<!-- Deploy all required server outputs -->
55+
<Copy SourceFiles="@(ServerOutput)"
56+
DestinationFolder="../COMClient/$(OutputPath)" />
57+
</Target>
58+
59+
<Target Name="Clean_RegFree"
60+
AfterTargets="Clean">
61+
<ItemGroup>
62+
<ServerOutputToDelete Include="../COMClient/$(OutputPath)COMServer.*" />
63+
</ItemGroup>
64+
65+
<!-- Cleanup deployed server outputs -->
66+
<Delete Files="@(ServerOutputToDelete)" />
67+
</Target>
68+
3469
</Project>

core/extensions/COMServerDemo/ReadMe.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Build and Run
1515

1616
The project will only build and run on the Windows platform.
1717

18+
### Registered COM ###
19+
1820
1) Install .NET Core 3.0 Preview 5 or later.
1921

2022
1) Navigate to the root directory and run `dotnet.exe build`.
@@ -23,4 +25,20 @@ The project will only build and run on the Windows platform.
2325

2426
1) Navigate to `COMClient/` and run `dotnet.exe run`.
2527

28+
Program should output an estimated value of &#960;.
29+
2630
**Note** Remember to unregister the COM server when the demo is complete.
31+
32+
### RegFree COM ###
33+
34+
1) Install .NET Core 3.0 Preview 5 or later.
35+
36+
1) Navigate to the root directory and run `dotnet.exe build /p:RegFree=True`.
37+
38+
- If the Registered COM demo was previously run, the project should be cleaned first - `dotnet.exe clean`
39+
40+
1) Run the generated binary directly e.g. `COMClient\bin\Debug\netcoreapp3.0\COMClient.exe`.
41+
42+
Program should output an estimated value of &#960;.
43+
44+
**Note** The RegFree COM scenario requires a customized [application manifest](https://docs.microsoft.com/windows/desktop/sbscs/manifests) in the executing binary. This means that attempting to execute through `dotnet.exe` will not work and instead trigger a rebuild of the project.

0 commit comments

Comments
 (0)