NewtonsoftJsonUsageAnalyzer 0.1.0-beta.2
See the version list below for details.
dotnet add package NewtonsoftJsonUsageAnalyzer --version 0.1.0-beta.2
NuGet\Install-Package NewtonsoftJsonUsageAnalyzer -Version 0.1.0-beta.2
<PackageReference Include="NewtonsoftJsonUsageAnalyzer" Version="0.1.0-beta.2"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add NewtonsoftJsonUsageAnalyzer --version 0.1.0-beta.2
#r "nuget: NewtonsoftJsonUsageAnalyzer, 0.1.0-beta.2"
// Install NewtonsoftJsonUsageAnalyzer as a Cake Addin #addin nuget:?package=NewtonsoftJsonUsageAnalyzer&version=0.1.0-beta.2&prerelease // Install NewtonsoftJsonUsageAnalyzer as a Cake Tool #tool nuget:?package=NewtonsoftJsonUsageAnalyzer&version=0.1.0-beta.2&prerelease
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:
- 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>
- 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>
- You can use a nuget package with this analyzer (TODO: upload to nuget)
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
- https://github.com/jonathanpeppers/memory-analyzers - example, how to build Roslyn analyzers.
- JetBrains Rider - really awesome predifined template for Roslyn analyzers, including samples and tests.
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 | 203 | 2/4/2024 |
0.1.0-beta.2 | 63 | 2/4/2024 |