dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.21k stars 5.86k forks source link

Document how to access reference assemblies from Roslyn #12317

Open svick opened 5 years ago

svick commented 5 years ago

Describe the new topic

Help us make content visible

cc: @BillWagner

Thraka commented 5 years ago

Hi @svick

Thank you for the suggestion. I've categorized this request and put it in the backlog.

dotnet-bot commented 3 years ago

This issue has been closed as part of the issue backlog grooming process outlined in #22351.

That automated process may have closed some issues that should be addressed. If you think this is one of them, reopen it with a comment explaining why. Tag the @dotnet/docs team for visibility.

Youssef1313 commented 3 years ago

I believe this issue needs to be addressed.

glopesdev commented 3 years ago

Also clarify the relationship with the basic reference assemblies project: https://github.com/jaredpar/basic-reference-assemblies/issues/12

NMSAzulX commented 3 years ago

Thanks to this issue, I think I should give some feedback. I am using roslyn and string scripts to build dynamic assemblies. I have made an open source library that has been used by many people. So far, there is no problem except that asp.net can't unload the domain. It automatically manages references. I divided the reference into two parts, 1. all assemblies from the DependencyContext .Default, and 2 references from dynamic compilation. Each time the assembly is compiled in the same domain, it adds up the references of guarantee 1 and 2 to roslyn to compile. Through reflection, I pre-cache all using code. Users only need to pay attention to their class code or method code.

But I found that DependencyContext can't reflect private fields because its meta-information is incomplete. If it is not complete, at least it should be described in the document. (If you say private fields should not be used by developers. I want to say, never underestimate developers' customized ideas, they will customize high-performance libraries that belong to their own needs. It is necessary to use the private / internal field.).

I have a little suggestion: allow developers to convert assemblies in the domain into references. Perhaps roslyn can automatically manage references based on domain (AssemblyLoadContext). This becomes easier when there is a unified reference management API.(If you are worried about the compatibility problems caused by the version, you can start with the version that supports assemblyloadcontext.)

NMSAzulX commented 3 years ago

< PreserveCompilationContext > this gives me a headache, and I have to release a nuget package for this so that developers can ignore the < PreserveCompilationContext > tag.

https://github.com/dotnetcore/Compile.Environment/blob/master/DotNetCore.Compile.Environment/targets/DotNetCore.Compile.Environment.targets

https://github.com/dotnetcore/Compile.Environment/blob/master/DotNetCore.Compile.Environment/DotNetCore.Compile.Environment.csproj#L32

MSDN-WhiteKnight commented 3 years ago

But I found that DependencyContext can't reflect private fields because its meta-information is incomplete. If it is not complete, at least it should be described in the document.

DependencyContext returns paths to reference assemblies. Reference assemblies by design does not contain private members, it is already documented here: https://docs.microsoft.com/en-us/dotnet/standard/assembly/reference-assemblies#reference-assemblies-structure It is not directly related to roslyn, because you can't reference private members in C#/VB anyway.

NMSAzulX commented 3 years ago

@MSDN-WhiteKnight Thanks. I can only use private fields in this way ,
domain.addreference(typeof(List<int>).Assembly.Location);