我需要在我的项目中引用一个程序集,需要有"嵌入互操作类型"设置为false以便成功编译。如果我没有提供此选项,则会出现编译时错误:
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.
如果我只是想要一个项目,我会将选项设置为false并且从不担心它,但是现在我正在制作一个nuget包,我试图找到一种方法添加软件包时设置选项。
我的nuspec文件目前有这个(省略元数据):
<files>
<file src="Interop.MSTSCLib.dll" target="lib\net40" />
<file src="AxInterop.MSTSCLib.dll" target="lib\net40" />
</files>
我查看了nuget文档,但无法找到如何执行此操作。它甚至可能吗?
答案 0 :(得分:4)
您需要在工具目录中安装install.ps1,例如
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 }
基于问题Can NuGet distribute a COM dll?,它是answer。这种区别是你不需要调用regsvr32,因为你不是要分发和注册一个com。这里。