hello world

This commit is contained in:
2025-10-03 02:10:17 +08:00
parent 02909d92c1
commit 0b1e060611
7 changed files with 81 additions and 2 deletions
+9
View File
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
</ItemGroup>
</Project>
+25
View File
@@ -0,0 +1,25 @@
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
namespace MySourceGenerator {
[Generator]
public class MySourceGenerator : ISourceGenerator {
public void Execute(GeneratorExecutionContext context) {
var sb = new StringBuilder();
sb.AppendLine("using System;");
sb.AppendLine("namespace Generated;");
sb.AppendLine("public static class HelloWorld {");
sb.AppendLine(" public static void SayHello() {");
sb.AppendLine(" Console.WriteLine(\"Hello World!!!\");");
sb.AppendLine(" }");
sb.AppendLine("}");
context.AddSource("HelleWorld.generated", SourceText.From(sb.ToString(), Encoding.UTF8));
}
public void Initialize(GeneratorInitializationContext context) {
System.Diagnostics.Debugger.Launch();
}
}
}