.NET 5.0+ (included in SDK)
Installation Guide
Section titled “Installation Guide”This guide covers installing and configuring the Purview Telemetry Source Generator in your project.
Requirements
Section titled “Requirements”Supported Frameworks
Section titled “Supported Frameworks”- .NET 8.0 or higher (Recommended)
- .NET Framework 4.8 or higher
Supported IDEs
Section titled “Supported IDEs”- Visual Studio 2022 (17.0 or higher)
- Visual Studio Code with C# extension
- JetBrains Rider 2022.3 or higher
- Any IDE with Roslyn analyzer support
Installation Methods
Section titled “Installation Methods”Method 1: .NET CLI (Recommended)
Section titled “Method 1: .NET CLI (Recommended)”dotnet add package Purview.Telemetry.SourceGenerator --version 5.0.0-prerelease.1Method 2: Package Manager Console (Visual Studio)
Section titled “Method 2: Package Manager Console (Visual Studio)”Install-Package Purview.Telemetry.SourceGenerator -Version 5.0.0-prerelease.1Method 3: Edit Project File (.csproj)
Section titled “Method 3: Edit Project File (.csproj)”Add directly to your .csproj file:
<ItemGroup> <PackageReference Include="Purview.Telemetry.SourceGenerator" Version="5.0.0-prerelease.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>analyzers</IncludeAssets> </PackageReference></ItemGroup>Method 4: Directory.Build.props (Multi-Project Solutions)
Section titled “Method 4: Directory.Build.props (Multi-Project Solutions)”For solutions with multiple projects that all need telemetry, create or edit Directory.Build.props at the solution root:
<Project> <ItemGroup> <PackageReference Include="Purview.Telemetry.SourceGenerator" Version="5.0.0-prerelease.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>analyzers</IncludeAssets> </PackageReference> </ItemGroup></Project>This automatically adds the package to all projects in the solution.
Verifying Installation
Section titled “Verifying Installation”Step 1: Create a Test Interface
Section titled “Step 1: Create a Test Interface”Create a file ITelemetryTest.cs:
using Purview.Telemetry;
[Logger]public interface ITelemetryTest{ [Info] void TestMessage(string message);}Step 2: Rebuild the Project
Section titled “Step 2: Rebuild the Project”dotnet buildStep 3: Check for Generated Files
Section titled “Step 3: Check for Generated Files”If EmitCompilerGeneratedFiles is enabled (see below), check:
obj/Debug/net8.0/generated/Purview.Telemetry.SourceGenerator/You should see generated files with names like:
{Namespace}.TelemetryTestCore.Logging.g.cs{Namespace}.TelemetryTestCoreDIExtension.DependencyInjection.g.cs
Step 4: Use the Generated Extension Method
Section titled “Step 4: Use the Generated Extension Method”In your Program.cs:
services.AddTelemetryTest(); // This should have IntelliSense supportIf IntelliSense recognizes AddTelemetryTest(), installation was successful! ✅
Configuration Options
Section titled “Configuration Options”Enable Generated File Output (Recommended for Development)
Section titled “Enable Generated File Output (Recommended for Development)”To inspect generated code during development, add to your .csproj:
<PropertyGroup> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)/generated</CompilerGeneratedFilesOutputPath></PropertyGroup>Generated files appear in obj/Debug/net8.0/generated/.
Conditional Compilation
Section titled “Conditional Compilation”To include source generator attributes in your assembly (usually not needed):
<PropertyGroup> <DefineConstants>PURVIEW_TELEMETRY_ATTRIBUTES</DefineConstants></PropertyGroup>By default, attributes are marked [Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] and are removed at runtime.
Disable Logging Generation
Section titled “Disable Logging Generation”If Microsoft.Extensions.Logging is not available in your project:
<PropertyGroup> <DefineConstants>EXCLUDE_PURVIEW_TELEMETRY_LOGGING</DefineConstants></PropertyGroup>This excludes logging-related attributes and code generation.
Additional Dependencies
Section titled “Additional Dependencies”The source generator itself has no runtime dependencies. However, to use the generated code, you need:
For Activities
Section titled “For Activities”# .NET 5.0+ (included in SDK)# No additional packages neededFor Logging (Generation v2 - Recommended)
Section titled “For Logging (Generation v2 - Recommended)”dotnet add package Microsoft.Extensions.Loggingdotnet add package Microsoft.Extensions.Telemetry.AbstractionsFor Logging (Generation v1 - Legacy)
Section titled “For Logging (Generation v1 - Legacy)”dotnet add package Microsoft.Extensions.LoggingFor Metrics
Section titled “For Metrics”# .NET 8.0+ (included in SDK)# No additional packages needed for IMeterFactoryFor OpenTelemetry (Recommended)
Section titled “For OpenTelemetry (Recommended)”To export telemetry to observability platforms:
# Core packagesdotnet add package OpenTelemetry.Extensions.Hostingdotnet add package OpenTelemetry.Exporter.Console
# Optional: Specific exportersdotnet add package OpenTelemetry.Exporter.Jaegerdotnet add package OpenTelemetry.Exporter.Prometheus.AspNetCoredotnet add package Azure.Monitor.OpenTelemetry.ExporterProject Types
Section titled “Project Types”ASP.NET Core Applications
Section titled “ASP.NET Core Applications”<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> </PropertyGroup>
<ItemGroup> <PackageReference Include="Purview.Telemetry.SourceGenerator" Version="5.0.0-prerelease.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>analyzers</IncludeAssets> </PackageReference> </ItemGroup></Project>Console Applications
Section titled “Console Applications”<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> </PropertyGroup>
<ItemGroup> <PackageReference Include="Purview.Telemetry.SourceGenerator" Version="5.0.0-prerelease.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>analyzers</IncludeAssets> </PackageReference> </ItemGroup></Project>Class Libraries
Section titled “Class Libraries”<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> </PropertyGroup>
<ItemGroup> <PackageReference Include="Purview.Telemetry.SourceGenerator" Version="5.0.0-prerelease.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>analyzers</IncludeAssets> </PackageReference> </ItemGroup></Project>.NET Aspire Projects
Section titled “.NET Aspire Projects”<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> </PropertyGroup>
<ItemGroup> <PackageReference Include="Aspire.Hosting" Version="8.0.0" /> <PackageReference Include="Purview.Telemetry.SourceGenerator" Version="5.0.0-prerelease.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>analyzers</IncludeAssets> </PackageReference> </ItemGroup></Project>See the Sample Application for a complete .NET Aspire example.
Multi-Targeting
Section titled “Multi-Targeting”If your project targets multiple frameworks:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>net8.0;net48</TargetFrameworks> </PropertyGroup>
<ItemGroup> <PackageReference Include="Purview.Telemetry.SourceGenerator" Version="5.0.0-prerelease.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>analyzers</IncludeAssets> </PackageReference> </ItemGroup>
<!-- Conditional dependencies for older frameworks --> <ItemGroup Condition="'$(TargetFramework)' == 'net48'"> <PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" /> </ItemGroup></Project>IDE Setup
Section titled “IDE Setup”Visual Studio 2022
Section titled “Visual Studio 2022”- Install latest Visual Studio 2022 (17.8 or higher recommended)
- Ensure “Source Generators” support is enabled (on by default)
- After adding the package, rebuild to trigger generation
- Generated files appear in Solution Explorer under Dependencies > Analyzers > Purview.Telemetry.SourceGenerator
Visual Studio Code
Section titled “Visual Studio Code”- Install the C# extension (ms-dotnettools.csharp)
- Ensure the latest .NET SDK is installed
- Open the project folder
- Run
dotnet buildfrom the terminal - IntelliSense should recognize generated types after build
JetBrains Rider
Section titled “JetBrains Rider”- Install Rider 2022.3 or higher
- Rider automatically detects source generators
- After adding the package, rebuild the solution
- Generated types appear in IntelliSense immediately
Troubleshooting Installation
Section titled “Troubleshooting Installation”Issue: “Type or namespace ‘Purview’ could not be found”
Section titled “Issue: “Type or namespace ‘Purview’ could not be found””Cause: Package not installed or build not run.
Solution:
dotnet restoredotnet buildIssue: “No extension method ‘Add{InterfaceName}’ found”
Section titled “Issue: “No extension method ‘Add{InterfaceName}’ found””Cause: Source generator didn’t run or interface not properly annotated.
Solution:
- Ensure the interface has
[ActivitySource],[Logger], or[Meter]attribute - Rebuild:
dotnet build --no-incremental - Check for build errors in the output
Issue: “Generated files not visible in IDE”
Section titled “Issue: “Generated files not visible in IDE””Cause: EmitCompilerGeneratedFiles not enabled.
Solution: Add to .csproj:
<PropertyGroup> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles></PropertyGroup>Issue: “Source generator errors during build”
Section titled “Issue: “Source generator errors during build””Cause: Incompatible package version or corrupted NuGet cache.
Solution:
# Clear NuGet cachedotnet nuget locals all --clear
# Restore packagesdotnet restore
# Clean and rebuilddotnet cleandotnet buildIssue: “Attributes not recognized (red squiggles)”
Section titled “Issue: “Attributes not recognized (red squiggles)””Cause: IDE hasn’t detected the generator yet.
Solution:
- Rebuild the project:
dotnet build - Restart the IDE
- Check the package is correctly referenced in
.csproj
Issue: “Multiple definitions of type ‘ActivitySourceAttribute’”
Section titled “Issue: “Multiple definitions of type ‘ActivitySourceAttribute’””Cause: Package referenced multiple times or in multiple Directory.Build.props files.
Solution: Remove duplicate references and ensure the package is only included once per project.
Upgrading from v3
Section titled “Upgrading from v3”If you’re upgrading from v3.x to v4.x:
Update Package Version
Section titled “Update Package Version”<!-- Before --><PackageReference Include="Purview.Telemetry.SourceGenerator" Version="5.0.0-prerelease.1" />
<!-- After --><PackageReference Include="Purview.Telemetry.SourceGenerator" Version="5.0.0-prerelease.1" />Update Using Statements
Section titled “Update Using Statements”// Before (v3)using Purview.Telemetry.Activities;using Purview.Telemetry.Logging;using Purview.Telemetry.Metrics;
// After (v4)using Purview.Telemetry; // Single namespace!Handle Breaking Changes
Section titled “Handle Breaking Changes”See the Breaking Changes guide for:
- Namespace consolidation details
- OpenTelemetry naming conventions (default in v4)
- Migration paths and compatibility options
Validating Installation
Section titled “Validating Installation”Run this checklist to confirm everything is working:
- Package installed (
dotnet list packageshows it) - Project builds without errors (
dotnet build) - IntelliSense recognizes
using Purview.Telemetry; - Test interface compiles successfully
- Generated DI extension method appears in IntelliSense
- Application runs and telemetry is emitted
Next Steps
Section titled “Next Steps”- Quick Start - Build your first telemetry interface in 5 minutes
- Getting Started - Comprehensive walkthrough with examples
- Sample Application - Explore the full .NET Aspire sample
- Breaking Changes - Migrating from v3 (if applicable)
Version History
Section titled “Version History”| Version | Release Date | Notes |
|---|---|---|
| 4.0.0-prerelease.2 | 2026-02-14 | Added TelemetryNames generated classes |
| 4.0.0-prerelease.1 | 2026-02-08 | OTel-aligned naming across MELT |
| 4.0.0-prerelease.0 | 2026-02-08 | Namespace consolidation, OTel naming conventions |
| 3.2.4 | 2025-07-27 | Last stable v3 release |
See the CHANGELOG for complete version history.