Пример #1
0
        public void Execute(GeneratorExecutionContext context)
        {
            // Research:
            //    https://dominikjeske.github.io/source-generators/
            //    https://docs.microsoft.com/en-us/dotnet/api/microsoft.build.execution.projectinstance.fromfile?view=msbuild-16-netcore
            //    https://github.com/unoplatform/Uno.SourceGeneration
            //    https://platform.uno/blog/using-msbuild-items-and-properties-in-c-9-source-generators/
            //    https://www.cazzulino.com/source-generators.html#debugging-source-generators



            // Experiments from:
            //  https://platform.uno/blog/using-msbuild-items-and-properties-in-c-9-source-generators/
            context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("$build_property.SomeName", out var value);
            // https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-reserved-and-well-known-properties?view=vs-2022
            context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.MSBuildProjectDirectory", out var projectDirectory);
            //var mainSyntaxTree = context.Compilation.SyntaxTrees.First(x => x.HasCompilationUnitRoot);
            //var directory = Path.GetDirectoryName(mainSyntaxTree.FilePath);

            var profiles = ProfileInfo.GetProfiles();

            foreach (var p in profiles)
            {
                var cache = Path.Combine(p.ProfilePath, ModelCacheBuilder.DefaultModelCacheFileName);
                if (File.Exists(cache))
                {
                    context.ReportDiagnostic(Diagnostic.Create("EFX-0", "EFX",
                                                               $"Found EFX DB Model Cache: {cache}",
                                                               DiagnosticSeverity.Warning, DiagnosticSeverity.Warning, true, 1));
                }
                else
                {
                    context.ReportDiagnostic(Diagnostic.Create("EFX-0", "EFX",
                                                               $"Did not find DB Model Cache for profile: {p.ProfilePath}",
                                                               DiagnosticSeverity.Warning, DiagnosticSeverity.Warning, true, 1));
                }
            }
        }