views:

1359

answers:

1

Does VS have an environment variable for the path to the current solution?

For example, there is "%PathToWebRoot%" which is generally set to the "WebSites" directory in your VS project directory. The value of it can be changed in any number of ways. I'm wondering if there's a variable that changes each time you load a solution to point to it's root.

I'm creating unit tests that will potentially be run on different machines and one of the directions you have to set before the method is the AspNetDevelopmentServerHost. It's recommended not to hard code them, of course, but the recommended environment variable isn't necessarily where your site will be and isn't in this case.

+2  A: 

VS has a lot of Macro variables that work from within VS. The one that gives you the full path to the solution is called $(SolutionPath). However, while this works from the Pre- and Post-build events (and, AFAIK, in the solution's MSBuild file), this is not an environment variable. If you think about, you can't have a (global) environment variable that points to "the path to the current solution", since you may have more than one instance of VS open.

Depending on your unit testing framework, you can often ask it about its execution context to get the current directory. That may not give you the solution path, though...

Mark Seemann
True, even if the current instance of VS changed it to match it's settings, that would screw up any other instance. I'll give $(SolutionPath) a try, unit tests run from inside VS so that may be what I need.
Otis
Worked like a charm, thanks. Don't suppose you know if there's one to figure out the current port of the development server?
Otis
The way I usually find out the names of these macros is by opening the project's Properties and going to the Build Events tab. If you do this and click either of the Edit buttons, you will get a dialog with (among other things) a Macros button. Clicking this button will give you a list of all the macro variables available for your project. I don't have a web project handy, so I can't look it up for you, but there certainly isn't any port number in the Class Library I'm currently inspecting...
Mark Seemann
I was just coming back to remove my question, as the test process begins a new server on whatever port I designate on the test method; so, I don't really need to know. Thanks for the reply anyhow!
Otis