Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Build macros for C# projects?

Hi,

I'm using Visual Studio .Net 2003.  Part of our system is a C# class library (set up as a project). I'd like to be able to run/debug NUnit tests against the project. In the project property pages, under "Configuration Properties...Debugging" there's an option to pass command line arguments to the target program (in my case, the NUnit gui executable).

Now, I'd like to be able to put "$(TargetPath) /run" as the command line argument -- this would pass the fully-qualified path to the dll into NUnit, and it could run the tests, and everyone would be happy.

But it seems that macros like $TargetPath are only supported for C++ projects. I can't get it to work for the C# class library. Is this right?

David.

David
Monday, October 11, 2004

I don't know whether you can specify macros on the Debug command line in a C# project, but you *can* specify them as a post-build step.

If that's the case then perhaps a post-build step could be to build a batch file, using something like ...

echo nunit $(TargetPath) /run > run_nunit.bat

... and then you specify run_nunit.bat on your debug line.

Christopher Wells
Monday, October 11, 2004

That is correct, as far as I know. However, you can place the DLL you wish to NUnit test in the command argument, and it will load it correctly.

Start Application: C:\Program Files\NUnit V2.1\bin\nunit-gui.exe

CommandLineArgument: NUnitTests.dll

This will run the NUnit GUI and attach the debugger to the GUI.

Alternatively, you can create an external tool and spell out the target path, but it's not debugging. The external tools have all the macros you are used to.

Bryan Jonker
Monday, October 11, 2004

Change over to a Nant build, baby.

    Flava Flav!

Flava Flav
Monday, October 11, 2004

David,

Do you really need to pass a fully-qualified filename? I've done this the way Bryan suggested and it worked fine.  I've never tried, but is it possible add the "/run" parameter into that scheme?

You may also like to look at the NUnit add-in for the IDE: http://weblogs.asp.net/nunitaddin .

John Rusk
Tuesday, October 12, 2004

You can also define a post-build step to copy the built executable into whichever directory it needs to be in for testing (and you can also change the Build Output Path so that it's built there in the first place).

Christopher Wells
Tuesday, October 12, 2004

Hi,

Thanks for the comments. Yes, I can get it working by just typing in the generated dll name, and NUnit then works fine.

I was just annoyed that the macros that I was used to in C++ projects didn't seem to be available in a C# project.  :-)

David.

David
Tuesday, October 12, 2004

I did a simple custom tool in VS.NET.  The settings are:

Title: NUnit
Command: <installdir>\nunit-console.exe
Arguments: $(ProjectDir)bin\debug\$(TargetName)$(TargetExt)

I do remember there being something funky with getting the path to resolve, but this works for me.  I then mapped a shortcut like Ctrl+Shift+T and it runs NUnit in the console out against the current assembly.

Kris
Tuesday, October 12, 2004

Test

test
Wednesday, November 24, 2004

*  Recent Topics

*  Fog Creek Home