ErrorCodes.Net.Analyzers 0.2.1

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package ErrorCodes.Net.Analyzers --version 0.2.1
                    
NuGet\Install-Package ErrorCodes.Net.Analyzers -Version 0.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ErrorCodes.Net.Analyzers" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ErrorCodes.Net.Analyzers" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="ErrorCodes.Net.Analyzers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ErrorCodes.Net.Analyzers --version 0.2.1
                    
#r "nuget: ErrorCodes.Net.Analyzers, 0.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ErrorCodes.Net.Analyzers@0.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ErrorCodes.Net.Analyzers&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=ErrorCodes.Net.Analyzers&version=0.2.1
                    
Install as a Cake Tool

ErrorCodes.Net

ErrorCodes.Net is a library for generating structured error codes with the format 0x12345678.

How the value is broken down:

0x 12 34 5678
Product ID Project ID Error Type Error Code

Product ID

Denotes which product the error belongs to. For example:

Service A with Product ID of 0 will have the format 0xXXXXXXXX while Service B with a Product ID of 1 will have the format 1xXXXXXXXX

Quick Start

  1. Install ErrorCodes.Net.Analyzers using the NuGet package manager in your IDE or use the following command in the project directory:
    PS C:\YOURSRC> dotnet add package ErrorCodes.Net.Analyzers
    
  2. In the project file, make sure to add the PrivateAssets="all" to the package:
    <PackageReference Include="ErrorCodes.Net.Analyzers" PrivateAssets="all" />
    
  3. Create a file in your project with the name ErrorCodes.yaml or ErrorCodes.yml and fill it with an example:
    ---
    projectId: 6
    namespace: ErrorCodes.Net.Generated
    errorTypes:
      - name: TestErrors
        errorTypeId: 0
        errorCodes:
          - errorCode: 1
            name: RunError
          - errorCode: 2
            name: LogsError
          - errorCode: 3
            name: UninstallError
    
  4. Set the build action for the new file to C# analyzer additional file in Visual Studio or AdditionalFiles in Rider.
  5. Rebuild the project.

If the rebuild was successful, you should be able to reference the error codes in the following way:

string error = ErrorCodeLookup.TestErrors.RunError.FormattedErrorCode;

For the above example file, the results of the FormatedErrorCode are:

Name Formatted output
RunError 0x060001
LogsError 0x060002
UninstallError 0x060003

Example top-level console application:

Program.cs

using SampleConsole;

Console.WriteLine(ErrorCodeLookup.TestErrors.RunError.FormattedErrorCode);
Console.WriteLine(ErrorCodeLookup.TestErrors.LogsError.FormattedErrorCode);
Console.WriteLine(ErrorCodeLookup.TestErrors.UninstallError.FormattedErrorCode);

Output

1x06000001
1x06000002
1x06000003

See the full sample project here

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.2-preview.2 203 4/14/2025
0.2.2-preview.1 196 4/14/2025
0.2.1 227 5/7/2024
0.2.0 190 4/30/2024
0.1.1-preview.8 107 4/30/2024
0.1.1-preview.7 113 4/26/2024
0.1.1-preview.6 111 4/25/2024
0.1.1-preview.5 111 4/23/2024
0.1.1-preview.4 103 4/23/2024
0.1.1-preview.3 116 4/22/2024