hello world
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
|
||||
# IDE0130: 命名空间与文件夹结构不匹配
|
||||
dotnet_style_namespace_match_folder = false
|
||||
# CS4014: 由于此调用不会等待,因此在调用完成前将继续执行当前方法
|
||||
dotnet_diagnostic.CS4014.severity = none
|
||||
# CA1822: 将成员标记为 static
|
||||
dotnet_diagnostic.CA1822.severity = none
|
||||
|
||||
# formating
|
||||
csharp_new_line_before_open_brace = none
|
||||
csharp_new_line_before_else = none
|
||||
csharp_new_line_before_catch = none
|
||||
csharp_new_line_before_finally = none
|
||||
csharp_new_line_before_members_in_object_initializers = none
|
||||
csharp_new_line_before_members_in_anonymous_types = none
|
||||
csharp_new_line_between_query_expression_clauses = none
|
||||
|
||||
@@ -15,5 +15,6 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<BaseIntermediateOutputPath Condition="'$(MSBuildProjectName)' == 'Source'">..\Build\.intermediate\Source</BaseIntermediateOutputPath>
|
||||
<BaseIntermediateOutputPath Condition="'$(MSBuildProjectName)' == 'Generator'">..\Build\.intermediate\Generator</BaseIntermediateOutputPath>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -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>
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-2
@@ -1,2 +1,8 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
||||
using Generated;
|
||||
namespace Source;
|
||||
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
HelloWorld.SayHello();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Generator\Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
+14
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Source", "Source\Source.csproj", "{F1B0542C-51A8-4953-A350-10B350394FE2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generator", "Generator\Generator.csproj", "{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -27,6 +29,18 @@ Global
|
||||
{F1B0542C-51A8-4953-A350-10B350394FE2}.Release|x64.Build.0 = Release|Any CPU
|
||||
{F1B0542C-51A8-4953-A350-10B350394FE2}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{F1B0542C-51A8-4953-A350-10B350394FE2}.Release|x86.Build.0 = Release|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Release|x64.Build.0 = Release|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{AA6A4A38-6F2C-4EB2-8A6C-122030177E32}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user