我创建了一个类库并将其上传到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>发布于 2021-08-10 12:04:06
将<IsPackable>false</IsPackable>添加到源生成器项目的.csproj似乎可以防止生成NuGet包,类似于单元测试项目。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<IsPackable>false</IsPackable> <!-- HERE -->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0"/>
<!-- ... -->https://stackoverflow.com/questions/68481899
复制相似问题