Unable to Deploy .NET Core Application with Microsoft.Office.Interop.Word via Azure DevOps Pipeline

I’m encountering an issue deploying my .NET Core application that uses Microsoft.Office.Interop.Word via an Azure DevOps pipeline. Locally, I managed to compare Word documents using Interop Word through COMReference, resolving a previous NuGet package issue. However, during deployment through Azure DevOps, I’m facing errors.

Here’s the context:

Word.Application wordApp = new Word.Application();
            wordApp.Visible = false;
            object wordTrue = (object)true;
            object wordFalse = (object)false;
            object fileToOpen = @"";
            object missing = Type.Missing;
            Word.Document doc1 = wordApp.Documents.Open(ref fileToOpen,
                   ref missing, ref wordFalse, ref wordFalse, ref missing,
                   ref missing, ref missing, ref missing, ref missing,
                   ref missing, ref missing, ref wordTrue, ref missing,
                   ref missing, ref missing, ref missing);

            object fileToOpen1 = @"";
            Word.Document doc2 = wordApp.Documents.Open(ref fileToOpen1,
                   ref missing, ref wordFalse, ref wordFalse, ref missing,
                   ref missing, ref missing, ref missing, ref missing,
                   ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing);

            Word.Document doc = wordApp.CompareDocuments(doc1, doc2, Word.WdCompareDestination.wdCompareDestinationNew, Word.WdGranularity.wdGranularityWordLevel,
            true, true, true, true, true, true, true, true, true, true, "", true);
            doc1.Close(ref missing, ref missing, ref missing);
            doc2.Close(ref missing, ref missing, ref missing);

            // Hides both original and revised documents
            wordApp.ActiveWindow.ShowSourceDocuments = WdShowSourceDocuments.wdShowSourceDocumentsNone;
            wordApp.Visible = true;

Initially, I faced a NuGet package error when using the Microsoft.Office.Interop.Word package, which led me to utilize COMReference as a workaround. While this solution worked locally, the Azure DevOps pipeline fails during the build process with the following error:

Error MSB4803: The task "ResolveComReference" is not supported on the .NET Core version of MSBuild.
Error CS0234: The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Is there an alternative approach or solution to successfully deploy a .NET Core application using Microsoft.Office.Interop.Word or any workaround to resolve this issue with Azure DevOps? Any guidance on resolving this deployment error would be greatly appreciated.

Leave a Comment