© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•10mo ago•
16 replies
triple a games in hell

issues with code generator

hi, im trying to make a basic codeanalysis project for a terraria mod im working on
id like to be able to ship the codeanalysis dll independently, rather than directly reference the codeanalysis project in each of my projects but whenever i reference the dll itself, the generators dont execute

i have made a minimum repro project below;

this is the basic generator i made:
[Generator(LanguageNames.CSharp)]
public class TestGenerator : IIncrementalGenerator {
    void IIncrementalGenerator.Initialize(
        IncrementalGeneratorInitializationContext context) {
        context.RegisterSourceOutput(context.AnalyzerConfigOptionsProvider, (x, options) => {
                x.AddSource(
                    "_.g.cs",
                    SourceText.From("/* hello */", Encoding.UTF8)
                );
            }
        );
    }
}
[Generator(LanguageNames.CSharp)]
public class TestGenerator : IIncrementalGenerator {
    void IIncrementalGenerator.Initialize(
        IncrementalGeneratorInitializationContext context) {
        context.RegisterSourceOutput(context.AnalyzerConfigOptionsProvider, (x, options) => {
                x.AddSource(
                    "_.g.cs",
                    SourceText.From("/* hello */", Encoding.UTF8)
                );
            }
        );
    }
}

and this is the csproj of the analyzer project:
<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
        <LangVersion>Latest</LangVersion>
        <Nullable>enable</Nullable>
        <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
        <DevelopmentDependency>true</DevelopmentDependency>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all"/>
        <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all"/>
    </ItemGroup>

    <ItemGroup>
        <None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
    </ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
        <LangVersion>Latest</LangVersion>
        <Nullable>enable</Nullable>
        <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
        <DevelopmentDependency>true</DevelopmentDependency>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all"/>
        <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all"/>
    </ItemGroup>

    <ItemGroup>
        <None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
    </ItemGroup>

</Project>
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

Using Microsoft.XmlSerializer.Generator issues
C#CC# / help
13mo ago
❔ Source code generator with reference to the main project
C#CC# / help
4y ago
Code Generator Broke after VS Update
C#CC# / help
8mo ago
code generator: Exception type "System.InvalidOperationException"
C#CC# / help
2y ago