locked
Problems with Debug Engine (Launcher) Properties RRS feed

  • Question

  • Hello
    I am currently writing my own Debug Engine and have some problems with the Launcher configuration.
    You can select my Debug Engine in the Project Properties \ Debugging \ Debugger To Launch listbox.
    So the installation of my engine and its launcher worked fine and I can see my own custom fields in the project properties.
    These properties get defined in an xml file that the project wizzard generates when I create a Visual C++ Debugger Launch Extension project and look something like this:

    ===

    <Rule Name="VendorNameCoolDebugger"
          DisplayName="VendorName Cool Debugger"
          PageTemplate="debugger"
          Description="VendorName Cool Debugger options"
          xmlns="http://schemas.microsoft.com/build/2009/properties">
      <Rule.DataSource>
        <DataSource Persistence="UserFile" />
      </Rule.DataSource>
      <StringProperty Name="LocalDebuggerCommand" DisplayName="Command"
                      Description="The debug command to execute."
                      F1Keyword="VC.Project.IVCLocalDebugPageObject.Command">
        <StringProperty.ValueEditors>
          <ValueEditor EditorType="DefaultFindFullPathPropertyEditor" DisplayName="&lt;regsvr32.exe&gt;">
            <ValueEditor.Metadata>
              <NameValuePair Name="Exename" Value="regsvr32.exe" />
            </ValueEditor.Metadata>
          </ValueEditor>
          <ValueEditor EditorType="DefaultStringPropertyEditor" DisplayName="&lt;Edit...&gt;"/>
          <ValueEditor EditorType="DefaultFilePropertyEditor" DisplayName="&lt;Browse...&gt;"/>
        </StringProperty.ValueEditors>
      </StringProperty>
        
      <StringProperty Name="LocalDebuggerCommandArguments" DisplayName="Command Arguments"
                      Description="The command line arguments to pass to the application."
                      F1Keyword="VC.Project.IVCLocalDebugPageObject.CommandArguments">
        <Argument Property="LocalDebuggerCommand" />
      </StringProperty>
      <StringProperty Name="LocalDebuggerWorkingDirectory" DisplayName="Working Directory"
                    Description="The application's working directory. By default, the directory containing the project file."
                    Subtype="folder"
                    F1Keyword="VC.Project.IVCLocalDebugPageObject.WorkingDirectory"/>
      <BoolProperty Name="LocalDebuggerAttach" DisplayName="Attach"
                    Description="Specifies whether the debugger should attempt to attach to an existing process when debugging starts."
                    F1Keyword="VC.Project.IVCLocalDebugPageObject.Attach"/>

    ...

    ===

    My problem now is the following:

    1) How can I define that my Debug Engine is NOT the default one for every new C++ native project?
       Changing this default would be a major impact of my engine to the normal Visual Studio environment, and I don't want that.
       There is an xml token called "Order" and I thought that would fix it, but it does not have any observable effect...

    2) How can I define a default entry for any new (or even already existing) StringProperty or BoolProperty?
       There is a xml token called "Default", but it does not change anything in a new created project.
       It does not work on properties that the wrapped Visual Studio Native Debug Engine knows, and it also does not work for my new entered properties.
       Interestingly some of the fields have defaults, that are not defined in that xml file.
       So for example the LocalDebuggerAttach has the default value "No" and I could not find any way to define it to "Yes" (or "true" or anything).

    Any1 an idea how to solve these issues?
    Regards,
    Belkar

    Thursday, June 21, 2012 4:01 PM

All replies

  • 1) How can I define that my Debug Engine is NOT the default one for every new C++ native project?
       Changing this default would be a major impact of my engine to the normal Visual Studio environment, and I don't want that.
       There is an xml token called "Order" and I thought that would fix it, but it does not have any observable effect...

    Excellent question.  The "vendorname.props" file that is included in your project as this XML snippet by default:

    <DebuggerFlavor>VendorNameCoolDebugger</DebuggerFlavor>

    This is what forces your debugger to be the default one.  If your debugger is only available when the user targets a custom platform that you're defining, then setting yours as the default can be the right choice.  But in your case it sounds like the fix is simply to remove this line from the vendorname.props file. 

    2) How can I define a default entry for any new (or even already existing) StringProperty or BoolProperty?
       There is a xml token called "Default", but it does not change anything in a new created project.
       It does not work on properties that the wrapped Visual Studio Native Debug Engine knows, and it also does not work for my new entered properties.
       Interestingly some of the fields have defaults, that are not defined in that xml file.
       So for example the LocalDebuggerAttach has the default value "No" and I could not find any way to define it to "Yes" (or "true" or anything).

    Another good question.  The Default xml attribute as you've already discovered, is almost useless.  The way to set defaults that impact Visual Studio is to go back into that vendorname.props file and set your property default values there, similar to the line that I advised above that you delete.

    By the way, I suggest you keep all your own debugger properties separate from other debuggers.  For example, rather than using LocalDebuggerAttach, consider using VendorNameDebuggerAttach.

    And (of course) change all references to VendorNameCoolDebugger to something meaningful to you. ;-)

    • Proposed as answer by N. Blanc Wednesday, November 14, 2012 4:58 PM
    Thursday, June 21, 2012 5:11 PM
  • Hello Andrew

    Both issues solved. It works fine as you describe it. Great :)

    I have one follow up question:
    When I have a StringProperty with Subtype="folder", then I get this "Browse..." menu entry.
    That's fine so far. But unfortunately the resulting path is relative (to the project).
    How can I define that I want an absolute path as result of the browse?

    I wonder if there is any documentation (MSDN, Microsoft Press, etc.) for these kind of problems?
    I am sure my boss would pay for that...

    Thank you very much for this fast response,
    Belkar

    Friday, June 22, 2012 8:22 AM
  • When I have a StringProperty with Subtype="folder", then I get this "Browse..." menu entry.

    That's fine so far. But unfortunately the resulting path is relative (to the project).
    How can I define that I want an absolute path as result of the browse

    I don't think that value editor exposes such an option to generate a full path.  But absolute paths are highly discouraged anyway since they make the project not transfer across locations easily.  But I can give you a couple of alternatives we recommend and use ourselves.  Since I think you're only consuming this relative path from your debug launcher, you can convert the property value from a relative path to a full path like this:

    // At the top of your source file:
    using Microsoft.VisualStudio.Project.Utilities;

    // As a member of your launcher class:
    [Import]
    private UnconfiguredProject UnconfiguredProject { get; set; }

    // Inside your method
    string relativePathToConvert;
    string absolutePath = this.UnconfiguredProject.MakeRooted(relativePathToConvert);

    Does that work for you?

    I wonder if there is any documentation (MSDN, Microsoft Press, etc.) for these kind of problems? I am sure my boss would pay for that...

    I'm afraid debugger launch extensibility isn't well documented (yet).

    Friday, June 22, 2012 3:01 PM

  • This is a nice solution to convert a relative path to an absolute (solution path dependent) path.
    But I need an absolute installation tool path that is not inside or relative or depending to the solution.
    So using a relative path would actually force my user to redefine it when he moves the project around.

    I see that other fields with Browse support this absolute search, so there must be a way to specify that.
    An example is the Project Properties \ Debugging \ Command field from the Windows Local Debugger.
    That's exactly what I need.

    Regards,
    Belkar

    Thursday, June 28, 2012 8:37 AM
  • Ah, I think I understand now.  The file picker will generate an absolute path, whereas the folder picker generates a project relative path.  

    I just double-checked, and none of the built-in property value editors will produce an absolute folder path for you from a picker dialog, sorry.  If you're willing to write an extension DLL, there is a such thing as custom value editors where you can write your own that would do exactly what you want, and integrate the same way so the user experience is similar to the default folder picker except that it produces a full path.  Are you interested in pursuing that?

    Friday, June 29, 2012 2:14 PM
  • I just discussed this with my peers.
    Currently we are happy with an absolute file browse and will avoid absolute paths by asking for a specific file in that folder (and determine the path from that).
    In case this will be a blocking issue in future I will pursue the custom value editor solution.

    Anyway, the fact that a folder is relative and a file is absolute sounds a bit strange to me...
    Maybe you should add a feature request to add a little flag in the xml definition to define the kind of path the browse dialog returns.

    Thx for your fast response,

    Belkar

    Monday, July 2, 2012 1:37 PM
  • Hello,

    I am trying to set default values for my debugger options. The solution described by Andrew works fine except for one glitch: If the default value is "$(TargetPath)" and the user leaves it as is then the property evaluates to an empty string during launch.

    In my function CanLaunch() I can work around this issue by checking the value of "DebuggerProperties.ConfigurationGeneral.TargetPath" but I would like to understand the problem and have a clean implementation. Can anyone shed light on this issue?

    Thanks,

    Nicolas

    public override bool CanLaunch(DebugLaunchOptions launchOptions)
    {
      var command = this.DebuggerProperties.MyDebugLauncher.CompanyMyDebuggerCommand.EvaluatedValueAtEnd;
      if (string.IsNullOrEmpty(command)) {
        command = this.DebuggerProperties.MyDebugLauncher.CompanyMyDebuggerCommand.UnevaluatedValueAtEnd;
        if (command == "$(TargetPath)") {
          command = this.DebuggerProperties.ConfigurationGeneral.TargetPath.EvaluatedValueAtEnd;
        }
        else {
          command = "";
        }
      }
      return !string.IsNullOrEmpty(command);
    }


    • Edited by N. Blanc Wednesday, October 31, 2012 3:59 PM
    Wednesday, October 31, 2012 3:48 PM
  • N. Blanc,

    The reason your CompanyMyDebuggerCommand property is empty is probably because you set the default value in a .props file that is imported before TargetPath is actually set (which IIRC is actually way down in the project .targets file, unfortunately).  Your workaround seems reasonable, although I'll ask my coworkers if they can recommend anything better.

    Wednesday, October 31, 2012 4:06 PM