build(generator): 添加源代码生成器的 MSBuild targets 配置文件

- 为 GFramework.Godot.SourceGenerators 创建 GeWuYou.GFramework.Godot.SourceGenerators.targets 文件
- 为 GFramework.SourceGenerators 创建 GeWuYou.GFramework.SourceGenerators.targets 文件
- 在项目中启用 EnforceExtendedAnalyzerRules 规则
- 修正项目引用路径配置
- 更新包打包配置以包含正确的 targets 文件
- 从 GFramework.csproj 中移除多余的 targets 文件排除配置
This commit is contained in:
GwWuYou 2025-12-27 23:05:44 +08:00
parent f3c5840ebe
commit c5a11820bc
5 changed files with 35 additions and 4 deletions

View File

@ -14,6 +14,7 @@
<!-- 可选:调试生成代码 --> <!-- 可选:调试生成代码 -->
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath> <CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup> </PropertyGroup>
<!-- Roslyn 依赖,只用于 Generator 自身 --> <!-- Roslyn 依赖,只用于 Generator 自身 -->
@ -27,7 +28,7 @@
<!-- Generator 编译期引用 Attributes / Common但不打包 --> <!-- Generator 编译期引用 Attributes / Common但不打包 -->
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\GFramework.Godot.SourceGenerators.Abstractions\GFramework.Godot.SourceGenerators.Abstractions.csproj" PrivateAssets="all"/> <ProjectReference Include="..\GFramework.Godot.SourceGenerators.Abstractions\GFramework.Godot.SourceGenerators.Abstractions.csproj" PrivateAssets="all"/>
</ItemGroup> </ItemGroup>
<!-- ★关键:只把 Generator DLL 放进 analyzers --> <!-- ★关键:只把 Generator DLL 放进 analyzers -->
@ -48,6 +49,6 @@
<None Include="$(OutputPath)\$(AssemblyName).Abstractions.dll" Pack="true" PackagePath="lib\netstandard2.0" Visible="true"/> <None Include="$(OutputPath)\$(AssemblyName).Abstractions.dll" Pack="true" PackagePath="lib\netstandard2.0" Visible="true"/>
<None Include="$(OutputPath)\$(AssemblyName).Abstractions.xml" Pack="true" PackagePath="lib\netstandard2.0" Visible="true"/> <None Include="$(OutputPath)\$(AssemblyName).Abstractions.xml" Pack="true" PackagePath="lib\netstandard2.0" Visible="true"/>
<!-- 包含targets文件 --> <!-- 包含targets文件 -->
<None Include="GFramework.Godot.SourceGenerators.targets" Pack="true" PackagePath="build" Visible="false"/> <None Include="GeWuYou.GFramework.Godot.SourceGenerators.targets" Pack="true" PackagePath="build" Visible="false"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This file is automatically generated by the NuGet package -->
<!-- It ensures that the source generators are properly registered during build -->
<ItemGroup>
<Analyzer Include="$(MSBuildThisFileDirectory)../analyzers/dotnet/cs/GFramework.Godot.SourceGenerators.dll"/>
<Analyzer Include="$(MSBuildThisFileDirectory)../analyzers/dotnet/cs/GFramework.Godot.SourceGenerators.Abstractions.dll"/>
</ItemGroup>
<!-- Ensure the analyzers are loaded -->
<Target Name="EnsureGFrameworkGodotAnalyzers" BeforeTargets="CoreCompile">
<Message Text="Loading GFramework.Godot source generators" Importance="high"/>
</Target>
</Project>

View File

@ -14,6 +14,7 @@
<!-- 可选:调试生成代码 --> <!-- 可选:调试生成代码 -->
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath> <CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup> </PropertyGroup>
<!-- Roslyn 依赖,只用于 Generator 自身 --> <!-- Roslyn 依赖,只用于 Generator 自身 -->
@ -49,6 +50,6 @@
<None Include="$(OutputPath)\$(AssemblyName).Abstractions.dll" Pack="true" PackagePath="lib\netstandard2.0" Visible="true"/> <None Include="$(OutputPath)\$(AssemblyName).Abstractions.dll" Pack="true" PackagePath="lib\netstandard2.0" Visible="true"/>
<None Include="$(OutputPath)\$(AssemblyName).Abstractions.xml" Pack="true" PackagePath="lib\netstandard2.0" Visible="true"/> <None Include="$(OutputPath)\$(AssemblyName).Abstractions.xml" Pack="true" PackagePath="lib\netstandard2.0" Visible="true"/>
<!-- 包含targets文件 --> <!-- 包含targets文件 -->
<None Include="GFramework.SourceGenerators.targets" Pack="true" PackagePath="build" Visible="false"/> <None Include="GeWuYou.GFramework.SourceGenerators.targets" Pack="true" PackagePath="build" Visible="false"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This file is automatically generated by the NuGet package -->
<!-- It ensures that the source generators are properly registered during build -->
<ItemGroup>
<Analyzer Include="$(MSBuildThisFileDirectory)../analyzers/dotnet/cs/GFramework.SourceGenerators.dll"/>
<Analyzer Include="$(MSBuildThisFileDirectory)../analyzers/dotnet/cs/GFramework.SourceGenerators.Abstractions.dll"/>
</ItemGroup>
<!-- Ensure the analyzers are loaded -->
<Target Name="EnsureGFrameworkAnalyzers" BeforeTargets="CoreCompile">
<Message Text="Loading GFramework source generators" Importance="high"/>
</Target>
</Project>

View File

@ -43,7 +43,6 @@
<None Remove="GFramework.SourceGenerators.Tests\**"/> <None Remove="GFramework.SourceGenerators.Tests\**"/>
<None Remove="GFramework.Godot.SourceGenerators.Abstractions\**"/> <None Remove="GFramework.Godot.SourceGenerators.Abstractions\**"/>
<None Remove="GFramework.SourceGenerators.Abstractions\**"/> <None Remove="GFramework.SourceGenerators.Abstractions\**"/>
<None Remove="GFramework.Godot.SourceGenerators.targets"/>
</ItemGroup> </ItemGroup>
<!-- 聚合核心模块 --> <!-- 聚合核心模块 -->
<ItemGroup> <ItemGroup>