XProgramming > XP Magazine > Adventures in C#: Building the App from the Book Files
COLLECTED TOPICS: Adventures in C# | Documentation in XP | Book Reviews
Adventures in C#: Building the App from the Book Files
Ron Jeffries
02/23/2004
An Amazon reviewer had difficulty building the application from the final files provided. My mistake, my expectation was for people to follow along in the building of the code, not for them to build the application from the existing source. I hadn't even intended to provide the source files until Microsoft asked me to. Here's how to build the app from the final file list provided on the book web site.

Building the Project

Here are steps for building a project that will compile and run, from the final zip file in the Microsoft download, 20039999Final Code. This will either come down as a zip file or unzip onto your hard drive as a directory, depending on how the download site provides my files. Either way, you want the 20039999Final Code files. Here are your steps:

  1. Open Visual Studio, create a new C# Project, Console Application. I named mine NotepadFinal.
  2. If VS creates a class for you, e.g. Class1.cs, delete it from the project.
  3. Copy all the files from the 20039999Final Code.zip file (or directory), except for the Notepad.csproj file, into the NotepadFinal directory.
  4. Click Project/Show All Files to show the files moved into the directory.
  5. Right-click on each of the files listed in the "Files in the Project" list below, and select "Include in Project". Note in particular that Notepad.cs is NOT to be included in the project: we removed references to it part way through the book.
    • CustomerTest.cs
      InputCommand.cs
      InputCommandTest.cs
      InsertAction.cs
      ITestTextBox.cs
      IUndoRestore.cs
      LittleTests.cs
      MockTextBox.cs
      SingleCharacterSnapshot.cs
      TestableTextBox.cs (and the corresponding .resx file)
      TestRegex.cs
      TestScroll.cs
      TestTextBox.cs
      TestTextModel.cs
      TextModel.cs
      XMLNotepad.cs (and the corresponding .resx file)
  6. If you compile at this point, you will find that a number of references are missing, because this is a console app. Use the Add References popup menu on the References item in the Solution Explorer, and add System.Drawing, System.Windows.Forms, and NUnit Framework. You should now be able to build the project without errors.
  7. Bring up the NUnit GUI, point to the XMLNotepad executable in your bin/debug folder, and run the tests. The tests should all run, except for one ignored test in TestTextModel, which is intentionally ignored, and for two red tests in CustomerTests, FileInput and TestAllFiles. If these fail, it is because they are pointing to a different directory on your system than they are on mine. Change the file name in the FileInput test (line 45) to be @"..\..\fileInput.test". Change the folder name in the TestAllFiles test to @"..\..\". Now all tests should run green.

What Happened?

I originally planned not to provide all the files for the app, because the idea of the book is to follow along as we program, thinking about what we're doing that makes sense for you, watching our good moves and our bad ones. I was surely wrong about that, and should have planned all along to provide at least the final version in an easy to build form.

The files provided on the Companion site include all files that were ever in the application, with chronological versions for most every day of the project. That's intended to reflect the forward flow of the project, adding things, changing things, as we go along. And it works just fine when one adds and removes files going along, but it doesn't work well when you just try to add them all to an empty project as a blob. Here's what should be in the Visual Studio project for the final build, and what's out:

Files in the Project

Here are the files that are part of the project at the final build:

CustomerTest.cs
InputCommand.cs
InputCommandTest.cs
InsertAction.cs
ITestTextBox.cs
IUndoRestore.cs
LittleTests.cs
MockTextBox.cs
SingleCharacterSnapshot.cs
TestableTextBox.cs (and the corresponding .resx file)
TestRegex.cs
TestScroll.cs
TestTextBox.cs
TestTextModel.cs
TextModel.cs
XMLNotepad.cs (and the corresponding .resx file)

Files NOT in the Project

The following files are in the directory, but not part of the Visual Studio project definition. The .test files are customer tests. They are not part of the Visual Studio project but they are supposed to be in the main directory so that the CustomerTest.cs file can find them.

fileInput.test
insertAfterPara.test
insertOL.test
insertPara.test
insertPre.test
insertUL.test
noextralines.test
paraAfterPara.test
saveload.test
sect1.test
trivial.test
undo.test
undosection.test

There are other files which are left in the directory for historical reasons, but that are not in the current project definition:

Class1.cs (left over from the original project creation?)
fileInput.txt (left over, ignore)
hello.txt (ditto)
Notepad.cs (obsoleted superclass) OptimizedTextModel.cs (obsoleted undo attempt)
TextManipulator.cs (obsoleted experiment)
TestManipulatorTest.cs
UndoAnalyzer.cs (obsoleted undo)
UndoAnalyzerTest.cs
ve-*.tmp (no idea, some VS files?)

Sorry for the Inconvenience

If you were trying to build the app from the source, rather than follow along in the book, I apologize for any inconvenience caused. Microsoft and I will update the Companion site ASAP and if you want a zipped-up directory of the project as it is on my system (Visual Studio 2003), I'll be glad to send it to you.

Thanks for your patience, and I hope you enjoy the book.

XProgramming > XP Magazine > Adventures in C#: Building the App from the Book Files
COLLECTED TOPICS: Adventures in C# | Documentation in XP | Book Reviews