Skip to content

Commit 4ebd6b9

Browse files
authored
ComWrappersGeneration fix for PublishAOT with DNNE (dotnet#7048)
* Set DnneBuildExports=false when publishing AOT * Set DnneAddGeneratedBinaryToProject=true * Update README to add /u flag for regsvr32.exe when unregistering
1 parent 57d8864 commit 4ebd6b9

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

core/interop/source-generation/ComWrappersGeneration/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ This sample supports NativeAOT and standard CoreCLR deployments. The native meth
2525

2626
### NativeAOT
2727

28-
Build the Native AOT binaries by running `dotnet publish -r <RID>` where `<RID>` is the RuntimeIdentifier for your OS, for example `win-x64`. The projects will copy the binaries to the `OutputFiles\` directory. After publishing, use `regsvr32.exe` to register `Server.dll` with COM by running run `regsvr.exe .\OutputFiles\Server\Server.dll`. Then, run the client application `.\OutputFiles\Client\Client.exe` and observe the output as it activates and uses a COM instance from `Server.dll`.
28+
Build the Native AOT binaries by running `dotnet publish -r <RID>` where `<RID>` is the RuntimeIdentifier for your OS, for example `win-x64`. The projects will copy the binaries to the `OutputFiles\` directory. After publishing, use `regsvr32.exe` to register `Server.dll` with COM by running run `regsvr32.exe .\OutputFiles\Server\Server.dll`. Then, run the client application `.\OutputFiles\Client\Client.exe` and observe the output as it activates and uses a COM instance from `Server.dll`. When you are finished, unregister the server by running `regsvr32.exe /u .\OutputFiles\Server\Server.dll`.
2929

3030
### CoreCLR
3131

32-
Build the projects by running `dotnet publish`. The projects will copy the binaries to the `OutputFiles\` directory. After publishing, use `regsvr32.exe` to register the native binary produced by DNNE, `ServerNE.dll` by running `regsvr.exe .\OutputFiles\Server\ServerNE.dll`. `ServerNE.dll` will start the .NET runtime and call the exported methods in the managed `Server.dll` which register the server with COM. Then, run the client application `.\OutputFiles\Client\Client.exe` and observe the output as it activates and uses a COM instance from `ServerNE.dll`.
32+
Build the projects by running `dotnet publish`. The projects will copy the binaries to the `OutputFiles\` directory. After publishing, use `regsvr32.exe` to register the native binary produced by DNNE, `ServerNE.dll`, by running `regsvr32.exe .\OutputFiles\Server\ServerNE.dll`. `ServerNE.dll` will start the .NET runtime and call the exported methods in the managed `Server.dll` which register the server with COM. Then, run the client application `.\OutputFiles\Client\Client.exe` and observe the output as it activates and uses a COM instance from `ServerNE.dll`. When you are finished, unregister the server by running `regsvr32.exe /u .\OutputFiles\Server\ServerNE.dll`.
3333

3434
## See also
3535

core/interop/source-generation/ComWrappersGeneration/Server/Server.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88

9-
<!-- Uncomment to publish as a native executable -->
9+
<!-- Uncomment to publish the project as a single native .dll -->
1010
<!-- <PublishAOT>true</PublishAOT> -->
1111
</PropertyGroup>
1212

@@ -15,10 +15,17 @@
1515
<EnableDynamicLoading>true</EnableDynamicLoading>
1616
<!-- Use our own .def file to export the COM methods as PRIVATE. The Windows native linker (Link.exe) warns when exported COM methods are not PRIVATE. -->
1717
<DnneWindowsExportsDef>Server.def</DnneWindowsExportsDef>
18+
<!-- Copy DNNE .dll and header files to the output directory -->
19+
<DnneAddGeneratedBinaryToProject>true</DnneAddGeneratedBinaryToProject>
20+
</PropertyGroup>
21+
22+
<PropertyGroup Condition="'$(PublishAOT)' == 'true'">
23+
<!-- Don't build the DNNE .dll when publishing a native .dll with Native AOT. -->
24+
<DnneBuildExports>false</DnneBuildExports>
1825
</PropertyGroup>
1926

2027
<ItemGroup>
21-
<PackageReference Include="DNNE" Version="2.0.7" Condition="'$(PublishAOT)' != 'true'"/>
28+
<PackageReference Include="DNNE" Version="2.0.7" />
2229
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
2330
<!-- When publishing AOT, use our own .def file to export the COM methods as PRIVATE. The Windows native linker (Link.exe) warns when exported COM methods are not PRIVATE. -->
2431
<LinkerArg Include="/DEF:&quot;Server.def&quot;" Condition="'$(PublishAOT)' == 'true'"/>

0 commit comments

Comments
 (0)