简体   繁体   中英

How to get unused references using roslyn?

I have hundreds of projects and I want to remove unused references from each project using roslyn. I saw this https://github.com/dotnet/roslyn/issues/625 but I have no Idea If it's already implemented and If there is a poc example that I can start with.

Please help me If you have any idea how to do this.

I did it by registering the compilation action that simply examines all the source trees in a project, finds all symbols referenced by them and considers the assemblies that declare them used, so everything else that's referenced by the project is unused. Here's the analyzer: https://github.com/HellBrick/HellBrick.Diagnostics/blob/ff0b3a415475eda3d2e9927a2ab4638ada5d7148/src/HellBrick.Diagnostics/UnusedReferences/UnusedReferencesAnalyzer.cs

Not sure if this is the most clean and correct way to do this, but it seems to get the job done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM