Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Can't seem to embed interop types when using packagereference in Visual Studio

$
0
0

If you add a reference to an interop assembly in Visual Studio, you can set 'Embed Interop Types' to true (though that might be the default). If you do, the types for the interop interfaces become 'dynamic' and no reference to the interop assembly exists in the manifest. However, when you move to using a PackageReference for the interop assembly the default for 'Embed Interop Types' is false and setting it to true is very difficult. This kind of works:

https://github.com/NuGet/Samples/blob/main/NuGet.Samples.Interop/README.md

It will allow you to set the EmbedInteropTypes to true and fix any compiler errors you may have run into due to EmbedInteropTypes being false. It will also not reference the interop assembly in the manifest. However, the VS editor will not treat the interface variables as 'dynamic' and thus will show the method calls and property gets/sets as if they are errors, ie. red squigglies.

This is similar, if not the same question as:

where is the Embed Interop Property in VS?

but as my account is new I wasn't able to comment and answer that post. Plus I'm hoping someone can chime in on whether there's more of a complete fix for this. I've noticed this in both VS 2019 and VS 2022.

I searched for ways to set 'Embed Interop Types' for a PackageReference but I don't see any way to do that other than the link I show above. And that only partially works.


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>