Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't "$(SolutionDir)" work in visual studio 2012?

I have a .net 4 MVC Web Api application that I originally built in visual studio 2010. As part of this solution I have a suite of unit test.

I have decorated the unit test methods with the following

 [AspNetDevelopmentServerHost("$(SolutionDir)\\DataCollectionService", "/")]

My understanding is that the "$(SolutionDir)" parameter holds the path to the solution directory, and makes the test suite more generic as it works in multiple environments. This all works great in visual studio 2010.

However when I open the project in visual studio 2012 and try run the test suite i get the following error

"message: the Web site path '$(SolutionDir)\DataCollectionService' does not exist...."

If I change it to the exact path like

    [AspNetDevelopmentServerHost("D:\\CASLog\\Trunk\\DataCollectionService", "/")]

It works fine, although its not longer generic.

I'm not sure if its significant but my visual studio 2010 has resharper, while my visual studio 2012 does not.

Any idea whats going on?

like image 744
David Kethel Avatar asked Oct 01 '12 22:10

David Kethel


1 Answers

Because $(SolutionDir) is in fact a macro. Macros are no longer available in VS2012. One workaround is to use an environment variable (custom or %PathToWebRoot%). Environment variables are supported by AspNetDevelopmentServerHost. You can set the value in a ClassInitializeAttribute method with Environment.SetEnvironmentVariable.

like image 129
Cybermaxs Avatar answered Oct 20 '22 19:10

Cybermaxs