I ran into this problem again. My problem was that the definition of one of my table-valued functions in the server (the target server of the publish) had a SQLCmd parameter commented out:
CREATE FUNCTION MyProblematicFunc
(
@beg_date date,
@end_date date
)
RETURNS TABLE
AS
RETURN
(
SELECT
Name,
Address,
--,cast([$(DBreferenceFromVS)].[dbo].[ConvertNumToDate](NumericDate) as DATE) [Create Date]
-- ^^^^ This comment above was causing the error on publish and on schema comparison. I had to remove it in the server
FROM RandomTable