0

how do I make Contract work on macOS?

the following code

private static int GetInt(string s)
{
    Contract.Requires<ArgumentNullException>(s != null);
    return 10;
}
static void Main()
{
    Console.WriteLine(GetInt("s"));
}

leads to the exception:

An assembly (probably "TestConsoleApp") must be rewritten using the code contracts binary rewriter (CCRewrite) because it is calling Contract.Requires and the CONTRACTS_FULL symbol is defined. Remove any explicit definitions of the CONTRACTS_FULL symbol from your project and rebuild. CCRewrite can be downloaded from http://go.microsoft.com/fwlink/?LinkID=169180. \r\nAfter the rewriter is installed, it can be enabled in Visual Studio from the project's Properties page on the Code Contracts pane. Ensure that "Perform Runtime Contract Checking" is enabled, which will define CONTRACTS_FULL.

it's 2020 today, I work with dot.net core on my mac, but the link from above is for downloading windows installer that was implemented 5 years ago in 2015 and works with Visual Studio 2010, 2012, 2013, 2015.

And I just wonder if public static class Contract is something that Microsoft uses internally or obsolete or something... I hope someone can shed some light on the matter, can't you? ))

Boris
  • 266
  • 2
  • 5

1 Answers1

1

you were asking "I just wonder if public static class Contract is something that Microsoft uses internally or obsolete or something".

As per my understanding, it's unfortunately obsolete (it used to work with VS 2015 as you pointed out, provided you installed an extension).

See: Does Visual Studio 2017 work with Code Contracts?

You could perhaps try PostSharp's version of Code Contracts?

I hope that MS will continue support of code contracts sometime in the future.