Add a CustomAppDomainInitializer so that MSBuildLocator is installed in all appdomains.
We want MSBuildLocator assembly resolver to be installed in every appdomain created by the build, such as the one created by the ResolveCOMReference task.
This commit is contained in:
Родитель
235c5afdb9
Коммит
962457bdc0
Двоичный файл не отображается.
|
@ -2,6 +2,8 @@
|
|||
<PropertyGroup>
|
||||
<AssemblyName>Microsoft.SourceBrowser.Common</AssemblyName>
|
||||
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>..\..\key.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
|
||||
<DefineConstants>$(DefineConstants);NET461</DefineConstants>
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
#if NET461
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Policy;
|
||||
|
||||
namespace Microsoft.SourceBrowser.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// We want a callback when an appdomain is created, to install the MSBuildLocator
|
||||
/// into the XAML markup compilation appdomain and other appdomains, such as ones
|
||||
/// created by the ResolveCOMReference task.
|
||||
/// See https://github.com/KirillOsenkov/AppDomainManagerTest
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class can't be in the entrypoint assembly because of a CLR bug.
|
||||
/// We need a way to callback the entrypoint assembly when a new appdomain
|
||||
/// is created. Let's just instantiate a well-known type from the
|
||||
/// entrypoint assembly.
|
||||
/// </remarks>
|
||||
public class CustomAppDomainManager : AppDomainManager
|
||||
{
|
||||
/// <summary>
|
||||
/// This runs in the old appdomain when a new appdomain is created
|
||||
/// </summary>
|
||||
public override AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
|
||||
{
|
||||
var result = base.CreateDomain(friendlyName, securityInfo, appDomainInfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This runs in the new appdomain very early when it is being initialized
|
||||
/// </summary>
|
||||
public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
|
||||
{
|
||||
base.InitializeNewDomain(appDomainInfo);
|
||||
NotifyEntrypointAssembly();
|
||||
}
|
||||
|
||||
private void NotifyEntrypointAssembly()
|
||||
{
|
||||
if (AppDomain.CurrentDomain.IsDefaultAppDomain())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var assembly = Assembly.Load("HtmlGenerator");
|
||||
if (assembly == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var type = assembly.GetType("Microsoft.SourceBrowser.HtmlGenerator.AppDomainInitializer");
|
||||
if (type == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Activator.CreateInstance(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,13 @@
|
|||
namespace Microsoft.SourceBrowser.HtmlGenerator
|
||||
{
|
||||
public class AppDomainInitializer
|
||||
{
|
||||
/// <summary>
|
||||
/// This is called everytime a new appdomain is created in the current process.
|
||||
/// </summary>
|
||||
public AppDomainInitializer()
|
||||
{
|
||||
Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
|
||||
</startup>
|
||||
<runtime>
|
||||
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false" />
|
||||
<DisableFXClosureWalk enabled="true" />
|
||||
<appDomainManagerType value="Microsoft.SourceBrowser.Common.CustomAppDomainManager"/>
|
||||
<appDomainManagerAssembly value="Microsoft.SourceBrowser.Common"/>
|
||||
</runtime>
|
||||
</configuration>
|
Загрузка…
Ссылка в новой задаче