refactor(build): 优化源代码生成器项目配置

- 移除 GeneratePackageOnBuild 和 IsRoslynComponent 配置项
- 统一设置 IncludeBuildOutput 为 false 以避免运行时库输出
- 更新 Microsoft.CodeAnalysis.Analyzers 版本至 4.14.0
- 为所有项目引用添加 PrivateAssets="all" 属性
- 简化打包配置,只将生成器 DLL 打包到 analyzers 目录
- 添加中文注释说明各配置项的作用和用途
This commit is contained in:
GwWuYou 2025-12-27 21:11:42 +08:00
parent eababa471a
commit fc88d908be
2 changed files with 37 additions and 43 deletions

View File

@ -3,42 +3,38 @@
<PropertyGroup>
<PackageId>GeWuYou.GFramework.Godot.SourceGenerators</PackageId>
<TargetFramework>netstandard2.0</TargetFramework>
<IsRoslynAnalyzer>true</IsRoslynAnalyzer>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<LangVersion>latest</LangVersion>
<IsRoslynComponent>true</IsRoslynComponent>
<!-- 对 generator 项目要启用扩展规则 -->
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<!-- 不把输出当作运行时库 -->
<!-- 这是 Roslyn Analyzer -->
<IsRoslynAnalyzer>true</IsRoslynAnalyzer>
<IncludeBuildOutput>false</IncludeBuildOutput>
<!-- 有助于调试生成的代码(可选) -->
<LangVersion>latest</LangVersion>
<!-- 可选:调试生成代码 -->
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
<!-- Roslyn 依赖(仅 Generator 自用) -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.14.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" PrivateAssets="all"/>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="4.14.0" PrivateAssets="all"/>
</ItemGroup>
<!-- Generator 编译期依赖 -->
<ItemGroup>
<!-- Generator 需要引用 Attributes 项目,但不作为运行时依赖 -->
<ProjectReference Include="..\GFramework.Godot.SourceGenerators.Attributes\GFramework.Godot.SourceGenerators.Attributes.csproj"
PrivateAssets="all"/>
<ProjectReference Include="..\GFramework.SourceGenerators.Common\GFramework.SourceGenerators.Common.csproj"/>
<ProjectReference Include="..\GFramework.SourceGenerators.Common\GFramework.SourceGenerators.Common.csproj"
PrivateAssets="all"/>
</ItemGroup>
<!-- 将 Generator 和 Attributes DLL 打包为 Analyzer -->
<!-- ★唯一需要打包的东西Generator DLL -->
<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.Godot.SourceGenerators.Attributes.dll" Pack="true"
PackagePath="analyzers/dotnet/cs" Visible="false"/>
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="AnalyzerReleases.Shipped.md"/>
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md"/>
<None Include="$(OutputPath)\$(AssemblyName).dll"
Pack="true"
PackagePath="analyzers/dotnet/cs"
Visible="false"/>
</ItemGroup>
</Project>

View File

@ -3,41 +3,39 @@
<PropertyGroup>
<PackageId>GeWuYou.GFramework.SourceGenerators</PackageId>
<TargetFramework>netstandard2.0</TargetFramework>
<IsRoslynAnalyzer>true</IsRoslynAnalyzer>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<LangVersion>latest</LangVersion>
<IsRoslynComponent>true</IsRoslynComponent>
<!-- 对 generator 项目要启用扩展规则 -->
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<!-- 不把输出当作运行时库 -->
<!-- 这是 Analyzer不是运行时库 -->
<IsRoslynAnalyzer>true</IsRoslynAnalyzer>
<IncludeBuildOutput>false</IncludeBuildOutput>
<!-- 有助于调试生成的代码(可选) -->
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<!-- 可选:调试生成代码 -->
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- Roslyn 依赖,只用于 Generator 自身 -->
<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"/>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="4.14.0" PrivateAssets="all"/>
</ItemGroup>
<!-- Generator 编译期引用 Attributes / Common但不打包 -->
<ItemGroup>
<!-- Generator 需要引用 Attributes 项目,但不作为运行时依赖 -->
<ProjectReference Include="..\GFramework.SourceGenerators.Attributes\GFramework.SourceGenerators.Attributes.csproj"
PrivateAssets="all"/>
<ProjectReference Include="..\GFramework.SourceGenerators.Common\GFramework.SourceGenerators.Common.csproj"/>
<ProjectReference Include="..\GFramework.SourceGenerators.Common\GFramework.SourceGenerators.Common.csproj"
PrivateAssets="all"/>
</ItemGroup>
<!-- 将 Generator 和 Attributes DLL 打包为 Analyzer -->
<!-- ★关键:只把 Generator DLL 放进 analyzers -->
<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.SourceGenerators.Attributes.dll" Pack="true"
PackagePath="analyzers/dotnet/cs" Visible="false"/>
<None Include="$(OutputPath)\$(AssemblyName).dll"
Pack="true"
PackagePath="analyzers/dotnet/cs"
Visible="false"/>
</ItemGroup>
</Project>