I've got Code Contracts working fine from inside Visual Studio 2010, but I can't get ccrewrite.exe
to do anything useful from the command line. Here's a sample app:
using System.Diagnostics.Contracts; public class Dummy { public static void Main(string[] args) { Contract.Requires(args.Length > 0); } }
I then compile the code and run ccrewrite.exe on it:
> csc /debug+ /D:CONTRACTS_FULL Dummy.cs > ccrewrite /o:RewrittenDummy.exe Dummy.exe elapsed time: 61ms
There's no RewrittenDummy.exe
file afterwards.
I've tried loads of options, but nothing's making any difference. A few things I've noticed:
I've tried turning warnings and verbosity up, and that doesn't help at all What am I doing wrong?
(Also asked as a question in the Code Contracts forum. I'll add any relevant answers here myself.)
Okay, this has been answered in the MSDN forum. For once, it wasn't really me being entirely stupid - it's something that could really do with a warning.
Read the forum post for full details, but the basic problem is that ccrewrite
couldn't find the contract classes: it was looking in the .NET 3.5 CLR version of mscorlib
instead of the .NET 4.0 one.
This can be fixed by explicitly listing the path to the relevant assembly:
> ccrewrite /o:rewrittendummy.exe dummy.exe /libpaths:%SystemRoot%\Microsoft.Net\Framework\v4.0.20506
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With