Dev/Test Environment For Databases With Cross-Database Joins
I would tend to suggest using multiple publish.xml files as described here Jamie Thompson blog

The database names (or a prefix) could then be stored as SQLCMD variables.

Each publish file would then be built and published as a build artifact - you'd need to code a custom powershell or batch job to pick the correct file based on the server name. (You could use the server name as a switch here)

You would need to set up the publish file for each environment once, but once that job is done, it won't need doing again.