Hard to tell what you're doing wrong, if anything.
Apart from the possibility of a bug (unlikely, since I've used that variable in the past, and it worked), this variable is only defined during the build (more specifically, only inside target scope, so for example it is not defined during the project's post-build steps). Thus, if you use different place, it will not be replaced.