What I use for a csproj for a Roslyn Code Generator

My csproj file looks like this

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

	<PropertyGroup>
		<TargetFramework>netstandard2.0</TargetFramework>
		<LangVersion>12.0</LangVersion>
		<Nullable>enable</Nullable>
		<ImplicitUsings>enable</ImplicitUsings>
		<IsRoslynComponent>true</IsRoslynComponent>
		<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
		<!--<IncludeBuildOutput>false</IncludeBuildOutput>-->
	</PropertyGroup>
	<PropertyGroup>

		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>

	<ItemGroup>
		<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
			<PrivateAssets>all</PrivateAssets>
			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
		</PackageReference>

		<PackageReference Include="System.CodeDom" PrivateAssets="all" GeneratePathProperty="true" Version="8.0.0" />
		<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
		<None Remove="bin\Debug\netstandard2.0\\*.dll" />
		<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />


	</ItemGroup>


	<PropertyGroup>
		<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
		<WarningsNotAsErrors>CS0436</WarningsNotAsErrors>
	</PropertyGroup>


	<ItemGroup>
		<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
		<None Include="../../README.md" Pack="true" PackagePath="\" />
		<None Include="../../readme.txt">
			<Pack>True</Pack>
			<PackagePath></PackagePath>
		</None>
		<None Include="../../LICENSE" Pack="true" PackagePath="\" />
	</ItemGroup>
	<PropertyGroup>
		<Description>Interface to null object - common</Description>
		<Copyright>MIT</Copyright>
		<NeutralLanguage>en-US</NeutralLanguage>
		<CurrentDate>$([System.DateTime]::Now.ToString(yyyyMMdd))</CurrentDate>
		<Authors>Andrei Ignat</Authors>
		<Title>A C# source-generated class library for generating null objects from interface</Title>
		<PackageTags>dotnet;dotnetcore;csharp;generators;sourcegen;roslyn;</PackageTags>
		<PackageProjectUrl>https://github.com/ignatandrei/rscg_Interface_to_null_object</PackageProjectUrl>
		<PublishRepositoryUrl>true</PublishRepositoryUrl>
		<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
		<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
		<IncludeSymbols>true</IncludeSymbols>
		<IncludeSource>true</IncludeSource>
		<NoWarn>NU5125;NU5039;CS0436</NoWarn>
		<!--<Version>8.$([System.DateTime]::Now.ToString(yyyy.1MMdd.1HHss))</Version>-->
		<!--<Version>$([System.DateTime]::Now.ToString(8.yyyy.1MMdd.1HHmm))</Version>-->
		<Version>2025.119.1910</Version>

		<!--<Optimize Condition="'$(Configuration)'=='Release'">true</Optimize>-->
		<RepositoryUrl>https://github.com/ignatandrei/rscg_Interface_to_null_object</RepositoryUrl>
		<PackageLicenseFile>LICENSE</PackageLicenseFile>
		<RepositoryType>git</RepositoryType>
		<EmbedUntrackedSources>true</EmbedUntrackedSources>
		<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
		<PackageReadmeFile>README.md</PackageReadmeFile>
		<IsPackable>true</IsPackable>
		<!--<PackageIcon>logo.png</PackageIcon>-->
	</PropertyGroup>


	<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
		<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
		<SourceLinkCreate>true</SourceLinkCreate>
		<SourceLinkOriginUrl>https://github.com/ignatandrei/rscg_Interface_to_null_object</SourceLinkOriginUrl>
	</PropertyGroup>
	
	
	
	<ItemGroup>
		<PackageReference Include="RazorBlade" Version="0.6.0" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
		<PackageReference Include="RSCG_NameGenerator" Version="2024.11.11.1830">
			<OutputItemType>Analyzer</OutputItemType>
			<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
		</PackageReference>

	</ItemGroup>

</Project>



And now a detailed explanation

Project Sdk

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

This tag specifies the SDK to use for the project. The Microsoft.NET.Sdk is a general-purpose SDK for .NET projects.

PropertyGroup

<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>12.0</LangVersion>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <IsRoslynComponent>true</IsRoslynComponent>
    <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
  • TargetFramework: Targets .NET Standard 2.0, ensuring compatibility with a wide range of .NET implementations.
  • LangVersion: Specifies the C# language version to use.
  • Nullable: Enables nullable reference types to improve null safety.
  • ImplicitUsings: Automatically includes commonly used namespaces.
  • IsRoslynComponent: Indicates that this project is a Roslyn component, useful for source generators.
  • EnforceExtendedAnalyzerRules: Enforces extended analyzer rules to maintain code quality.

Emit Compiler Generated Files

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
  • EmitCompilerGeneratedFiles: Emits compiler-generated files for debugging and analysis.
  • CompilerGeneratedFilesOutputPath: Specifies the output path for compiler-generated files.

Package References

<ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="System.CodeDom" PrivateAssets="all" GeneratePathProperty="true" Version="8.0.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
    <None Remove="bin\Debug\netstandard2.0\\*.dll" />
    <None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>
  • Microsoft.CodeAnalysis.Analyzers: Adds a reference to the Microsoft.CodeAnalysis.Analyzers package, which provides code analysis tools.
  • System.CodeDom: Adds a reference to the System.CodeDom package, useful for code generation.
  • Microsoft.CodeAnalysis.CSharp: Adds a reference to the Microsoft.CodeAnalysis.CSharp package, necessary for Roslyn-based projects.
  • None Remove: Removes unnecessary DLLs from the build output.
  • None Include: Includes the generated DLL in the NuGet package under the specified path.

Treat Warnings as Errors

<PropertyGroup>
    <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
    <WarningsNotAsErrors>CS0436</WarningsNotAsErrors>
</PropertyGroup>
  • TreatWarningsAsErrors: Treats all warnings as errors to ensure code quality.
  • WarningsNotAsErrors: Excludes specific warnings from being treated as errors.

Source Link and Additional Files

<ItemGroup>
    <PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
    <None Include="../../README.md" Pack="true" PackagePath="\" />
    <None Include="../../readme.txt">
        <Pack>True</Pack>
        <PackagePath></PackagePath>
    </None>
    <None Include="../../LICENSE" Pack="true" PackagePath="\" />
</ItemGroup>
  • Microsoft.SourceLink.GitHub: Adds SourceLink support for GitHub, enabling better debugging experiences.
  • README.md: Includes the README.md file in the NuGet package.
  • readme.txt: Includes the readme.txt file in the NuGet package.
  • LICENSE: Includes the LICENSE file in the NuGet package.

Package Metadata

<PropertyGroup>
    <Description>Interface to null object - common</Description>
    <Copyright>MIT</Copyright>
    <NeutralLanguage>en-US</NeutralLanguage>
    <CurrentDate>$([System.DateTime]::Now.ToString(yyyyMMdd))</CurrentDate>
    <Authors>Andrei Ignat</Authors>
    <Title>A C# source-generated class library for generating null objects from interface</Title>
    <PackageTags>dotnet;dotnetcore;csharp;generators;sourcegen;roslyn;</PackageTags>
    <PackageProjectUrl>https://github.com/ignatandrei/rscg_Interface_to_null_object</PackageProjectUrl>
    <PublishRepositoryUrl>true</PublishRepositoryUrl>
    <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
    <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
    <IncludeSymbols>true</IncludeSymbols>
    <IncludeSource>true</IncludeSource>
    <NoWarn>NU5125;NU5039;CS0436</NoWarn>
    <Version>2025.119.1910</Version>
    <RepositoryUrl>https://github.com/ignatandrei/rscg_Interface_to_null_object</RepositoryUrl>
    <PackageLicenseFile>LICENSE</PackageLicenseFile>
    <RepositoryType>git</RepositoryType>
    <EmbedUntrackedSources>true</EmbedUntrackedSources>
    <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
    <PackageReadmeFile>README.md</PackageReadmeFile>
    <IsPackable>true</IsPackable>
</PropertyGroup>
  • Description: Provides a description for the NuGet package.
  • Copyright: Specifies the copyright information.
  • NeutralLanguage: Sets the neutral language for the assembly.
  • CurrentDate: Sets the current date, useful for versioning.
  • Authors: Specifies the author of the package.
  • Title: Provides a title for the NuGet package.
  • PackageTags: Specifies tags for the NuGet package to improve discoverability.
  • PackageProjectUrl: Provides the URL to the project repository.
  • PublishRepositoryUrl: Publishes the repository URL in the NuGet package metadata.
  • GenerateAssemblyInfo: Generates assembly information attributes.
  • GeneratePackageOnBuild: Disables automatic package generation on build.
  • IncludeSymbols: Includes symbol files in the NuGet package for debugging.
  • IncludeSource: Includes source files in the NuGet package for debugging.
  • NoWarn: Suppresses specific warnings.
  • Version: Sets the version of the NuGet package.
  • RepositoryUrl: Specifies the repository URL.
  • PackageLicenseFile: Specifies the license file for the package.
  • RepositoryType: Specifies the repository type.
  • EmbedUntrackedSources: Embeds untracked source files in the PDB for better debugging.
  • AllowedOutputExtensionsInPackageBuildOutputFolder: Allows PDB files in the package build output folder.
  • PackageReadmeFile: Specifies the README file for the package.
  • IsPackable: Indicates that the project is packable into a NuGet package.

GitHub Actions

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'>
    <ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
    <SourceLinkCreate>true</SourceLinkCreate>
    <SourceLinkOriginUrl>https://github.com/ignatandrei/rscg_Interface_to_null_object</SourceLinkOriginUrl>
</PropertyGroup>
  • ContinuousIntegrationBuild: Enables continuous integration build settings.
  • SourceLinkCreate: Enables SourceLink creation for better debugging.
  • SourceLinkOriginUrl: Specifies the SourceLink origin URL.

Additional Package References

<ItemGroup>
    <PackageReference Include="RazorBlade" Version="0.6.0" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
    <PackageReference Include="RSCG_NameGenerator" Version="2024.11.11.1830">
        <OutputItemType>Analyzer</OutputItemType>
        <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
    </PackageReference>
</ItemGroup>
  • RazorBlade: Adds a reference to the RazorBlade package, useful for code generation.
  • RSCG_NameGenerator: Adds a reference to the RSCG_NameGenerator package, useful for generating names in source code.