views:

102

answers:

2

I have several class files in App_Code in an ASP.net website running in Microsoft Visual Studio 2005 Professional.

In liu of using a full unit test suite I just want to somehow compile those project-wide classses into an .EXE so that I can nightly run unit tests on them.

I do know how to create a separate C# library project consisting of those files and how to include them into my website--but that is not desirable--I don't want to give up the ability to make on-the-fly code changes of those library classes when running the website in the debugger. As far as I know .Net debugger isn't powerful enough to modify code in included libraries with instant auto re-compilation on page re-load.

So, I want my cake and eat it, too:

  1. Command-line unit testing of website class files in App_Code directory
  2. Being able to modify those class files w/o stopping/re-starting the web debugger.

Is it possible to have both?

+1  A: 

You should put the code in an altogether separate class library/assembly, then reference it from your web project and the command-line utility. As far as I know, it makes no difference where you modify your code, when stopped in the debugger. Never had problems myself.

Hope that helps.

Kieren Johnstone
I just tried it and I get this error message: "This source file has changed. It no longer matches the version of the file used to build the application being debugged." This prohibits the edit and continue paradigm.
Pete Alvin
+1: simple and it works. And moving the code into a separate assembly has the benefit that it encourages devs to write testable classes which don't depend on the current HttpContext.
Juliet
I am very surprised - are you sure you have the project in the same solution? If it's a separate solution/instance of Visual Studio you might get into trouble with it..
Kieren Johnstone
Ah... I had them in different solutions. I created a NEW solution with both the desired class library and website and when I attempt to edit the code in the library I now get a different error: "Changes are not allowed when the debugger has been attached to an already running process or the code being debugged is optimized." I checked MyLibary/Build/Configuration: Active(Debug)/General/[] Optimize Code is NOT checked... still confused!
Pete Alvin
It's more likely being specific about the fact that it was attached to the process after it had been run; are you using Debug->Start with debugging, or attaching to the web server ?
Kieren Johnstone
F5 (Debug > Start Debugging)
Pete Alvin
Just checking something out here..
Kieren Johnstone
I am unable to modify code while the app is running, regardless of whether I'm trying to modify code in a separate assembly or not: using the integrated development server, or IIS, in 32-bit or 64-bit mode. Are you sure you can edit-and-continue if it's all in the web app?
Kieren Johnstone
A: 

Your project is under source control, right? Right? In that case, you can use your source control system to include a link to your asp.net project's app_code folder as part of a separate unit testing project. The exact linking mechanism varies by source control platform, but done right it means there's exactly one instance of your App_Code folder in source control that's visible from two different projects. This way, everything stays up to date.

This has the advantage of allowing you to keep easy, uncompiled code right there just like you always have, but still making the code available for testing.

Joel Coehoorn