Reputation: 4418
There's an assembly I need to reference in my project, that needs to have the "Embed Interop Types" set to false in order to successfully compile. If I don't put this option, I get the compile time error:
A reference was created to embedded interop assembly 'Interop.MSTSCLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because of an indirect reference to that assembly created by assembly 'AxInterop.MSTSCLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Consider changing the 'Embed Interop Types' property on either assembly.
If I were to simply have a project, I would set the option to false and never worry about it, but now that I'm making a nuget package with it, I'm trying to find a way to set the option when the package is added.
My nuspec file currently has this (ommiting metadata):
<files>
<file src="Interop.MSTSCLib.dll" target="lib\net40" />
<file src="AxInterop.MSTSCLib.dll" target="lib\net40" />
</files>
I've looked at the nuget documentation but couldn't find how to do this. Is it even possible?
Upvotes: 3
Views: 3157
Reputation: 5049
You'll need an install.ps1 in the tools directory like
param($installPath, $toolsPath, $package, $project)
$project.Object.References | Where-Object { $_.Name -eq "Interop.MSTSCLib" } | ForEach-Object { $_.EmbedInteropTypes = $false }
$project.Object.References | Where-Object { $_.Name -eq "AxInterop.MSTSCLib" } | ForEach-Object { $_.EmbedInteropTypes = $false }
Based on the question Can NuGet distribute a COM dll? and it's answer. This difference is you don't need the call to regsvr32 as you're not trying to distribute and register a com dll.
Upvotes: 6