Does visual studio 2010 Premium include the contract tools?

不想你离开。 提交于 2019-12-22 04:45:12

问题


According to this feature matrix, Visual Studio 2010 Premium (RC) includes "static code analysis".

However, adding calls to Contract.Requires at the start of my methods doesn't seem to have any effect. I don't get runtime exceptions if the contract is violated. I don't get compiler warnings if a contract cannot be proven. I also can't find a "Code Contracts" tab in the project settings.

Am I missing something obvious or is this feature only available in the Ultimate edition?


回答1:


There does indeed seem to be some confusion about whether or not Code Contracts is included in the framework that comes with beta 2 of VS2010, or even in VS2010 itself. The Code Contracts forum (and expecially this post) has several mentions of this with no answers as of yet.


I don't think that Code Contracts falls under the heading of static code analysis. I think static code analysis refers to other code analysis tools like FxCop.

I have tried using Contract.Requires in VS2010 beta 2 ultimate edition, but I get the same behaviour as you. If you look in the project properties under the Code Analysis tab, you can enable code analysis, but this doesn't relate to Code Contracts.

According to the comment by Melitta (from the Base Class Libraries Team) on the connect article Make data contract static checking available in Professional Edition:

...but the restriction on the static analysis tool stands for this upcoming release. It keeps the code analysis story consistent, in that the static analysis tools require VSTS.

This suggests that you (will) have to have the team system version to get the compile-time version of Code Contracts.




回答2:


To get static analysis in Beta 2 you have to download and install the Code Contracts bits (1.2.21023.14 or higher) from MSDN DevLabs. Then under the project properties, there will now be a Code Contracts tab... from here you can turn on static analysis...

The behaviour you're seeing is because the Code Contracts API is in mscorlib assembly, which allows asserts to work, but nothing else.

I'm assuming this won't be necessary by RTM.




回答3:


You need to turn on the code contracts runtime checking in the project properties. If that settings pane doesn't exist then you need to install the Code Contracts download from Microsoft (despite the fact that the Contract.Requires exists in the framework).

Only the runtime checking is available in the Professional editions.



来源:https://stackoverflow.com/questions/1608406/does-visual-studio-2010-premium-include-the-contract-tools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!