VSTS Tip: ASP.NET Unit Tests and PathToWebRoot

It used to be extremely painful to get ASP.NET unit tests working together from the same code base on team build and in multiuser environments because of a hardcoded path in the unit test that would break on different machines with different local paths. There is now a %PathToWebRoot% variable to give a more flexibility. Unfortunately you will still get a hardcoded path when your code is being stored in a non-default location. This is all too common when you are working with source code in a separate enlistment. So in that case you go to Tools->Options and in test settings there is a field allowing you to indicate the location of your local web root path. Once you’ve done that you can replace the segment of the hardcoded path with “%PathToWebRoot%” and it will run locally as well as under team build and on other machines providing those users also set their local web root path in the same manner using the Tools->Options setting.

There is some MSDN documentation on this as well. Search for PathToWebRoot and you should find the corresponding help topic.

Comments (0)

Skip to main content