How should I upgrade an old C# project which uses code contracts?

281 Views Asked by At

I am working on a large C# project which uses code contracts extensively and compiles against an older version of the .NET Framework (3.5). This project is a library, and I am also developing other applications which consume it as a dependency. I would like to use .NET Core 2.1 for these new projects. I believe my options are as follows:

  1. Upgrade the library from .NET Framework 3.5 to .NET Framework 4.6.1+, which I believe will make it compatible with .NET Standard 2.0 and thus usable by a .NET Core 2.1 project.
  2. Upgrade the library to build against .NET Standard 2.0 explicitly, using the new .NET Core toolchain.

I have the following questions:

  1. It looks like code contracts are dead and unsupported in .NET core; this means I will be unable to run the code contract analyzer if I go with Option (2), correct?
  2. If I go with Option (1), the analyzer can still run but I'll have to switch to Igor Beck's unofficial NuGet package per this answer to support .NET 4.6.1+, correct?

Ideally I'd like to keep the benefits of code contracts, although since they're unsupported I recognize this will continue to hold back the library version as time goes on.

0

There are 0 best solutions below