-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Use AssemblyLoadContext Name instead of AppDomain #9353
Use AssemblyLoadContext Name instead of AppDomain #9353
Conversation
f875fa1
to
d8cb65f
Compare
d8cb65f
to
6256d67
Compare
6256d67
to
95f0f64
Compare
Could you possibly reuse/repurpose this integration test for assembly loads tracking?: https://github.com/dotnet/msbuild/blob/main/src/Build.UnitTests/BinaryLogger_Tests.cs#L192-L250 (plus if needed we have
All good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution!
It looks good to me as is.
Please try if you can have a simple test verifying the NET behavior.
Once this is cleared (or once we know reasons why it's complicated - so I can jump in to help) I'm happy to sign off
I did see that test, so I'll take a look at extending it out a bit to cover the relevant part of the log change. |
@JanKrivanek I took the test and split it into two versions, one that looks for the presence of Do you think it would be worth having a test that actually shows a task loading into a non-default |
I leave up on you :-) If you'd have to test another load context you'd need to have a task in separate assembly - all our tests use tasks that are compiled within the already loaded test assemblies, so you'd either need to add a separate project (too heavyweight for the test) or build one-off temp assembly within the test.
If you'll leave the test as is (totally fine for the purpose they're validating) - those 2 differ only in that single assertion string - it'd be more readable if those 2 call a single helper giving it the assertion string as param.
|
Not all of them! One is actually perfect for this; check out https://github.com/dotnet/msbuild/blob/08494c73128451a3f7cfb47a5e9cbd63f5507a1f/src/Shared/UnitTests/TypeLoader_Dependencies_Tests.cs |
19f5cb9
to
5821a90
Compare
@JanKrivanek I pushed up a new commit that adjusts the first test in the way you suggested, and I augmented the test @rainersigwald pointed out as well. How does that look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Fixes #9348
Context
When MSBuild was updated to isolate tasks into a custom
AssemblyLoadContext
,AssemblyLoadsTracker
was not updated to be aware of this change. This means that the log messages always sayAppDomain: [Default]
and don't show any information about whichAssemblyLoadContext
was used to load the assembly.Changes Made
When
FEATURE_ASSEMBLYLOADCONTEXT
is defined:AssemblyLoadsTracker
now populatesAssemblyLoadBuildEventArgs
with the name of theAssemblyLoadContext
used to load the assembly . TheappDomainDescriptor
parameter is re-used to do this.AssemblyLoadBuildEventArgs.Message
to use label theAppDomainDescriptor
value as "AssemblyLoadContext" instead of "AppDomain".Testing
I couldn't find any existing tests that coveredUnit tests added.AssemblyLoadsTracker
behavior, so I haven't updated or added any tests yet.Notes
AssemblyLoadContext.GetLoadContext
can returnnull
, but only if the assembly loaded isn't derived fromRuntimeAssembly
. The only way I'm aware that would be true is ifMetadataLoadContext
was used to load the assembly asReflectionOnly
, and I wouldn't think that would be a relevant case here. For now, if it wasnull
for some reason, I've madeappDomainDescriptor
have the value "unknown". Otherwise, if I let thenull
through,AssemblyLoadBuildEventArgs
would print "[Default]" in its message, which would not be correct.I added a new string resource in a separate commit because I wasn't sure if that would be okay or not. I know that means there's some translation work to do. Looking at the existing translations for
TaskAssemblyLoaded
, since "AppDomain" isn't translated, it looks like it should just be a matter of copying the existing one and replacing that one word.