Sometimes, despite Visual Studio being an excellent IDE, you want to go the No VS route and hack your code in notepad. Perhaps you just want to make a quick change and its not worth firing up the full VS experience. Maybe you are only checking the code as a background time-filler in between other tasks you don’t want VS eating up your workstations resources all day. Perhaps most likely you’ll need to edit your code on a PC without VS (e.g. Netbook). A while ago I came across this excellent post by SecretGeek where he’s used a batch script to add compilation to the excellent Notepad++. I recommend taking 5 minutes to follow his instructions and get this working as it makes Notepad++ even more useful. Don’t forget you will need to change the .Net framework path in the batch file if you’re coding apps older than .Net 4.0.
I’ve also copied the batch file and then modified it to work for solution files too, so I can compile the whole solution if required instead of just the project file. I’ve then added a second entry in the Notepad++ file (as per SecretGeek’s instructions) and a second shortcut key for this batch file. The only change required is to amend the “*.*proj” to “*.*sln”. This change assumes that the project and solution files are NOT in the same folder though as this confuses the .Net compiler.
As good as Notepad++ is as a notepad tool, if you need something a little more like a mini IDE then I recommend “Programmers Notepad”. Not only is it an excellent lightweight Notepad like tool but it also supports “projects” and tools. By far the best feature though is that it parses the output from the compiler and highlights the results. Also clicking on the error will take you straight to the offending line of code (see screenshots below).
It is easy to integrate SecretGeek’s above batch files into Programmers Notepad. Go to Tools > Add Tool, and set it up like this:
Now we’re cooking! So what’s left? Well what about being able to run your Unit Tests from this mini IDE? Let’s assume Visual Studio is installed on the machine in question (which negates the point of the exercise perhaps, but not always as sometimes you have it installed but just don’t want to run the full blown VS IDE) so we can run MSTest via a batch file. For this batch file to work though we have to make a few more assumptions:
1 You will always run the tests whilst the unit test project code is the open active document in Programmers Notepad.
2 The test assembly name is the same name as the test project file.
Using these assumptions we can code the RunTests.bat batch file to find the active document’s VS project file (*.*proj) and use its name to find the output assembly name in the bin\debug folder. Once we have the test assembly we can throw it at MSTest for it to run the tests. Assigning this new batch file to a Tool menu item in Programmers Notepad (as we did with the other batch files above) we can run the tests within Programmers Notepad and the test results will be output into the output window.
The code for the RunTests.bat batch files is:
@ECHO OFF Set MSTestPath="C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MStest.exe" :findproj Set current=%cd% If not exist *.*proj goto tryFindProjAgain REM get project file name FOR %%f IN (*.*proj) DO Set dllname=%%f REM Convert proj file name to test assembly name set dllname=%dllname:csproj=dll% Set fullpath=%cd%\bin\Debug\%dllname% %MSTestPath% /testcontainer:%fullpath% /detail:errormessage goto end :tryFindProjAgain ECHO No project file found in: ECHO %cd% cd .. REM detect if we are at the root level if "%current%"=="%cd%" goto end goto findproj :end
Please let me know iff you’re looking for a article
writer for your site. You have some really great articles and I think I would be a good asset.
If you ever want to take some of the load off, I’d absolutely love
to write some content for your blog in exchange for a lik back to
mine. Please blast me an e-mail if interested.