Demo a vanilla OneNote add-in using .NET 5.0
https://github.com/dotnet/core-setup/blob/master/Documentation/design-docs/COM-activation.md
- .NET Framework used mscoree.dll as a shim to bootrap COM activation
- .NET Core uses comhost.dll and one is generated for the project; see Install.reg
Requirements: Visual Studio 16.8 or higher, .NET 5.0 SDK
-
Visual Studio -> Create a new project
-
C#/Windows/Library -> Choose Class Library
-
Enter names
-
Target Framework -> .NET 5.0
-
Edit the csproj file:
Change the TargetFramework to net5.0-windows and enable COM hosting
<TargetFramework>net5.0-windows</TargetFramework> <EnableComHosting>true</EnableComHosting>
To use Windows Forms, add the UseWindowsForms element
true
-
Add COM reference Microsoft.Office 16.0 Object Library
This adds Interop.Microsoft.Office.Corea. Note that some people have found it necessary to enable Embed Interop Type in the dependency proeprties but it seems to work without it.
-
Add COM reference Microsoft OneNote 15.0 Type Library
This adds Interop.Microsoft.Office.Interop.OneNotea. Note that some people have found it necessary to enable Embed Interop Type in the dependency proeprties but it seems to work without it.
-
Browse to reference \Common7\IDE\PublicAssemblies\extensibility.dll
This adds Extensiblity
-
Create a new class (or rename the default Class1.cs) for the addin
The name can be anything you want -
Add these using statements
using Microsoft.Office.Core; using Microsoft.Office.Interop.OneNote;
-
Add the following attributes to the addin class
[ComVisible(true)] [Guid("4D86B2FD-0C2D-4610-8916-DE24C4BB70B5")] [ProgId("OneNoteVanilla5")]
replacing the Guid with your own unique Guid
replacing the ProgId with a unique ID; this will be recorded in the System Registry -
Extend the class with these interfaces:
: IDTExtensibility2 // adds lifetime handlers to the addin : IRibbonExtensibility // adds ribbon handlers to the addin