Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Reports diagnostics, helping you to annotate your source tree with (Item)NotNull / (Item)CanBeNull attributes.

License

Notifications You must be signed in to change notification settings

bkoelman/ResharperCodeContractNullability

Repository files navigation

Resharper Code Contract Nullability

Build status codecov

This Visual Studio analyzer supports you in consequently annotating your codebase with Resharpers nullability attributes. Doing so improves the nullability analysis engine in Resharper, so NullReferenceExceptions at runtime will become something from the past.

Update: When used on a project that has C# nullable reference types enabled, this analyzer suppresses its original behavior and turns into a utility to convert existing Resharper nullability attributes to C# 8 syntax. See documentation for details.

Get started

  • You need Visual Studio 2015/2017/2019 and Resharper v9 (or higher) to use this analyzer. See here if you use Visual Studio 2013 or lower.

  • From the NuGet package manager console:

    Install-Package ResharperCodeContractNullability

    Install-Package JetBrains.Annotations

  • Rebuild your solution

Alternatively, you can install as a Visual Studio Extension from the Visual Studio Gallery.

Instead of adding the JetBrains package, you can put the annotation definitions directly in your source code. In that case, it's recommended to set the conditional and/or internal options checked.

To make analysis work over multiple projects in your solution, define the JETBRAINS_ANNOTATIONS conditional compilation symbol in your project properties.

Analyzer in action

Trying out the latest build

After each commit, a new prerelease NuGet package is automatically published to AppVeyor at https://ci.appveyor.com/project/bkoelman/resharpercodecontractnullability/branch/master/artifacts. To try it out, follow the next steps:

  • In Visual Studio: Tools, NuGet Package Manager, Package Manager Settings, Package Sources
  • Open the NuGet package manager console (Tools, NuGet Package Manager, Package Manager Console)
    • Select AppVeyor ResharperCodeContractNullability as package source
    • Run command: Install-Package ResharperCodeContractNullability -pre

Running on your build server

This assumes your project uses ResharperCodeContractNullability via NuGet, but Resharper is not installed on your build server. To make the analyzer succeed there, simply add another NuGet reference to your project.

  • From the NuGet package manager console:

    Install-Package JetBrains.ExternalAnnotations