我创建了一个类库并将其上传到 NuGet.org。类库使用 C# 源代码生成器来生成重复代码(例如使用值元组的方法)。
类库在 NuGet.org 上过着幸福的生活,但是不知何故,源生成器项目也被打包和上传,这不是我想要的......
如何防止源生成器项目上传到 NuGet?
.csproj
类库的:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<!-- Version, Authors, Description and other NuGet package info abbreviated here. -->
</PropertyGroup>
<ItemGroup>
<ProjectReference
Include="..\MyLib.SourceGenerators\MyLib.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
</ItemGroup>
</Project>
.csproj
源生成器的:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>