为 Excel VSTO 插件制作程序集 COM-Visible 中断构建

Make assembly COM-Visible breaks build for Excel VSTO addin

我正在开发 C# VSTO Excel 插件,它将被一些 excel VBA 调用。因此我必须:

寄存器没有破坏任何东西,但是使程序集 COM 可见会产生以下两个错误:

Error       The assembly "C:\Users\...\ExcelInterop.dll" could not be converted to a type library. Type library exporter encountered an error while processing 'ExcelInterop.ThisAddIn, ExcelInterop'. Error: Error loading type library/DLL.   ExcelInterop            
Error       The assembly 'Microsoft.Office.Tools.Common.v4.0.Utilities, Version=10.0.0.0, Culture=neutral, PublicKeyToken=...' is not registered for COM Interop. Please register it with regasm.exe /tlb.  ExcelInterop            

如果我创建一个普通的 class 库项目,它工作正常,所以我猜它与 ThisAddin.cs 有关,它将 C# 链接到 excel 工作表。请注意,我 not 从生成的样板文件中完全更改 ThisAddin.cs

我想做什么?

从我的 VSTO Excel 加载项,我必须 import/export 一些 excel 数据并将其发送给企业 API(无法从 VBA Excel 插件)。但是,VBA 为客户端提供了 UI(除其他外),这就是为什么我不能用 C# 重写整个 VBA 插件的原因。

阅读以下 SO post 帮助我更好地理解 COM-Visible 的含义...

我只需要标记 class 我需要在 VBA 中使用,如下所示,而不是使整个程序集 COM 可见:

[GuidAttribute("54c23560-db8d-4ec9-a19f-f920ba0558c0"), ComVisible(true)]
public class Manager
{
...
}

我从 https://www.guidgenerator.com/online-guid-generator.aspx 生成了 Guid。