I am trying to use the recently-released .NET core with MS Office using the interop assemblies
I've got a minimal project file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Office.Interop.Word">
<Version>15.0.4797.1003</Version>
</PackageReference>
</ItemGroup>
</Project>
and this C# program
using System;
using Microsoft.Office.Interop.Word;
namespace ii
{
class Program
{
static void Main(string[] args)
{
var app = new Application();
Console.WriteLine(app.Version);
app.Quit();
}
}
}
Unfortunately this fails with
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.
File name: 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
When I added the package to the project I got this
warn : Package 'Microsoft.Office.Interop.Word 15.0.4797.1003' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.0'. This package may not be fully compatible with your project.
info : Package 'Microsoft.Office.Interop.Word' is compatible with all the specified frameworks in project
implying 'compatible' but not 'fully compatible'
Is there a way to do this or must I use .NET Framework instead of Core?
I am using Windows 10, .NET core 3.0.100 and MS Office 365 (Word is version 16.0.11929.20298)
dynamic excel = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application", true));
and start using the Application object you get back - without type support. Interop assemblies make life a lot easier though by providing the CLSIDs and strongly-typed proxy object you'd otherwise have to create yourself. – Panagiotis KanavosFileNotFoundException
mentioned above – Peter Hulldynamic
– Panagiotis Kanavos