2009-10-02 13 views
14

Neden #IF Not DEBUG VB.NET'te beklediğim şekilde çalışıyor? C# yanı beklenen davranışa sahip, tabii ki,VB.NET Önişlemci Yönergeleri

#Const D = True 
#If D Then 
    Console.WriteLine("D") 
#End If 

#If Not D Then 
    Console.WriteLine("Not D") 
#End If 
' Outputs: D 

Ve:

#If DEBUG Then 
    Console.WriteLine("Debug") 
#End If 

#If Not DEBUG Then 
    Console.WriteLine("Not Debug") 
#End If 

#If DEBUG = False Then 
    Console.WriteLine("Not Debug") 
#End If 
' Outputs: Debug, Not Debug 

Ama bir manuel olarak ayarlanan const yapar

#if DEBUG 
    Console.WriteLine("Debug"); 
#endif 

#if !DEBUG 
    Console.WriteLine("Not Debug"); 
#endif 
// Outputs: Debug 
+0

İşleri cezası, birincisi görüntüler sadece hata ayıklama modunda hata ayıklama ve değil ayıklama, Yayın modunda hata ayıklama değil . Proje ayarlarınızda "garip" bir şey olmadığından emin misiniz? –

+0

Hmmm ... Var olan bir ASP.NET projesinde hem VS2008 hem de Snippet Derleyicisi ile denedim. Yeni bir Konsol projesini deneyeceğim ve ne olacağını göreceğim. –

+0

Denediğim yeni bir konsol uygulamasıydı. –

cevap

10

çıkıyor, onda da değil tüm kırık olan VB.NET'in - sadece CodeDomProvider (hem ASP.NET hem de Snippet Derleyicisi'nin kullandığı). vbc.exe sürümü 9.0.30729.1 derleme

Imports System 
Public Module Module1 
    Sub Main() 
     #If DEBUG Then 
      Console.WriteLine("Debug!") 
     #End If 

     #If Not DEBUG Then 
      Console.WriteLine("Not Debug!") 
     #End If 
    End Sub 
End Module 

(NET FX 3.5): Basit bir kaynak dosya Verilen

> vbc.exe default.vb /out:out.exe 
> out.exe 
    Not Debug! 

mantıklı ... ben yapmadım DEBUG tanımlayın, bu yüzden "Hata Ayıklama" ifadesini gösterir. CodeDomProvider kullanarak

> vbc.exe default.vb /out:out.exe /debug:full 
> out.exe 
    Not Debug! 

Ve:

yine
Using p = CodeDomProvider.CreateProvider("VisualBasic") 
    Dim params As New CompilerParameters() With { _ 
     .GenerateExecutable = True, _ 
     .OutputAssembly = "out.exe" _ 
    } 
    p.CompileAssemblyFromFile(params, "Default.vb") 
End Using 

> out.exe 
Not Debug! 

Tamam - mantıklı. DEBUG'ı tanımlamadım, bu yüzden "Hata Ayıklama" ifadesini gösteriyor. Ama ya hata ayıklama sembolleri eklerseniz?

Using p = CodeDomProvider.CreateProvider("VisualBasic") 
    Dim params As New CompilerParameters() With { _ 
     .IncludeDebugInformation = True, _ 
     .GenerateExecutable = True, _ 
     .OutputAssembly = "C:\Users\brackett\Desktop\out.exe" _ 
    } 
    p.CompileAssemblyFromFile(params, "Default.vb") 
End Using 

> out.exe 
Debug! 
Not Debug! 

Hmm ... DEBUG'ı tanımlamadım, ancak belki de benim için tanımladı mı? Ama eğer yapsaydı, bunu "1" olarak tanımlamış olmalıydı çünkü bu davranışı başka bir değerle alamıyorum. ASP.NET, CodeDomProvider, must define it the same way kullanarak.

CodeDomProvider'ın VB.NET'in aptalca psuedo-logical operators üzerinden tetiklenmesi gibi görünüyor.

Hikaye ahlakı? VB.NET için #If Not iyi bir fikir değildir.


Ve şimdi bu kaynak kullanılabilir beklediğim gibi, ben verify that it does actually set it equal to 1 edebilirsiniz: Benim için

if (options.IncludeDebugInformation) { 
     sb.Append("/D:DEBUG=1 "); 
     sb.Append("/debug+ "); 
}