Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

.net 4.0 - Why is ccrewrite.exe not doing anything from the command line?

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:

  • It's definitely loading Dummy.exe, because if I specify a non-existent file, it dies
  • Dummy.exe definitely contains references to Contract - if I run it with no arguments, it fails appropriately (but the error message hasn't been filled in as I'd expect if it had been rewritten)
  • Using postconditions and invariants makes no difference

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.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.NetFrameworkv4.0.20506

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...