I've started using Code Contracts in all new code I'm writing, such as in a framework library I'm building to help bootstrap IoC, O/RM, etc., in an ASP.NET MVC application. I've written a simple build script for this framework library that looks like the following:
@echo off
echo.
echo Cleaning build output (removing 'obj' and 'bin' folders)...
for /f "tokens=*" %%G in ('dir /b /ad /s bin') do rmdir /s /q "%%G"
for /f "tokens=*" %%G in ('dir /b /ad /s obj') do rmdir /s /q "%%G"
rmdir /s /q build
echo.
echo Starting the build...
call "%VS100COMNTOOLS%\vsvars32.bat"
msbuild Integration.build /target:Build
echo.
echo Done!
pause
This doesn't work. What I end up with in my build
folder if I run this is, for whatever reason, assemblies that aren't fully rewritten by ccrewrite
alongside .pdb.original
, .rewritten
and .csproj.FileListAbsolute.txt
files that litter the output directory.
What does work is first building the solution in Visual Studio 2010, commenting out line 3 through 7 in the batch file and running it again. I then end up with properly rewritten assemblies and no .pdb.original
nor .rewritten
files.
What I've deduced from this is that Visual Studio 2010 somehow triggers the Code Contract rewriter properly so the resulting assemblies from the Visual Studio 2010 build is re-used by the command-line MSBuild call, so what my batch script basically does is just copying files to the build
directory. Rather useless, in other words.
I've read this, but Jon's problem seems different from mine since ccrewrite
is obviously doing something, but it's just not completing the rewriting for whatever reason. The Integration.build
file builds the correct configuration (that has Code Contracts enabled in the .csproj
files) and everything else looks right, it just doesn't work properly.
So, I'm wondering: How do I run MSBuild the way Visual Studio 2010 is where ccrewrite
does what it's supposed to and doesn't litter my output directory with .rewritten
and .pdb.original
files? Does anyone have a perfect example of how an MSBuild file doing proper Code Contracts rewriting looks like?