0

My csproj defines a build configuration 'Debug-plus' with Code Contracts.

<PropertyGroup Condition="'$(Configuration)' == 'Debug-plus'">
    <DefineConstants>TRACE;DEBUG;CONTRACTS_FULL</DefineConstants>
    <CodeContractsEnableRuntimeChecking>True</CodeContractsEnableRuntimeChecking>

What happens if someone tries to build the project in this configuration without Code Contracts installed?

Ideally, I would like them to see an error with a message explaining how to install Code Contracts. The worst could happen would be for the build to succeed but without code contracts being checked at runtime, so for tests to give different results on different computers.

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
  • https://www.nuget.org/packages/CodeContracts.MSBuild/ – Sam Harwell Oct 17 '14 at 10:48
  • Possible duplicate of this question that I answered here on StackOverflow: [Can I leave contracts in code that I'm merging with a codebase used by non-code contracts developers?](http://stackoverflow.com/questions/25627419/can-i-leave-contracts-in-code-that-im-merging-with-a-codebase-used-by-non-code) – fourpastmidnight Mar 01 '16 at 14:12

1 Answers1

2

If you use CodeContracts as a NuGet package, then on machines that don't have CodeContracts package will fail the build. They will see error like this:

Build FAILED.

"c:\src\MyProj.csproj" (default target) (1) ->
(EnsureNuGetPackageBuildImports target) ->
  c:\src\MyProj.csproj(302,5): error : This project references NuGet package(s)
that are missing on this computer. Enable NuGet Package Restore to download 
them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. 
The missing file is ..\packages\CodeContracts.MSBuild.1.7.10908.1101-beta\build\CodeContracts.MSBuild.targets.

    0 Warning(s)
    1 Error(s)

If you like to customize error message, open your .csproj file in text editor and modify target EnsureNuGetPackageBuildImports. It is probably good idea to add specific steps required to install CodeContracts package.

seva titov
  • 11,720
  • 2
  • 35
  • 54