コード例 #1
0
        private AnalyzersAndFixers GetAnalyzersAndFixers(Project project)
        {
            var context = new AnalyzerLoadContext();

            var analyzerAssemblies = project.AnalyzerReferences
                                     .Select(reference => TryLoadAssemblyFrom(reference.FullPath, context))
                                     .OfType <Assembly>()
                                     .ToImmutableArray();

            return(AnalyzerFinderHelpers.LoadAnalyzersAndFixers(analyzerAssemblies));
        }
コード例 #2
0
        private Assembly?TryLoadAssemblyFrom(string?path, AnalyzerLoadContext context)
        {
            // Since we are not deploying these assemblies we need to ensure the files exist.
            if (path is null || !File.Exists(path))
            {
                return(null);
            }

            try
            {
                context.AssemblyFolderPath = Path.GetDirectoryName(path);

                // First try loading the assembly from disk.
                return(context.LoadFromAssemblyPath(path));
            }
            catch { }

            // Give up.
            return(null);
        }