I am unable to build a project targeting .NET Framework 4.7.2. Specifically, this is an Excel VSTO Add-In using a ClickOnce deployment.
I am using Visual Studio 2019. The add-in has a working code base, but previously it was targeting earlier .NET versions (4.0, 4.5). Changes in some of the dependencies and the web services they interact with mean that some libraries used needed to be upgraded to later versions, and so some dependency shuffling got me in this mess.
The build always fails with several errors of the form:
Problem generating manifest. Could not load file or assembly '
PATH_TO_NUGET_PACKAGES\microsoft.windows.sdk.contracts\**\*.winmd
' or one of its dependencies. An attempt was made to load a program with an incorrect format.
All of them are in that Microsoft.Windows.Sdk.Contracts
namespace, which is obtained somewhere along the way. This add-in uses WinForms.
I have seen several answers here and elsewhere to similar problems, but none of the solutions have been useful in resolving my issue.
For instance, in 'Could not load file or assembly exception', several options are given. The accepted answer involves the ClickOnce security setting, but that is not even visible in a Class Library output type, which the add-ins are.
Several other answers in that question and others concern conflicts between 32-bit and 64-bit deployments or dependencies. Some of the answers are for IIS, others not, but in general they mostly hinge around either ensuring that you are using 'Any CPU' as the platform target, or that everything is targeted towards an x86 target. I had been using 'Any CPU' from the start, but changing to any target in the Build settings and the configurations available has had no change in the result. It might be that an architecture target is to blame due to differences in dependencies, but I don't know how to resolve it.
The accepted answer in 'Could not load file or assembly Windows.winmd' suggests excluding the .winmd
files by changing their Publish Status in the 'Publish' area of the project's properties. However, since this is an Office Add-in I don't actually have such a button at all.
Another answer mentions adding it to the GAC with gacutil -i
, but that won't work for these .winmd
files.
This is not my area of expertise, I am not the original author of this add-in, and I barely know what I'm doing when it comes to .NET. Any help sorting this out would be appreciated!