© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•12mo ago•
1 reply
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>
<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"/>
<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!");
    }
}
[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
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

source generator
C#CC# / help
3y ago
❔ Source generator & protobuf
C#CC# / help
4y ago
✅ MVVM Source Generator not copying attributes
C#CC# / help
3y ago
✅ Source Generator, dynamic assembly not added.
C#CC# / help
4y ago