I made a C# 9 source code generator, you can find it here
When I use the whole project inside another solution and reference it as a project it works but when I upload it with current configs into the Nuget (here) it does not work.
How to config a C# 9 source generator correctly to work as a Nuget package? What is wrong with my project?
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.0.2</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>dotnet</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<GenerateRepositoryUrlAttribute>true</GenerateRepositoryUrlAttribute>
<PackBuildOutput>true</PackBuildOutput>
<PackageId>MockableStaticGenerator</PackageId>
<PackOnBuild>true</PackOnBuild>
<PackFolder>analyzers\cs</PackFolder>
<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup>
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json ;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
If you unzip the nuget package, you'll see that the package is stored in the lib directory. It has to be stored in the analyzers directory.
One way to do that is to add the following to your csproj:
If you're multitargeting it should be:
This will include your project as both a library and an analyzer.
To use it just as an analyzer, add the following: