Git Product home page Git Product logo

Comments (2)

jobmarley avatar jobmarley commented on June 2, 2024

Hey,

that's a bit late, but I ran into the same kind of issues. And after quite a bit of investigation I was able to understand what's going on.
So first, the c++ project system doesn't load the debugger extension on project load (I don't even know if it happens with other project types). If you want your extension to be loaded, you can use
[Export(ExportContractNames.Scopes.ConfiguredProject, typeof(IProjectDynamicLoadComponent))]
If you do that you will see that the LoadAsync/UnloadAsync are called if you have the right capability (you can try with "VisualC").

Even though that's unintuitive, the list of available debuggers is not defined by the exported MEF debuggers, but by the rules registered for the project.
When you click the debug button, the exported IDebugLaunchProvider are enumerated and the one with a matching name is instanciated and CanLaunchAsync, etc... are called.
Now the issue is the documentation suggest that we use ExportPropertyXamlRuleDefinition, but I wasn't able to make that work at all (in vs 2022).
The best way in my opinion is to use IProjectDynamicLoadComponent. Then import a IAdditionalRuleDefinitionsService in the constructor, and add the rule manually.
Then your debugger will appears in the drop down menu.

[Export(ExportContractNames.Scopes.ConfiguredProject, typeof(IProjectDynamicLoadComponent))]
[ExportDebugger("MyDebugger")]
[AppliesTo("VisualC")]
public class MyDebugLaunchProvider
	: DebugLaunchProviderBase,
	IProjectDynamicLoadComponent
{
	private ConfiguredProject m_configuredProject = null;

	[ImportMany(ExportContractNames.VsTypes.IVsHierarchy)]
	private OrderPrecedenceImportCollection<IVsHierarchy> IVsHierarchies { get; set; }

	[ImportingConstructor]
	public MyDebugLaunchProvider(ConfiguredProject configuredProject, IAdditionalRuleDefinitionsService rds)
		: base(configuredProject)
	{
		IVsHierarchies = new OrderPrecedenceImportCollection<IVsHierarchy>(projectCapabilityCheckProvider: configuredProject.UnconfiguredProject);
		m_configuredProject = configuredProject;
		Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("XamlRuleToCode:MyDebugger.xaml");
		Rule rule = ((IProjectSchemaNode)XamlServices.Load(stream)).GetSchemaObjects(typeof(Rule)).Cast<Rule>().FirstOrDefault();
		rds.AddRuleDefinition(rule, "Project");
	}

	public override Task<bool> CanLaunchAsync(DebugLaunchOptions launchOptions)
	{
		// perform any necessary logic to determine if the debugger can launch
		return Task.FromResult(true);
	}

	public override async Task<IReadOnlyList<IDebugLaunchSettings>> QueryDebugTargetsAsync(DebugLaunchOptions launchOptions)
	{
		var settings = new DebugLaunchSettings(launchOptions);

		settings.LaunchDebugEngineGuid = DebuggerEngines.NativeOnlyEngine;

		settings.AppPackageLaunchInfo = new VsAppPackageLaunchInfo();
		settings.Arguments = "";
		settings.CurrentDirectory = "<exedir>";
		settings.Executable = "<exepath>.exe";
		settings.LaunchOperation = DebugLaunchOperation.CreateProcess;
		settings.LaunchOptions = launchOptions;
		settings.Options = "";
		settings.PortName = "";
		settings.PortSupplierGuid = Guid.Empty;
		settings.ProcessId = 0;
		settings.ProcessLanguageGuid = Guid.Empty;
		settings.Project = IVsHierarchies.FirstOrDefault()?.Value;
		settings.RemoteMachine = "";
		settings.SendToOutputWindow = false;
		settings.StandardErrorHandle = IntPtr.Zero;
		settings.StandardInputHandle = IntPtr.Zero;
		settings.StandardOutputHandle = IntPtr.Zero;

		return new IDebugLaunchSettings[] { settings };
	}

	public async Task LoadAsync()
	{
			
	}
	public async Task UnloadAsync()
	{
	}
}

Hopefully that might help you or others who run into the same issue.

from vsprojectsystem.

svenbieg avatar svenbieg commented on June 2, 2024

I have some DesignTime.props

  <ItemGroup>
    <ProjectCapability Include="CustomDebugger" />
  </ItemGroup>

and DesignTime.targets

  <ItemGroup>
    <PropertyPageSchema Include="Rules\CustomDebugger.xaml" />
  </ItemGroup>

like shown in the CpsExtension-example. The Debugger shows up in the UI and the DLL is loaded, but DebugLaunchProvider isn't invoked.

I've added the code above

[Export(ExportContractNames.Scopes.ConfiguredProject, typeof(IProjectDynamicLoadComponent))]

but it does nothing.

from vsprojectsystem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.