Microsoft KB Archive/818217

= Conditional compilation symbols that use string literals are not compiled by Vbc.exe =

Article ID: 818217

Article Last Modified on 11/22/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



SYMPTOMS
When your Visual Basic .NET or Visual Basic 2005 project contains conditional compilation symbols that use string literals, the Visual Basic .NET or Visual Basic 2005 Command Line Compiler (vbc.exe) may not compile the source code that is defined between the conditional compilation symbols. The generated executable may not run as expected.



CAUSE
When you use the /define switch for vbc.exe to provide string literals for conditional compilation, vbc.exe expects string values to be entered between &quot;&quot;&quot; and &quot;&quot;&quot; (three pairs of quotation marks). When you enter the string literals between double quotation marks, the conditional comparison fails, and the code is not generated as expected.



WORKAROUND
To work around this problem, type each string literal at the command line in two extra pairs of quotation marks. For example, type the string literal &quot;Hello&quot; as &quot;&quot;&quot;Hello&quot;&quot;&quot;.

Note If you use response files to specify command line parameters, prepend a backward slash mark (\) to the opening quotation mark and to the closing quotation mark for each string literal. For example, type the string literal &quot;Hello&quot; as \&quot;Hello\&quot;.



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
  Open Notepad, and then copy the following code: Public Module Test

Public Sub Main

#If BOOLVALUE Then System.Console.WriteLine (&quot;BOOLVALUE is True&quot;) #End If

#If STRINGVALUE = &quot;Hello&quot; Then System.Console.WriteLine (&quot;STRING is Hello&quot;) #End If

End Sub

End Module  Save the file as Test.vb. Open the Visual Studio .NET or in Visual Studio 2005 command prompt. Change the directory path to the directory that contains Test.vb. Type the following command at the command prompt, and then press the ENTER key:

vbc /target:exe /d:STRINGVALUE=&quot;Hello&quot;,BOOLVALUE=True /verbose Test.vb

Note The /d switch defines symbols. The symbols that you want should be listed, separated by commas. Run Test.exe. Notice the output.

Only BOOLVALUE is True is displayed. STRING is Hello is not displayed.</li></ol>

<div class="references_section">