示例#1
0
        private static RazorProjectEngine GetDiscoveryProjectEngine(
            IReadOnlyList <MetadataReference> references,
            StaticCompilationTagHelperFeature tagHelperFeature)
        {
            var discoveryProjectEngine = RazorProjectEngine.Create(RazorConfiguration.Default, new VirtualRazorProjectFileSystem(), b =>
            {
                b.Features.Add(new DefaultMetadataReferenceFeature {
                    References = references
                });
                b.Features.Add(tagHelperFeature);
                b.Features.Add(new DefaultTagHelperDescriptorProvider());

                CompilerFeatures.Register(b);
                RazorExtensions.Register(b);
            });

            return(discoveryProjectEngine);
        }
示例#2
0
        private static IReadOnlyList <TagHelperDescriptor> GetTagHelpersFromCompilation(Compilation compilation, StaticCompilationTagHelperFeature tagHelperFeature, SyntaxTree syntaxTrees)
        {
            var compilationWithDeclarations = compilation.AddSyntaxTrees(syntaxTrees);

            tagHelperFeature.Compilation    = compilationWithDeclarations;
            tagHelperFeature.TargetAssembly = compilationWithDeclarations.Assembly;

            return(tagHelperFeature.GetDescriptors());
        }
示例#3
0
        private IReadOnlyList <TagHelperDescriptor> GetTagHelpers(IEnumerable <MetadataReference> references, StaticCompilationTagHelperFeature tagHelperFeature, Compilation compilation)
        {
            List <TagHelperDescriptor> descriptors = new();

            tagHelperFeature.Compilation = compilation;
            foreach (var reference in references)
            {
                if (compilation.GetAssemblyOrModuleSymbol(reference) is IAssemblySymbol assembly)
                {
                    tagHelperFeature.TargetAssembly = assembly;
                    descriptors.AddRange(tagHelperFeature.GetDescriptors());
                }
            }
            return(descriptors);
        }