为什么 ccrewrite.exe 不从命令行执行任何操作?

发布于 2024-07-29 22:33:34 字数 936 浏览 4 评论 0原文

我的代码契约在 Visual Studio 2010 中运行良好,但我无法让 ccrewrite.exe 从命令行执行任何有用的操作。 这是一个示例应用程序:

using System.Diagnostics.Contracts;

public class Dummy
{
    public static void Main(string[] args)
    {
        Contract.Requires(args.Length > 0);
    }
}

然后我编译代码并在其上运行 ccrewrite.exe:

> csc /debug+ /D:CONTRACTS_FULL Dummy.cs

> ccrewrite /o:RewrittenDummy.exe Dummy.exe
elapsed time: 61ms

之后就没有 RewritingDummy.exe 文件了。

我尝试了很多选择,但没有任何区别。 我注意到的一些事情:

  • 它肯定会加载 Dummy.exe,因为如果我指定一个不存在的文件,它就会死亡
  • Dummy.exe 肯定包含对 Contract 的引用 - 如果我不带参数运行它,它会相应地失败(但是错误消息尚未按照我预期的方式填写(如果已重写)
  • 使用后置条件和不变量没有任何区别

我尝试过将警告和详细程度调高,但这根本没有帮助 我究竟做错了什么?

(也作为问题提出代码契约论坛。我将自己在此处添加任何相关答案。)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

粉红×色少女 2024-08-05 22:33:34

好的,这已回答MSDN 论坛。 这一次,我并不是完全愚蠢——这确实可以通过警告来解决。

阅读论坛帖子以获取完整详细信息,但基本问题是 ccrewrite 找不到合约类:它正在 .NET 3.5 CLR 版本的 mscorlib 中查找.NET 4.0 之一。

这可以通过显式列出相关程序集的路径来修复:

> ccrewrite /o:rewrittendummy.exe dummy.exe 
  /libpaths:%SystemRoot%\Microsoft.Net\Framework\v4.0.20506

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文