How to enable Contracts in C#?

313 Views Asked by At

I tried to include contracts into my project, something like:

    public Segment Bounds() {
        Contract.Ensures(segments.Length > 0, "Segments are not empty");
        return new Segment(segments[0].a, segments.Last().b);
    }

I get error (shown as message box) which said me that I should install CCRewrite. I got it here, installed but "Contracts" tab in project settings was not appeared and I continue to get the same error. I'm using Visual Studio 2017 Community. Is it possible to use contracts with this version of Visual Studio?

1

There are 1 best solutions below

0
Hermann.Gruber On

From the CodeContract project wiki:

Visual Studio 2013 is the only version that is supported as a build environment for Code Contracts.

As pointed out in OP's comment, more background information can be found in the following issue:

I have the same issue, I bet on CC for some largish projects. As much as I love it and will miss it, I think everyone should seriously consider getting them out of their code base sooner rather than later. There is just not enough commitment there from either MS or the volunteers here (I don't blame them, it was always made clear that it's a non supported technology). -- chrisaut

My conclusion (in accordance with @HansPassant's comment) is that the project is abandoned.