There seems to be no way to go through the NullOrWhiteSpace string as SqlCmdVariable . Basic syntax for SqlCmdVariable :
<SqlCmdVariable Include="DomainPrefix"> <DefaultValue> </DefaultValue> <Value></Value> </SqlCmdVariable>
Either Value or DefaultValue should have some non-white space value.
So, for your first option, as @Peter suggested in the commentary on the question, you can handle this in your Post Deployment SQL script by testing for a specific value, like <Live> or something else. Do something like the following:
DECLARE @DomainPrefix NVARCHAR(50) = N'$(DomainPrefix)'; IF (@DomainPrefix = N'<Live>') BEGIN SET @DomainPrefix = ''; END;
And then just @DomainPrefix with the strings instead of including $(DomainPrefix) in them.
Of course, if you need a SQLCMD variable that will be available in the main T-SQL context, and not just as a T-SQL variable (for example, if you use it as a bound server or a database prefix along the lines UPDATE $(DomainPrefix)[DatabaseName].[dbo].[TableName]... , where $(DomainPrefix) usually defined as [LinkedServerName]. ), you must leave using Value /**/ (or even /* Live */ ) so that the resulting T- SQL is interpreted as:
UPDATE [LinkedServerName].[DatabaseName].[dbo].[TableName]...
or
UPDATE [DatabaseName].[dbo].[TableName]...
both of them are valid T-SQL and work. Therefore, in this case, you will use the following:
<SqlCmdVariable Include="DomainPrefix"> <Value>/* Live */</Value> </SqlCmdVariable>
source share