如何将源生成器作为nuget包添加到C# net5项目中?
若要将项目添加为源生成器,请执行以下代码:
<ItemGroup>
<ProjectReference Include="..\xyz.SourceGenerators\xyz.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
SetTargetFramework="TargetFramework=netstandard2.0" />
</ItemGroup>但是,我正在寻找XML作为源生成器添加一个PackageReference包。
发布于 2021-09-15 13:16:01
我想出了解决办法。谢谢你在评论中的暗示。
<PackageReference Include="xyz.SourceGenerators" Version="1.0.0">足以添加包含源生成器的Nuget包。
但是,您需要正确地将生成器添加到nuget包中。为此,将以下行添加到nuget包的.csproj中。
<ItemGroup>
<None Include="$(OutputPath)\netstandard2.0\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>解决方案来自:How to pack a C# 9 source generator and upload it to the Nuget?
https://stackoverflow.com/questions/69165175
复制相似问题