-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5be281e
commit d775c0c
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#if FEATURE_ASSEMBLYLOADCONTEXT | ||
|
||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Shared; | ||
using Microsoft.Build.Utilities; | ||
using System.Runtime.Loader; | ||
|
||
namespace Microsoft.Build.UnitTests | ||
{ | ||
public class ValidateAssemblyLoadContext : Task | ||
{ | ||
public override bool Execute() | ||
{ | ||
var thisLoadContext = AssemblyLoadContext.GetLoadContext(typeof(ValidateAssemblyLoadContext).Assembly); | ||
|
||
// Check by name because this always reports false, presumably due to ALC shenanigans: | ||
// if (thisLoadContext is MSBuildLoadContext context) | ||
if (thisLoadContext.GetType().FullName == typeof(MSBuildLoadContext).FullName) | ||
{ | ||
if (!thisLoadContext.Name.EndsWith(typeof(ValidateAssemblyLoadContext).Assembly.GetName().Name + ".dll")) | ||
{ | ||
Log.LogError($"Unexpected AssemblyLoadContext name: \"{thisLoadContext.Name}\", but the current executing assembly was {typeof(ValidateAssemblyLoadContext).Assembly.GetName().Name}"); | ||
} | ||
else | ||
{ | ||
Log.LogMessage(MessageImportance.High, $"Task {nameof(ValidateAssemblyLoadContext)} loaded in AssemblyLoadContext named {thisLoadContext.Name}"); | ||
} | ||
} | ||
else | ||
{ | ||
Log.LogError($"Load context was a {thisLoadContext.GetType().AssemblyQualifiedName} instead of an {typeof(MSBuildLoadContext).AssemblyQualifiedName}"); | ||
} | ||
|
||
return !Log.HasLoggedErrors; | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters