I am porting a .Net Framework 4.7.2 project to .NET 5 and have Excel.Interop build errors that Intellisense has no problem with. I have:
- Created a new .NET WPF project
- Update the TargetFramework property in the .csproj file from .netcore3.1 to net5.0-windows
- Copied my classes over into the new project
- Added a reference to the Excel 16.0 Object Library
- Changed the Copy Local property of the Interop.Microsoft.Office.Interop.Excel dependency to Yes and changed the Embed Interop Types property to Yes as well
- Started a build
The build fails with Interop errors like "'object' does not contain a definition for 'Value'" even though those errors in Intellisense go away after I update the Copy Local and Embed Interop Types properties.
Following the build, if I double-click on each of the build errors, the class file opens and Intellisense considers the error resolved: it disappears from the list and the red line under the code disappears as well.
I see Interop.Microsoft.Office.Interop.Excel in the project Dependencies --> COM expandable items in the Solution Explorer, but when I right click on the Solution, do Properties, and look at Project Dependencies for my project, nothing is listed. Is this a problem? Would a COM reference be listed in Solution Properties --> Project Dependencies?
I was under the impression that the Office Interop libraries would be compatible with .NET 5 and that I am setting things up correctly. Why is does Intellisense think things are fine but build errors result?
Things I've tried
- Restarting Visual Studio and my computer
- Removing the reference and re-adding it
- Cleaning and rebuilding the solution
- Deleting the bin and obj folders in the project