Search code examples
msbuildhooktarget

Custom ITaskHost on non windows system


I'm trying to register a custom ITaskHost in a HostServices to be accessed during the build process with the Task.HostObject Property.

HostServices hostServices = new HostServices();
string prjPath = "/mnt/devel/CrowIDE/build/Debug/netcoreapp3.1/src/CustomCrowIDE.targets"       
hostServices.RegisterHostObject(prjPath, "CustomBeforeBuild", "HookTask", this);
ProjectInstance pi = BuildManager.DefaultBuildManager.GetProjectInstanceForBuild (project);         
BuildRequestData request = new BuildRequestData (pi, new string[] { target }, hostServices);            
BuildResult result = BuildManager.DefaultBuildManager.Build (solution.buildParams, request);

But the HostObjet property of my custom task stays null.

I've read that ITaskHost are com object on windows that have to be registered in the ROT table, but here on linux, is it possible to bypass this constraints?


Solution

  • I've found another solution to forward result to the hosting application using the ILogger and the possibility to raise custom events with CustomBuildEventArgs. The trick is to use reflexion in the logger to bypass isolation.