gpt4 book ai didi

visual-studio - 在 NuGet 包中将互操作类型嵌入到 false

转载 作者:行者123 更新时间:2023-12-01 11:19:03 24 4
gpt4 key购买 nike

我需要在我的项目中引用一个程序集,它需要将“嵌入互操作类型”设置为 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 文档,但找不到如何执行此操作。有可能吗?

最佳答案

您需要在工具目录中安装一个 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 dll。

关于visual-studio - 在 NuGet 包中将互操作类型嵌入到 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46353244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com