开发者

Connect.Exec() not executing (Visual Studio 2010 Addin)

I'm trying to open a form from Visual Studio add-in code, Connect class:

public void Exec(
        string pCommandName,
        vsCommandExecOption pExecuteOption,
        ref object pVarIn,
        ref object pVarOut,
        ref bool pHandled)
    {
        pHandled = false;
        if (pExecuteOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
        {
            if (pCommandName == "VisualStudioSolutionGenerator.Connect.VisualStudioSolutionGenerator")
      开发者_如何学Go      {
                Form1 form = new Form1();
                form.Show();
                pHandled = true;
                return;
            }
        }
    }

This works fine if Form1 is defined in the same assembly, but if it is in another assembly, Exec() will not even be called. I saw a similar question being posted here, but it was not answered.

Anyone has any idea why this is the case? Thanks


This is what solved the problem:

I created the addin project named 'VisualStudioSolutionGenerator' the same way on a different machine and got this error when I tried to execute it in debug mode:
"The Add-in <addin_name> failed to load or caused an exception ...".
Error code was 80070002, which means some files are missing.
So I checked "C:\Users\<user_name>\Documents\Visual Studio 2010\Addins\VisualStudioSolutionGenerator - For Testing.AddIn" (Windows 7 machine) and the Assembly tag in that file pointed to "<addin_project_path>/bin/VisualStudioSolutionGenerator.dll". This file exists, but dlls for other solution projects used by addin project, including the one with 'Form1' were not copied to this folder on build, they are only present in "<addin_project_path>/bin/Debug/" folder.

Changing Assembly tag in 'For Testing' addin file to "<addin_project_path>/bin/Debug/" removed the exception and Connect.Exec() now executes normally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜