在 .net 4.7 中找不到 EntryPoint 属性的替代品

Can't find the replacement for EntryPoint Attribute in .net 4.7

所以我正在尝试将 solidoworks 宏从 .net 3.5 更新到 .net 4.7

当我正要这样做时,我发现有一个名为 EntryPoint(0) 的方法,它基本上是宏代码的起点。

添加以下代码:

using Microsoft.VisualStudio.Tools.Applications.Contract;
using Microsoft.Office.Tools.Excel;
using Microsoft.Office.Tools;
using SolidWorks;
using SolidWorks.Interop.sldworks;
using System;
using static System.Reflection.MethodInfo; 
using System.Runtime.InteropServices;
using System.AddIn.Contract.Collections; 
using System.ComponentModel;
using System.Diagnostics;
using System.Management;
using System.Runtime;
using System.Runtime.InteropServices.ComTypes;
using System.Windows.Forms;

namespace GoPublish.csproj
{
    public sealed class SolidWorksMacro : OuterDispProxy
    {
      [EntryPoint(0)]
      public SldWorks swApp;

      [DllImport("ole32.dll")]
      private static extern int CreateItemMoniker([MarshalAs(UnmanagedType.LPWStr)] string lpszDelim, [MarshalAs(UnmanagedType.LPWStr)] string lpszItem, out IMoniker ppmk);

      [DllImport("ole32.dll")]
      private static extern int GetRunningObjectTable(uint reserved, out IRunningObjectTable pprot);

我无法在 .net 4.7 中找到它的替代品

关于我该怎么做的任何建议?

Class EntryPointAttribute 在 Microsoft.VisualStudio.Tools.Applications.Contract.dll 中定义,它是 VSTA(Visual Studio 应用程序工具)的一部分。我不太熟悉它,但我的理解是它是用于 macro/plugin 开发的 VS 的轻量级版本。

你当然可以在没有这个 dll 的情况下构建 solidworks 宏,但是有很多方法可以构建宏,所以也许你的特定设置确实需要它。

我猜您一直在为 3.5 版本使用 VSTA,并在 4.7 版本中切换到 VisualStudio,这才是您的实际问题。

.net 4.7 完全支持为以前版本构建的库,因此您可以尝试手动添加引用。在这里我可以找到 Microsoft.VisualStudio.Tools.Applications.Contract.dll :C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Tools.Applications.Contract.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Tools.Applications.Contract.dll