public override void Execute(SourceGeneratorContext context) { #if DEBUG Debugger.Launch(); #endif _logger = context.GetLogger(); DirectoryInfo projDir = new DirectoryInfo(Path.GetDirectoryName(context.Project.FilePath) ?? throw new InvalidOperationException("Context's project's file path is null")); string solutionFullName = null; while (projDir.Parent != null) { string filePath = Path.Combine(projDir.FullName, "BitConfigV1.json"); if (File.Exists(filePath)) { solutionFullName = Directory.EnumerateFiles(projDir.FullName, "*.sln").FirstOrDefault(); break; } projDir = projDir.Parent; } CallGenerateCodes((MSBuildWorkspace)context.Project.Solution.Workspace, context.Project, solutionFullName).GetAwaiter().GetResult(); }
public override void Execute(SourceGeneratorContext context) { #if DEBUG Debugger.Launch(); #endif _logger = context.GetLogger(); DirectoryInfo projDir = new DirectoryInfo(Path.GetDirectoryName(context.Project.FilePath)); string solutionFullName = null; while (projDir.Parent != null) { string filePath = Path.Combine(projDir.FullName, "BitConfigV1.json"); if (File.Exists(filePath)) { solutionFullName = Directory.EnumerateFiles(projDir.FullName, "*.sln").FirstOrDefault(); break; } projDir = projDir.Parent; } CallGenerateCodes(context.Project.Solution.Workspace, solutionFullName); }
public override void Execute(SourceGeneratorContext context) { var project = context.GetProjectInstance(); context.GetLogger().Debug($"{nameof(MyCustomSourceGenerator)}: This is a DEBUG logging"); context.GetLogger().Info($"{nameof(MyCustomSourceGenerator)}: This is an INFO logging"); #if DEBUG // Only in DEBUG to prevent breaking the CI build. context.GetLogger().Warn($"{nameof(MyCustomSourceGenerator)}: This is a WARN logging"); context.GetLogger().Error($"{nameof(MyCustomSourceGenerator)}: This is an ERROR logging"); #endif // This test ensures that dependent libraries are included in the compilation // generated from the AdHoc workspace. var dependentString = BuildVariableFromType(context, DependentTypeName, "_dependent"); // This test ensures that linked files included in the project are included // in the Compilation instance used by the generators. var linkedString = BuildVariableFromType(context, LinkedTypeName, "_linked"); // This test validates that some duplicate files do not interfere wi var objectString = BuildVariableFromType(context, SystemObject, "_object"); var stringTypeString = BuildVariableFromType(context, "System.String", "_aString"); context.AddCompilationUnit( "Test", $@" #pragma warning disable 169 namespace Test {{ public static class MyGeneratedType {{ // Project: {project?.FullPath} public const string Project = @""{ project?.FullPath}""; {dependentString} {linkedString} {objectString} {stringTypeString} }} }}" ); }
public override void Execute(SourceGeneratorContext context) { //_ = Debugger.Launch(); // uncomment to debug code generator logger = context.GetLogger(); logger.Info("Executing Hyperlinq generator!"); var compilation = context.Compilation; hyperlinqNamespace = compilation.SourceModule.GlobalNamespace.GetNamespace("NetFabric", "Hyperlinq"); CollectExtensionMethods(context); GenerateSource(context); }
public override void Execute(SourceGeneratorContext context) { var project = context.GetProjectInstance(); context.GetLogger().Debug($"{nameof(MyCustomSourceGenerator)}: This is a DEBUG logging"); context.GetLogger().Info($"{nameof(MyCustomSourceGenerator)}: This is an INFO logging"); #if DEBUG // Only in DEBUG to prevent breaking the CI build. context.GetLogger().Warn($"{nameof(MyCustomSourceGenerator)}: This is a WARN logging"); context.GetLogger().Error($"{nameof(MyCustomSourceGenerator)}: This is an ERROR logging"); #endif context.AddCompilationUnit( "Test", $@" namespace Test {{ public static class MyGeneratedType {{ // Project: {project?.FullPath} public const string Project = @""{ project?.FullPath}""; }} }}" ); }