It has nothing to do with visual studio, it's the standard batch beginner bug.
Percent expansion doesn't work in parenthesis as you expected.
It expands when the complete block is parsed, before any of the lines is executed.
So %location%
is expanded to nothing, the value before it enters the block.
At the cmd line it works the same way, BUT if you start the batch two times, it seems that it works, but you only see the correct value, as it is still set.
How to solve it?
Don't use it (the percent expansion), use delayed expansion instead!
setlocal EnableDelayedExpansion
if %1==Release (
if exist %2 (
set location=%2
echo !location!
....