简体   繁体   中英

How to make a dialog appear when Visual Studio is started. - VS Extension

I am building a Visual Studio extension and I am stumped on how I would show a dialog when visual studio is started.

The main use for it is going to be when Visual studio starts my extension will check for updates if an update is found a dialog appears.

Information on extensions is very scarce so I have no idea how to do this. I am using C#.

Edit: I have tried adding the code in the package file that has all of the command code/callbacks into it's initialize event and it shows the dialog before visual studio appears to have even loaded and does not continue to load until I close it. I feel like I am getting closer though.

Is their an extension start up command I can create in VSCT file, kind of like they have for menu items?

I was able to figure out my problem. It took alot of trial and error due to the lack of info. I had originally tried the OnStartupcomplete() event but it was not working for me, hence I came here. The reason why it was not working was because the DTE object wasn't initialized at that point. So I was able to create the object and add the handler.

[ProvideAutoLoad(Microsoft.VisualStudio.Shell.Interop.UIContextGuids.NoSolution)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string)]

 protected override void Initialize()
    {
       //DTE gets called
        var dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
        _EventsObj = dte.Events.DTEEvents;
        _EventsObj.OnStartupComplete += OnStartupComplete;

    }

        public void OnStartupComplete()
    {
        //This is the code to launch the dialog.


        EvaluationDialog EvalForm = new EvaluationDialog();
        EvalForm.ShowDialog();

    }

I'm assuming you are using a Visual Studio Add-in project. If you want just a message box, in the Connect.cs file, add a reference to System.Windows.Forms and a using statement:

using System.Windows.Forms;

In the OnConnection method:

public void OnConnection(object application, 
    ext_ConnectMode connectMode, 
    object addInInst, ref Array custom)
{
    MessageBox.Show("message box");

    // or you could use your on dialog class
    var myDialog=new MyDialog();
    myDialog.Show();

    // ...
}

We are using OnAfterOpenProject. You can check for updates and bring up a dialog if found.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM