Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppDomains #16

Open
KirillOsenkov opened this issue Mar 6, 2018 · 9 comments
Open

AppDomains #16

KirillOsenkov opened this issue Mar 6, 2018 · 9 comments

Comments

@KirillOsenkov
Copy link
Member

We need to figure out what to do about AppDomains (such as MarkupCompiler):

>	PresentationBuildTasks.dll!MS.Internal.MarkupCompiler.OnSourceFileResolve Line 693	C#
 	PresentationBuildTasks.dll!MS.Internal.MarkupCompiler.Initialize Line 460	C#
 	PresentationBuildTasks.dll!MS.Internal.MarkupCompiler.Compile Line 265	C#
 	PresentationBuildTasks.dll!MS.Internal.CompilerWrapper.DoCompilation Line 268	C#
 	[AppDomain (HtmlGenerator.exe�, #1) -> AppDomain (markupCompilationAppDomain�, #2)]	
 	PresentationBuildTasks.dll!Microsoft.Build.Tasks.Windows.MarkupCompilePass1.DoMarkupCompilation Line 1274	C#
 	PresentationBuildTasks.dll!Microsoft.Build.Tasks.Windows.MarkupCompilePass1.Execute Line 194	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute Line 631	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask Line 787	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskBuilder.InitializeAndExecuteTask Line 660	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskBuilder.ExecuteBucket Line 441	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskBuilder.ExecuteTask Line 331	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskBuilder.ExecuteTask Line 182	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TargetEntry.ProcessBucket Line 850	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TargetEntry.ExecuteTarget Line 515	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TargetBuilder.ProcessTargetStack Line 467	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TargetBuilder.Microsoft.Build.BackEnd.ITargetBuilderCallback.LegacyCallTarget Line 285	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskHost.InternalBuildProjects Line 671	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.MSBuild.ExecuteTargets Line 680	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.CallTarget.ExecuteInternal Line 134	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask Line 779	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskBuilder.InitializeAndExecuteTask Line 660	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskBuilder.ExecuteBucket Line 441	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskBuilder.ExecuteTask Line 331	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TaskBuilder.ExecuteTask Line 182	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TargetEntry.ProcessBucket Line 850	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TargetEntry.ExecuteTarget Line 515	C#
 	Microsoft.Build.dll!Microsoft.Build.BackEnd.TargetBuilder.ProcessTargetStack Line 467	C#
@KirillOsenkov
Copy link
Member Author

KirillOsenkov commented Mar 6, 2018

We can use AppDomainManager to install the resolver for all appdomains in the process:
https://github.com/KirillOsenkov/AppDomainManagerTest/blob/master/README.md

@DustinCampbell
Copy link
Member

Relying on AppDomainManager is probably not the best solution since it exposes the fact that we're doing custom AppDomain resolution. IMO, the Locator should push the assembly resolution event handler somewhere into MSBuild. Then, MSBuild should hook it up when creating AppDomains for tasks that require them.

FWIW, at the moment, this is a big problem with using the locator approach generally because any XAML-based project will fail..

@KirillOsenkov
Copy link
Member Author

Yes, if we control the place where we create appdomains for tasks then it is certainly better.

@rainersigwald
Copy link
Member

MSBuild controls it for AppDomainIsolatedTask, but tasks are (sadly) free to create their own AppDomains. Not sure if XAML does that, though.

@DustinCampbell
Copy link
Member

FWIW, it looks like XAML does create their own AppDomain, so this is a sticky problem.

@KirillOsenkov
Copy link
Member Author

A workaround here for the XAML case is to set AlwaysCompileMarkupFilesInSeparateDomain=false
KirillOsenkov/SourceBrowser@a675330

KirillOsenkov added a commit to KirillOsenkov/MSBuildStructuredLog that referenced this issue Aug 18, 2018
@KirillOsenkov
Copy link
Member Author

I was able to successfully use the AppDomainManager to intercept AppDomain creation to install the MSBuildLocator in all AppDomains, and it works great with XAML markup compile appdomain.

https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/master/src/StructuredLogger/CustomAppDomainManager.cs

@KirillOsenkov
Copy link
Member Author

Here's another successful example of installing MSBuildLocator for all appdomains:
KirillOsenkov/SourceBrowser@962457b

@sharwell
Copy link
Member

sharwell commented Jun 2, 2019

It would be nice to make that CustomAppDomainManager part of the MSBuild Locator assembly, which could optionally be specified in the app.config file for an application. For now I've added a package reference to SourceBrowser just so I can use that type. I would have just copied the class, but it doesn't work with publicsign.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants