jaredpar / basic-reference-assemblies

Produce NuPkg files that have .NET Reference assemblies as resources
MIT License
96 stars 15 forks source link

What is the difference between 'DependencyContext' and 'basic-reference-assemblies'? #12

Open NMSAzulX opened 3 years ago

NMSAzulX commented 3 years ago

Hello. I am using DependencyContext .Default .CompileLibraries to get references. which namespace in Microsoft.Extensions.DependencyModel.

It works(However, there are some fields or attributes whose metadata cannot be found during dynamic compilation).

What is the difference between Microsoft.Extensions.DependencyModel and basic-reference-assemblies?

jaredpar commented 3 years ago

Can you link to any docs to that API? I'm unfamiliar with that so hard to say how it relates to this project.

NMSAzulX commented 3 years ago

@jaredpar https://github.com/dotnet/runtime/tree/main/src/libraries/Microsoft.Extensions.DependencyModel

When I used dynamic compilation before, the roslyn error could not find the object reference. For dynamic compilation is a very troublesome thing, currently I use


foreach (var asm in DependencyContext
            .Default
            .CompileLibraries
            .SelectMany(cl => cl.ResolveReferencePaths()))
            {
                DomainManagement.Default.AddReferencesFromDllFile(asm);
            }

this code to solve the problem.

NMSAzulX commented 3 years ago

When I use the dll file provided by DependencyContext to reflect private fields, such as _size of List<int>. It will indicate that this field cannot be found. So I have to reload typeof (List<int>). Assenbly.Location into the reference to find _size;. I suspect DependencyContext can't provide metadata other than public level, or I'm not familiar with it.