I created a NuGet using Source Generator feature.
Here is my csproj of my generator:
<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <!-- Generates a package at build -->
<IncludeBuildOutput>false</IncludeBuildOutput> <!-- Do not include the generator as a lib dependency -->
</PropertyGroup>
<ItemGroup>
<!-- Package the generator in the analyzer directory of the nuget package -->
<None Include="$(OutputPath)$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
</ItemGroup>
When adding it as a reference to another project, its working well but I would like to generate source code only at build time, not when editing the code.
I still didn’t manage to have this work.
I tried to deactivate “Run on live analysis” but it didn’t work:
Completly remove Analyzer is not an option as I still need to generate those files during compilation.
Do you have any idea how to deactivate only during editing ?