Fix expression resolving when specified in a profile

by passing profile ID as active profile to resolveExpressions when not null.
Also move reading of properties from active profiles ahead of reading global
properties because the ones in a profile should take preference.
Adding a test to verify the problems.