There was an announcement last week of the second preview of .NET Core 3.0. Scrolling down the page, one item that caught my eye was the section on Windows Native Interop. This includes COM and therefore Visio. The post highlights a dotnet sample that targets Excel and so I thought I have a quick go at trying this against Visio as well.
Visio from .NET Core
I forked the dotnet/samples repository on GitHub and submitted a pull request and so now you can see the code here:
There's really not much to do, but the steps I went through were as follows:
-
Installed Visual Studio 2019 Preview. I think this is optional, but I wanted to try it out in any case. (2019 sits very happily along side my 2017 install and I've not had any conflicts so far.)
-
Installed .NET Core 3.0 Preview 2.0
-
Created a new project - I copied the Excel demo and opened this in Visual Studio (hence the solution file), but you could use the CLI to generate a new project. In either case you need to add the COM reference to the project file manually (by copying from a .NET Framework project) as Visual Studio doesn't support this scenario currently.
Why bother?
You might be reading this and thinking, well that's nice but...so what? Well, to start with I thought this was just an interesting itch that I'd scratch, but I can also see some scenarios where .NET Core might be useful - for example if you already have Core in your tool chain then having a Visio output (or input) as a Global tool might be really handy (don't forget you can new up an InvisibleApp as opposed to the standard one). Another area might be where you want a portable tool that can target Visio when used on a system that hosts it, but carry on with other functionality when that's not the case.
Anyway, for the moment it's nice to see that .NET Core is able to support COM interop and that Visio is part of that party.