我能留在代码中的合同我正在与非合约代码开发人员使用的代码库合并? [英] Can I leave contracts in code that I'm merging with a codebase used by non-code contracts developers?

查看:193
本文介绍了我能留在代码中的合同我正在与非合约代码开发人员使用的代码库合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几个月中,我一直在开发为我公司方项目,但现在上级已经决定这将是一个很好的融入现有的产品。

For the last few months I've been developing a side project for my company, but the higher-ups have now decided it would be a good fit in an existing product.

我一直在开发使用微软的代码合同静态类型检查(部分原因是因为我没有使用过他们,是好学)侧的项目。

I've been developing the side project using Microsoft's Code Contracts for static type checking (partly because I hadn't used them before and was eager to learn).

我的问题是,如果我在我的代码检查与地方的合同代码库,将所有其他开发者所需要的代码契约安装能够继续开发工具?我知道,他们没有它安装在一个事实,我在这里的初中,所以我怀疑我能说服他们全部取回来。

My problem is that if I check in my code to the code base with Contracts in place, will every other developer need the Code Contracts tools installed to be able to continue developing? I know for a fact that none of them have it installed, and I'm the junior here so I doubt I could convince them all to take it up.

我使用.NET 4.5,所以代码库合同m的包括在内,但我想知道如果Visual Studio会抱怨说,他们无法与 CONTRACTS_FULL 建设在构建选项中指定每次他们去构建,或者,如果我离开 CONTRACTS_FULL 在构建选项时,当其他开发商试图打造会发生什么?另外我想知道如何当一个合同失败,但代码还没有建立与代码契约重写最终产品将采取行动。

I'm using .Net 4.5, so the Code Contract libraries are included, but I'm wondering if Visual Studio will complain that they're not building with CONTRACTS_FULL specified in the build options every time they go to build, or, if I leave CONTRACTS_FULL in the build options, what will happen when another developer tries to build? Additionally I'm wondering how the end-product will act when a Contract fails, but the code has not been built with the Code Contracts Rewriter.

我创建了一个新的解决方案只有一个项目。创建了一个简单的函数,烧制代码违反合同,以合同的代码和卸载 CONTRACTS_FULL 没有指定。建成并运行它,并收到以下错误:

I created a new solution with just one project. Created a simple function that fired a code contract violation, with code contracts uninstalled and CONTRACTS_FULL not specified. Built and ran it and received the following error:

Run-time exception (line 8): An assembly (probably "hdxticim") must be rewritten using the code contracts binary rewriter (CCRewrite) because it is calling Contract.Requires<TException> and the CONTRACTS_FULL symbol is defined.  Remove any explicit definitions of the CONTRACTS_FULL symbol from your project and rebuild.  CCRewrite can be downloaded from http://go.microsoft.com/fwlink/?LinkID=169180. 
After the rewriter is installed, it can be enabled in Visual Studio from the project's Properties page on the Code Contracts pane.  Ensure that "Perform Runtime Contract Checking" is enabled, which will define CONTRACTS_FULL



我觉得错误信息需求。重写,因为CONTRACTS_FULL不是指定最肯定

I think the error message needs rewriting, as CONTRACTS_FULL is most definitely not specified.

由于马蒂亚斯Fidemraizer,我们已经制定了,这时候使用情况 Contract.Requires< TException方式>(),而不是 Contract.Requires()

Thanks to Matías Fidemraizer, we've worked out that this happens when using Contract.Requires<TException>() and not on Contract.Requires().

在理想情况下,我想修改此行为以使合同触发提供异常,好像它是一个正常的后卫语句而不是抱怨重写。

Ideally, I'd like to modify this behaviour so that the Contract fires the provided exception as if it were a normal guard statement instead of complaining about the rewriter.

这里有一个小提琴演示问题: HTTPS ://dotnetfiddle.net/cxrAPe

推荐答案

简短的回答是:是的。如果您在使用代码契约代码检查,那么这可能构建代码的所有开发人员还必须安装,以构建代码代码契约。

The short answer is: Yes. If you check in the code with Code Contracts, then all developers that might build that code must also have Code Contracts installed in order to build the code.

在矛盾什么@CBauer在他的回答中写道,有一个福地包代码契约。不,这不是一个的NuGet包&MDASH;它是一个基于MSI安装程序安装

In contradiction to what @CBauer wrote in his answer, there is a "blessed" package for Code Contracts. No, it's not a NuGet package—it's an MSI installer based installation.

最后,如果你是在调试一个持续集成环境构建(如开发,QA​​ / QC和/或测试),那么这些构建服务器也需要安装代码契约。

Finally, if you are in a Continuous Integration environment for debug builds (e.g. Development, QA/QC and/or Testing), then those build servers will also need to have Code Contracts installed.

当您使用代码契约,调试版本总是需要使用代码契约的。请注意,这是的不一定的对的发布的建立情况。这取决于合同的检查你使用什么样的形式,并在项目属性指定的选项上。

When you use Code Contracts, Debug builds always require the use of Code Contracts. Please note that this is not necessarily the case for Release builds. It depends on what form of contract checking you're using and the options specified in the Project Properties.

代码契约手动拥有所有的细节。 ,这是相当不错的,我强烈建议抽空阅读和理解它的时候

The Code Contracts manual has all the details. It's quite good and I highly recommend taking the time to read and understand it.

应该注意的是,如果你使用 Contract.Requires< TException>(布尔条件)前提条件的形式,你的必须的对的发布的构建启用代码合同(见第5部分:使用指南,具体而言,第20页 用法2 的情况下)。

It should be noted that if you use the Contract.Requires<TException>(bool condition) form of preconditions, you must have Code Contracts enabled for Release builds (see Section 5: Usage Guidelines, specifically, page 20, Usage 2 scenario).

由于要整合这个代码进入尚未开发出代码契约现有的代码库,你应该考虑修改你的代码契约项目属性设置,以符合的使用场景3 的概述了第20页代码的合同手册,并使用传统如果 - 那么掷模式改写你的合同。这将使你的团队最好的变换方式的代码库使用代码契约无处不在,让您最终取代传统如果 - 那么掷先决条件检查和实际代码契约 Contract.Requires(布尔条件)检查,如果你喜欢, Contract.Requires< TException方式>(布尔条件)检查

Since you are integrating this code into an existing codebase that has not been developed with Code Contracts, you should consider revising your Code Contracts Project Property settings to conform to Usage Scenario 3 outlined on page 20 of the Code Contracts manual, and reformulate your contracts using the "legacy" if-then-throw pattern. This will enable your team to best tranisition the code base to using Code Contracts everywhere, allowing you to eventually replace "legacy" if-then-throw precondition checks with actual Code Contracts Contract.Requires(bool condition) checks, and if you like, Contract.Requires<TException>(bool condition) checks.

更新:很快就会有一个的NuGet包代码契约
我在今天新的GitHub存储库代码契约。对于那些你不知道是谁,微软开源这一点,它现在是一个社区驱动的努力。

UPDATE: There Will Soon Be A NuGet Package For Code Contracts I was at the new GitHub repository for Code Contracts today. For those of you who don't know, Microsoft has open-sourced this and it is now a community-driven effort.

最近,他们(在一月份)公布< STRONG> v1.10.xxxx.RC1 的释放。你可以找到关于它的信息在这里对他们的GitHub库

They recently (back in January) announced v1.10.xxxx.RC1 release. You can find information about it here on their GitHub repository.

这篇关于我能留在代码中的合同我正在与非合约代码开发人员使用的代码库合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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