是否可以从具有扩展名的项目创建对象

问题描述

我需要的是使用 VSIX 扩展在主项目中创建 C# 类的实例。这可能吗?

示例:- 安装了我的扩展程序的项目。当扩展调用它时应该创建该打开文件的一个实例。在 Vsix 项目内部,以便将这些方法用于其他目的。

这里是我尝试过的;

     public Void ExecuteCommand(SaveCommandArgs args,CommandExecutionContext executionContext)
    {
        ThreadHelper.ThrowIfNotOnUIThread();

      
        if (args.SubjectBuffer.Properties.TryGetProperty(typeof(ITextDocument),out ITextDocument textDoc))
        {
            var filePath = textDoc.FilePath;
             // Here I get the Open File Locatiob
            var dte = Package.GetGlobalService(typeof(DTE)) as DTE;
            ProjectItem item = dte.Solution?.FindProjectItem(filePath);


            var name = Path.GetFileNameWithoutExtension(filePath);
            
             // test is the project I used for Extension. namespace Test in the project that used the Extension.
          // Here When I tried to create a object from that class In give me assembly error. Activator point to the Current VSIX assembly not the Project  assembly we want
            object obj = ((ObjectHandle)Activator.CreateInstance(null,"Test."+name)).Unwrap();
            Type type = obj.GetType();

           

            
        }}

那么我真正想知道的是我正在尝试的是可能还是不可能?如果有可能如何在此处获取该程序集,或者是否有其他更好的方法来做到这一点?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)