none
command with parameters RRS feed

  • Question

  • I have created a VSPackage using wizard that comes with VS SDK. The package defines one command that can be accessed from Tools menu. The package is loading fine, I can execute the command manually, from the command window, from command line (/Command switch) or using DTE.ExecuteCommand() call ("Tools.MyCommand"). However I would like the command to accept switches and arguments. Currently whenever I try to execute my command with arguments I get something like: Command "Tools.MyCommand" does not accept arguments or switches. How do I make sure that it accepts arguments? Should this be done during command registration in Initialize() method? Or maybe in .vsct file?
    Thursday, January 31, 2013 6:07 PM

Answers

  • Add the AllowParams CommandFlag in your VSCT for the command.

    Ryan

    • Marked as answer by TomaszGrobelny Wednesday, February 6, 2013 3:15 PM
    Thursday, January 31, 2013 8:32 PM
    Moderator
  • I presume you are not using an OleMenuCommand in your command handling (you don't explain how you are doing it above) or if you are you are not setting ParametersDescription to "$" (which means 'I take any kind of paramter').

    I can't really explain how adding DefaultInvisible made it work, because without ParametersDescription it doesn't work that way for me.

    If you are explicitly implementing IOleCommandTarget then you need to handle the Exec that is a query for your parameter information, the comment from the command window code that queries to see if the command accepts parameters:

    // To query the parameter type list of a command, we call Exec with
    // the LOWORD of nCmdexecopt set to OLECMDEXECOPT_SHOWHELP (instead of
    // the more usual OLECMDEXECOPT_DODEFAULT), the HIWORD of nCmdexecopt
    // set to VSCmdOptQueryParameterList, pvaIn set to NULL, and pvaOut
    // pointing to a VARIANT ready to receive the result BSTR.

    VSCmdOptQueryParameterList is 1.

    • Marked as answer by TomaszGrobelny Wednesday, February 6, 2013 3:15 PM
    Wednesday, February 6, 2013 1:03 AM
    Moderator

All replies

  • Add the AllowParams CommandFlag in your VSCT for the command.

    Ryan

    • Marked as answer by TomaszGrobelny Wednesday, February 6, 2013 3:15 PM
    Thursday, January 31, 2013 8:32 PM
    Moderator
  • Seems promising but does not work as expected - I still get the same error. I also tried to add another flag in the same place (DefaultInvisible) and this one works as expected.

    <Button guid="guidPwVsPackageCmdSet" id="cmdidMyCommand" priority="0x0100" type="Button">
      <Parent guid="guidPwVsPackageCmdSet" id="MyMenuGroup" />
      <Icon guid="guidImages" id="bmpPic1" />
      <CommandFlag>DefaultInvisible</CommandFlag>
      <CommandFlag>AllowParams</CommandFlag>
      <Strings>
        <ButtonText>Execute My Command</ButtonText>
      </Strings>
    </Button>
    

    Any ideas?
    Friday, February 1, 2013 8:34 AM
  • I suspect you are being fooled, DefaultInvisible has nothing at all to do with accepting parameters. I suspect after adding AllowParams the VSCT was not recompiled/re-embedded (I have seen bugs where the build system does not always do that). I would remove the DefaultInvisible flag unless you need the behavior it provides, do a clean build of your project and test again. I guarantee you (as the person that owns the command system code) that AllowParams is what you need and DefaultInvisible has nothing to do with accepting params.
    Friday, February 1, 2013 3:45 PM
    Moderator
  • I know that DefaultInvisible has nothing to do with params - I added it just to make sure that changes made to .vsct file are seen by Visual Studio. It seems that DefaultInvisible takes effect (the menu item disappears), but AllowParams does not (command still does not accept params). Consequently, it does not seem to be a build issue.
    Friday, February 1, 2013 6:23 PM
  • Any updates?

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 4, 2013 2:58 AM
    Moderator
  • Who are you asking? Me or Ryan?
    Tuesday, February 5, 2013 9:01 AM
  • There is nothing to update from my side, I added a command with AllowParams and it worked just fine. I can't comment on what Tomasz is seeing since I can't repro it.
    Tuesday, February 5, 2013 3:59 PM
    Moderator
  • Which version of VS are you testing on? I am testing on VS2010SP1.

    And what are the steps that you tried? In my case:

    1. I created a new vspackage project (Visual C#, no test projects, only menu command)

    2. Added [ProvideAutoLoad(VsConstants.UICONTEXT.NoSolution_string)] attribute

    3. Add commandflag as above

    4. Run experimental instance of VS and try to execute command from command window.

    Tuesday, February 5, 2013 10:39 PM
  • I presume you are not using an OleMenuCommand in your command handling (you don't explain how you are doing it above) or if you are you are not setting ParametersDescription to "$" (which means 'I take any kind of paramter').

    I can't really explain how adding DefaultInvisible made it work, because without ParametersDescription it doesn't work that way for me.

    If you are explicitly implementing IOleCommandTarget then you need to handle the Exec that is a query for your parameter information, the comment from the command window code that queries to see if the command accepts parameters:

    // To query the parameter type list of a command, we call Exec with
    // the LOWORD of nCmdexecopt set to OLECMDEXECOPT_SHOWHELP (instead of
    // the more usual OLECMDEXECOPT_DODEFAULT), the HIWORD of nCmdexecopt
    // set to VSCmdOptQueryParameterList, pvaIn set to NULL, and pvaOut
    // pointing to a VARIANT ready to receive the result BSTR.

    VSCmdOptQueryParameterList is 1.

    • Marked as answer by TomaszGrobelny Wednesday, February 6, 2013 3:15 PM
    Wednesday, February 6, 2013 1:03 AM
    Moderator
  • Changing MenuCommand to OleMenuCommand and setting the ParametersDescription property to "$" made it work. Thanks a lot.

    Is there any documentation on what can I assign to ParametersDescription property? "$" seems kind of magical to me...

    Wednesday, February 6, 2013 3:14 PM
  • I don't believe it is (well) documented, I can try to put something together and post it later, though I am a bit swamped at the moment, so it may take a day or two. Suffice to say it is far more complicated than either having "$" or nothing, there are named parameters, short-hand names, specific parameter types that enable things like auto complete in the command window (like the file name auto-complete of commands like File.OpenFile), etc...
    Wednesday, February 6, 2013 5:58 PM
    Moderator
  • It would be very nice of you if you could write a few words of documentation about ParametersDescription. Not that I need it to complete my objectives right now, but it would certainly be useful to anybody dealing with commands.
    Thursday, February 7, 2013 10:21 AM