NewtonsoftJsonUsageAnalyzer 0.2.0

dotnet add package NewtonsoftJsonUsageAnalyzer --version 0.2.0
NuGet\Install-Package NewtonsoftJsonUsageAnalyzer -Version 0.2.0
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="NewtonsoftJsonUsageAnalyzer" Version="0.2.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NewtonsoftJsonUsageAnalyzer --version 0.2.0
#r "nuget: NewtonsoftJsonUsageAnalyzer, 0.2.0"
#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.
// Install NewtonsoftJsonUsageAnalyzer as a Cake Addin
#addin nuget:?package=NewtonsoftJsonUsageAnalyzer&version=0.2.0

// Install NewtonsoftJsonUsageAnalyzer as a Cake Tool
#tool nuget:?package=NewtonsoftJsonUsageAnalyzer&version=0.2.0

Newtonsoft.Json Usage Analyzer

A roslyn analyzer, which allows to detect and fail builds, which use Newtonsoft.Json library.

Motivation

Newtonsoft.Json is a great library, and there is no any problems to use it. However, in some cases, people might to decide to use System.Text.Json instead of. In these cases, it is needed to have some way to detect usage of Newtonsoft.Json and prevent it, during migration.

How to use

In a nutshell, you have 3 ways, how to use it:

  1. You can attach this analyzer per specific project(s) (e.g., NewtonsoftJsonUsageAnalyzer.Sample.csproj):
    <ItemGroup>
        <ProjectReference Include="..\NewtonsoftJsonUsageAnalyzer\NewtonsoftJsonUsageAnalyzer.csproj"
                          OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
    </ItemGroup>
  1. You can attach this analyzer globally via Directory.Build.props:
<Project>
  <ItemGroup>
    
    <ProjectReference Include="$(MSBuildThisFileDirectory)\NewtonsoftJsonUsageAnalyzer\NewtonsoftJsonUsageAnalyzer.csproj"
                      PrivateAssets="all"
                      ReferenceOutputAssembly="false"
                      OutputItemType="Analyzer" />
  </ItemGroup>
</Project>
  1. You can use a nuget package with this analyzer (TODO: upload to nuget)

Example of NS0001

Example of NS0001

$ dotnet build
1>Examples.cs(4,1): Error NS0001 : Detected Newtonsoft usage: 'Newtonsoft.Json'
1>------- Finished building project: NewtonsoftJsonUsageAnalyzer.Sample. Succeeded: False. Errors: 1. Warnings: 0
Build completed in 00:00:01.838

Credits

  1. https://github.com/jonathanpeppers/memory-analyzers - example, how to build Roslyn analyzers.
  2. JetBrains Rider - really awesome predifined template for Roslyn analyzers, including samples and tests.
There are no supported framework assets in this 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.0 153 2/4/2024
0.1.0-beta.2 45 2/4/2024