使用加载项的项目在其他应用程序 [英] Use Addin project in another application

查看:262
本文介绍了使用加载项的项目在其他应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了与我创建了一些文件programtically溶液中的插件应用程序。我将这一在另一个WinForms应用程序。因此,一旦用户点击该按钮,一个新的项目与某些输入动态创建的。

I have created a addin application with which i'm creating a solution with some files programtically. I have to integrate this in another winforms application. So once the user clicks the button a new project is created with some inputs dynamically.

在插件项目的形式包含了一个方法(的OnConnection),它被自动调用。这将创建项目在运行时。该应用程序工作正常。

In the addin project the form contains a method(OnConnection) which gets called automatically. This creates the project at run-time. The application works fine.

    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
            {
                _applicationObject = (DTE2)application;
                _addInInstance = (AddIn)addInInst;
                createProjectsFromTemplates(_applicationObject);
            }

public void createProjectsFromTemplates(DTE2 dte)
        {
            try
            {
                // Create a solution with two projects in it, based on project 
                // templates.
                Solution2 soln = (Solution2)dte.Solution;
                string csTemplatePath;
                //string vbTemplatePath;
                string csPrjPath = "\\\\#####.com\\###\\My Documents\\TestCreateProject";
                //string vbPrjPath = "C:\\UserFiles\\user1\\addins\\MyVBProject";

                // Get the project template path for a C# console project.
                // Console Application is the template name that appears in 
                // the right pane. "CSharp" is the Language(vstemplate) as seen 
                // in the registry.
                csTemplatePath = soln.GetProjectTemplate("WpfApplication.zip", "CSharp");
                System.Windows.Forms.MessageBox.Show("C# template path: " + csTemplatePath);

                // Get the project template path for a Visual Basic console
                // project.
                // "vbproj: is the DefaultProjectExtension as seen in the 
                // registry.
                //vbTemplatePath = soln.GetProjectTemplate("ConsoleApplication.zip", "vbproj");
                //System.Windows.Forms.MessageBox.Show("Visual Basic template path: " + vbTemplatePath);

                // Create a new C# console project using the template obtained 
                // above.
                soln.AddFromTemplate(csTemplatePath, csPrjPath, "NewWCFCSharpAutoGeneratorProject", false);

                // Create a new Visual Basic console project using the template 
                // obtained above.
                //soln.AddFromTemplate(vbTemplatePath, vbPrjPath, "New VB Console Project", false);


                Project prj;
                ProjectItem prjItem;

                String itemPath;
                // Point to the first project (the Visual Basic project).
                prj = soln.Projects.Item(1);

                prjItem = prj.ProjectItems.AddFromFileCopy("\\\\####.com\\###\\My Documents\\SampelCSharp.cs");
                // Retrieve the path to the class template.
                //itemPath = soln.GetProjectItemTemplate("MyClass.zip", "CSharp");
                //Create a new project item based on the template, in this
                // case, a Class.
                //prjItem = prj.ProjectItems.AddFromTemplate(itemPath, "MyNewClass.cs");
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("ERROR: " + ex.Message);
            }
        }

现在我要以创建项目在运行时使用外接项目从其他应用程序(的WinForms)。我建了插件项目和进口的.dll文件到该应用程序。我创建了这个类的一个实例,并获得了的OnConnectionmethod.But我不知道什么要传递的参数。因为调试它显示了应用参数的方法时进行内它的一些COM对象。

Now i have to use the add in project from another application(Winforms) in order to create the project at run-time. I have build the addin project and imported the .dll file to that application. I have created an instance for the class and got the "OnConnection" method.But i'm not sure about what to be passed as the parameters. Because when debugging the method it shows the "application" parameter carries some "COM" objects within it.

此外,如果应用程序运行一次,新的项目时,再次执行它说文件已经存在的路径创建。我要覆盖旧的。

Also if the application runs once, the new project is created when executed again it says file already exists in the path. I have to overwrite the older one.

这究竟是什么解决办法吗?

What is the solution for this?

注意:使用Visual Studio 2012和框架3.5

推荐答案

试试这个:

EnvDTE80.DTE2 dte2;
dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.11.0");

Connect objConnect = new Connect();
Array objArray = null;
objConnect.OnConnection(dte2, ext_ConnectMode.ext_cm_UISetup, null, ref objArray);

这篇关于使用加载项的项目在其他应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆