Implement support for overriding the version number.

Fixes #5410
Test.