可以在Microsoft code合同与ASP.NET网站使用? [英] Can Microsoft Code Contracts be used with an ASP.NET Website?

查看:88
本文介绍了可以在Microsoft code合同与ASP.NET网站使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用微软code合同在ASP.NET MVC应用程序没有任何问题,但我似乎无法得到它的一个基本的ASP.NET网站运行相当。我不能完全肯定它,使其与这种类型的项目(尽管它不应该的问题)的工作,所以我希望把它给大家。

I'm currently using Microsoft Code Contracts in an ASP.NET MVC application without any issues but I can not seem to get it quite running in a basic ASP.NET Web site. I'm not entirely sure it was made to work with this type of project (although it shouldn't matter) so I wanted to bring it up to everyone.

我可以编译合同就好了,但code跳过它们,因为我假设它没有被通过属性页面启用就像你在其他项目类型(即ASP.NET MVC)做的。我去了该项目在我的ASP.NET web站点(其中显示一个对话框,而不是典型的属性页)的属性页,但它不会产生相同的菜单选项,因此,没有一个专门章节至code合同。

I can compile the contracts just fine but the code skips over them since I'm assuming it hasn't been enabled through the Properties Page like you would do in other project types (ie ASP.NET MVC). I've gone to the property page of the project (which displays a dialog instead of the typical properties page) in my ASP.NET web site but it does not yield the same menu options and as such, doesn't have a section devoted to Code Contracts.

另外,我有微软code合同,我用我的业务逻辑从网站中分离一个类库项目中正确启用。该合同编译罚款,但是当合同被违反,它抛出一个相当无信息 错误,没有内部异常类型System.ExecutionEngineException被抛出的异常。我的合同中规定要显示的消息后,违反却是无处异常之内。它只是停止进程的执行(我认为这是微软code合同的默认功能)。

Also, I have Microsoft Code Contracts properly enabled within a class library project that I use to separate my business logic from the web site. The contracts compile fine but when a contract is violated, it throws a rather uninformative "Exception of type 'System.ExecutionEngineException' was thrown" error with no inner exception. My contract specifies a message to display upon violation but it is nowhere within the exception. It simply halts the execution of the process (which I believe is the default functionality for Microsoft Code Contracts).

我找不到任何地方明确规定,某一特定项目类型能或不能(或不应该)与合约所采用,所以我只是想看看是否有人有这个问题。

I can't find anywhere that explicitly states that a particular project type can or can't (or shouldn't) be used with Contracts so I just wanted to see if anyone has had this issue.

感谢您的帮助!

推荐答案

我有同样的问题,这是我如何解决它:

I had the same problem and this is how I solved it:

在引用的类库,右键 - >属性 - > code合同。
确保执行合同检查被选中。我有我设置为完全
合同参考议会:确保它被设置为生成

In the Referenced Class Libraries, right click -> properties -> code contracts. Make sure "perform contract checking" is checked. I had mine set to "Full" Contract Reference Assembly: make sure it is set to "Build"

保存更改。

在那些在其code无合同引用的类库,设置合同参考大会以不建。

In the Referenced Class Libraries that have no contracts in their code, set the Contract Reference Assembly to "Do Not Build".

然后在MVC项目,有code合同履行合同检查检查。我有我设置为完全。

Then in the MVC project, have the Code Contracts "perform contract checking" checked. I had mine set to "Full".

希望有所帮助别人。

这篇关于可以在Microsoft code合同与ASP.NET网站使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆