Conditional compilation symbols that use string literals are not compiled by Vbc.exe (818217)



The information in this article applies to:

  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

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 """ and """ (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 "Hello" as """Hello""".

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 "Hello" as \"Hello\".

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open Notepad, and then copy the following code:
    Public Module Test
    
       Public Sub Main()
    
          #If BOOLVALUE Then
             System.Console.WriteLine ("BOOLVALUE is True")
          #End If
    
          #If STRINGVALUE = "Hello" Then
             System.Console.WriteLine ("STRING is Hello")
          #End If
    
       End Sub
    
    End Module
  2. Save the file as Test.vb.
  3. Open the Visual Studio .NET or in Visual Studio 2005 command prompt. Change the directory path to the directory that contains Test.vb.
  4. Type the following command at the command prompt, and then press the ENTER key:

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



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

    Only BOOLVALUE is True is displayed. STRING is Hello is not displayed.

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbString kbCommandLine kbCodeGen kbCompiler kbConsole kbprb KB818217 kbAudDeveloper