You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
I had to setup a build server with VS15 for evaluation.
The only thing needed to get it run was to copy C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.Targets\ImportAfter\CodeContractsAfter.targets
to C:\Program Files (x86)\MSBuild\15.0\Microsoft.Common.Targets\ImportAfter\CodeContractsAfter.targets
Of course you don't get the CC settings page in the project properties, but it's sufficient to try out existing solutions
Reacted by Igor Wolbers, Anthony Truskinger, Lexcess, Jonathan Raymer and Nigel Taylor
Location since recent builds seem to be :\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Microsoft.Common.targets\ImportAfter
(depending on edition)
On 12 Mar 2017, at 9:44 am, mmusaev ***@***.***> wrote:
I meant by support if Code Contract would be integrated into Visual Studios 2017 Settings Tab.
―
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
Yaakov (@yaakov-h) PR #482 makes it work at least at compile time, however if static analysis is active I always see CodeContracts: Task manager is unavailable (unable to run in background). in the output, and the build takes forever since it has to wait for CC. Did you experience the same behavior?
tom-englert (@tom-englert) the task manager appears to be provided by Code Contracts' Microsoft.VisualStudio.CodeTools plugin, which was part of the too-hard basket.
As I understand it, all the Visual Studio extension-y bits would need to be packages as a VSIX, rather than the MSI dumping DLLs all over the place and writing to Visual Studio's registry.
Siyabulela Mooi (@Mzangwe) While System.Diagnostics.Contracts types are in place in the class library itself, the rewriting tools needed to make use of this data aren't integrated with Visual Studio 2017. You can put in all the Contract statements you want in your code, and none of them will have any effect at runtime because the assemblies weren't rewritten to actually check pre- and post-conditions or invariants.
They App breaks in whichever mode. This then come very handy with Automated Tests even for the PROD stuff. I added CodeContracts.MSBuild Nuget Package for my automated build pipelines.
Activity
yaakov-h commentedon Jul 26, 2016
Note to self: Looks like most of the targets work is in WiX: https://github.com/Microsoft/CodeContracts/blob/79a04c96679b6d400c286dd62d6a2ec77462da72/Microsoft.Research/ManagedContract.Setup/ManagedContracts.wxs#L1078-L1087
tom-englert commentedon Nov 12, 2016
I had to setup a build server with VS15 for evaluation.
The only thing needed to get it run was to copy
C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.Targets\ImportAfter\CodeContractsAfter.targetsto
C:\Program Files (x86)\MSBuild\15.0\Microsoft.Common.Targets\ImportAfter\CodeContractsAfter.targetsOf course you don't get the CC settings page in the project properties, but it's sufficient to try out existing solutions
yaakov-h commentedon Nov 12, 2016
That works for me too, though I haven't tried CC with any of the new C#7 features yet.
I think the settings pane should show up if you run the MSI after installing VS15. If not, there's a breaking change somewhere in VS.
patroza commentedon Dec 14, 2016
Location since recent builds seem to be
:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Microsoft.Common.targets\ImportAfter(depending on edition)
[-]VS15 (Preview) support[/-][+]Visual Studio 2017 (RC) support[/+]takinosaji commentedon Mar 7, 2017
Patrick Roza (@patroza) doesnt work in release version. Pathes from post of Yaakov (@yaakov-h) work
[-]Visual Studio 2017 (RC) support[/-][+]Visual Studio 2017 support[/+]mmusaev commentedon Mar 10, 2017
Does this mean that Code Contracts will be supported in Visual Studio 2017 soon?
patroza commentedon Mar 10, 2017
Kostiantyn Chomakov (@takinosaji) I've decided to move on and not have this headache at every new VS version :)
yaakov-h commentedon Mar 11, 2017
mmusaev Depends what you mean by "supported", and if anyone's left alive here to merge #482.
mmusaev commentedon Mar 11, 2017
I meant by support if Code Contract would be integrated into Visual Studios 2017 Settings Tab.
yaakov-h commentedon Mar 11, 2017
mmusaev commentedon Mar 12, 2017
Would it be possible to ask for help from Microsoft/Research lab on this?
tom-englert commentedon Mar 19, 2017
Yaakov (@yaakov-h) PR #482 makes it work at least at compile time, however if static analysis is active I always see
CodeContracts: Task manager is unavailable (unable to run in background).in the output, and the build takes forever since it has to wait for CC. Did you experience the same behavior?yaakov-h commentedon Mar 19, 2017
tom-englert (@tom-englert) the task manager appears to be provided by Code Contracts'
Microsoft.VisualStudio.CodeToolsplugin, which was part of the too-hard basket.As I understand it, all the Visual Studio extension-y bits would need to be packages as a VSIX, rather than the MSI dumping DLLs all over the place and writing to Visual Studio's registry.
tom-englert commentedon Mar 20, 2017
I see, so probably it's easier to turn on CC only temporary, than to try fixing this...
yaakov-h commentedon Mar 20, 2017
Probably. I actually run cccheck completely out-of-band (see #459) so I didn't really notice.
Mzangwe commentedon Apr 24, 2018
This works out of the box in Visual Studio 2017. It is past of the System.Diagnostics.Contracts namespace. See example below:
Contract.Requires<ArgumentNullException>(amount > 0, "Amount to deposit must be positive.");charabaruk commentedon Apr 24, 2018
Siyabulela Mooi (@Mzangwe) While System.Diagnostics.Contracts types are in place in the class library itself, the rewriting tools needed to make use of this data aren't integrated with Visual Studio 2017. You can put in all the
Contractstatements you want in your code, and none of them will have any effect at runtime because the assemblies weren't rewritten to actually check pre- and post-conditions or invariants.Mzangwe commentedon Apr 25, 2018
@coldacid Chris, I used the exact Code Contract in both Debug and Release. They both fail when adding a negative deposit amount.
I added these in the .csproj below
<PropertyGroup> <CodeContractsAssemblyMode>1</CodeContractsAssemblyMode> <CodeContractsEnableRuntimeChecking>True</CodeContractsEnableRuntimeChecking> <CodeContractsRuntimeOnlyPublicSurface>False</CodeContractsRuntimeOnlyPublicSurface> <CodeContractsRuntimeThrowOnFailure>True</CodeContractsRuntimeThrowOnFailure> <CodeContractsRuntimeCallSiteRequires>False</CodeContractsRuntimeCallSiteRequires> <CodeContractsRuntimeSkipQuantifiers>False</CodeContractsRuntimeSkipQuantifiers> <CodeContractsRunCodeAnalysis>False</CodeContractsRunCodeAnalysis> <CodeContractsNonNullObligations>False</CodeContractsNonNullObligations> <CodeContractsBoundsObligations>False</CodeContractsBoundsObligations> <CodeContractsArithmeticObligations>False</CodeContractsArithmeticObligations> <CodeContractsEnumObligations>False</CodeContractsEnumObligations> <CodeContractsRedundantAssumptions>False</CodeContractsRedundantAssumptions> <CodeContractsInferRequires>False</CodeContractsInferRequires> <CodeContractsInferEnsures>False</CodeContractsInferEnsures> <CodeContractsInferObjectInvariants>False</CodeContractsInferObjectInvariants> <CodeContractsSuggestAssumptions>False</CodeContractsSuggestAssumptions> <CodeContractsSuggestRequires>True</CodeContractsSuggestRequires> <CodeContractsSuggestEnsures>False</CodeContractsSuggestEnsures> <CodeContractsSuggestObjectInvariants>False</CodeContractsSuggestObjectInvariants> <CodeContractsDisjunctiveRequires>False</CodeContractsDisjunctiveRequires> <CodeContractsRunInBackground>True</CodeContractsRunInBackground> <CodeContractsShowSquigglies>False</CodeContractsShowSquigglies> <CodeContractsUseBaseLine>False</CodeContractsUseBaseLine> <CodeContractsEmitXMLDocs>True</CodeContractsEmitXMLDocs> <CodeContractsCacheAnalysisResults>True</CodeContractsCacheAnalysisResults> <CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel> <CodeContractsReferenceAssembly>Build</CodeContractsReferenceAssembly> <CodeContractsAnalysisWarningLevel>0</CodeContractsAnalysisWarningLevel> </PropertyGroup>Then for the Release Condition:
<CodeContractsRuntimeCheckingLevel>ReleaseRequires</CodeContractsRuntimeCheckingLevel>They App breaks in whichever mode. This then come very handy with Automated Tests even for the PROD stuff. I added CodeContracts.MSBuild Nuget Package for my automated build pipelines.