C#C
C#10mo ago
MechWarrior99

Source generator not working?

I am trying to setup a incremental source generator, and following a number of different tutorials/blogs. It was working then I changed something and it no longer works, even after reverting the changes.

This is the source gen .csproj file
<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
        <LangVersion>10.0</LangVersion>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces"
                          Version="4.0.1"
                          PrivateAssets="all" />
    </ItemGroup>
</Project>

And this is how I am referencing it.
<ProjectReference Include="..\SourceGen\SouceGen.csproj" 
                          OutputItemType="Analyzer"
                          ReferenceOutputAssembly="false"/>


And the test generator.
[Generator]
public class TestingGenerator : IIncrementalGenerator
{
    public void Initialize(IncrementalGeneratorInitializationContext context)
    {
        throw new Exception("Test Exception!");
    }
}


I rebuild after every change using dotnet build MyProject.sln --no-incremental.

I except to see a warning in the logs saying that the source gen .csproj will not be included but I don't.

Anything clear that I am doing wrong or how to debug?
Was this page helpful?