It seems like when you add another database as a reference to a SQL Server Database Project, the way to reference that database in the query code is via the Database Variable Name which is the notation $(ReferencedDatabaseName):
So a query in the primary database would then reference an object from the referenced database in the following way:
SELECT Field1, Field2
FROM [$(ReferencedDatabaseName)].SchemaName.ObjectName
Is there a way to just directly reference the database by it's actual name, e.g.:
SELECT Field1, Field2
FROM ReferencedDatabaseName.SchemaName.ObjectName
If not, does that mean if I import an existing database that references objects in other databases into my solution, I need to replace all the referenced database names with this database variable name notation?
The literal database name could be used. The "Database variable" field has to be omitted when Database Reference is created.
There is a bug which causes Database Variable Name to be empty thereafter.
All you need to do is to reload solution.
Now the database can be referenced by it's actual name.