SQLCMD is not working in pre-deployment script in sql project
Community wiki answer:

You need to switch to SQLCMD mode in Visual Studio via the menu SQL > Execution Settings.

You can also have all SQL files open in SQLCMD mode by default if you dig into Options > SQL Server Tools > Query Execution.