feat(generator): 配置代码生成器项目以支持NuGet包发布

- 添加 IsRoslynAnalyzer 和 GeneratePackageOnBuild 属性
- 更新项目引用配置以支持分析器使用
- 添加 System.Collections.Immutable 包引用
- 配置生成文件输出路径和可见性
- 添加 README.md 文件并配置打包路径
- 设置包读取文档文件引用
This commit is contained in:
GwWuYou 2025-12-10 09:42:09 +08:00
parent 8058860a80
commit 65a9afe04f
3 changed files with 15 additions and 6 deletions

View File

@ -1,25 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>GeWuYou.GFramework.Generator</PackageId>
<TargetFramework>netstandard2.0</TargetFramework>
<IsRoslynAnalyzer>true</IsRoslynAnalyzer>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<LangVersion>latest</LangVersion>
<IsRoslynComponent>true</IsRoslynComponent>
<!-- 对 generator 项目要启用扩展规则 -->
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<!-- 不把输出当作运行时库 -->
<IncludeBuildOutput>false</IncludeBuildOutput>
<PackageReadmeFile>README.md</PackageReadmeFile>
<!-- 有助于调试生成的代码(可选) -->
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" PrivateAssets="all"/>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all"/>
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
@ -32,8 +33,13 @@
<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true"
PackagePath="analyzers/dotnet/cs" Visible="false"/>
<None Include="$(OutputPath)$(AssemblyName).dll" Pack="true" PackagePath="lib/netstandard2.0" />
<None Include="$(OutputPath)\GFramework.Generator.Attributes.dll" Pack="true"
PackagePath="analyzers/dotnet/cs" Visible="false"/>
<None Update="README.md">
<Pack>true</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,3 @@
项目额外的简单代码生成器
目前已有的功能
- 为枚举添加两个扩展方法方便判断枚举值

View File

@ -44,7 +44,7 @@
<!-- 引用 Source Generator -->
<ItemGroup>
<ProjectReference Include="GFramework.Generator\GFramework.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="GFramework.Generator\GFramework.Generator.csproj" PrivateAssets="all" />
<ProjectReference Include="GFramework.Generator.Attributes\GFramework.Generator.Attributes.csproj"/>
<ProjectReference Include="GFramework.Core\GFramework.Core.csproj"/>
</ItemGroup>