結局のところ、壊れているのは VB.NET のすべてではなく、CodeDomProvider (ASP.NET と Snippet Compiler の両方が使用する) だけです。
単純なソース ファイルが与えられた場合:
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
vbc.exe バージョン 9.0.30729.1 (.NET FX 3.5) でコンパイル:
> vbc.exe default.vb /out:out.exe
> out.exe
Not Debug!
それは理にかなっています...私はDEBUGを定義していないので、「Not Debug!」と表示されます。
> vbc.exe default.vb /out:out.exe /debug:full
> out.exe
Not Debug!
そして、CodeDomProvider を使用して:
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!
わかりました、もう一度-それは理にかなっています。DEBUG を定義していないので、「Not Debug」と表示されます。しかし、デバッグ シンボルを含めるとどうなるでしょうか。
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!
うーん...私はDEBUGを定義しませんでしたが、おそらくそれは私のために定義しましたか? しかし、そうであれば、それを「1」と定義したに違いありません。他の値ではその動作を取得できないためです。CodeDomProvider を使用する ASP.NET は、同じ方法で定義する必要があります。
CodeDomProvider が VB.NET の愚かな疑似論理演算子につまずいているようです。
この話の教訓?#If Not
VB.NET には適していません。
ソースが利用可能になったので、期待どおりに実際に 1 に設定されていることを確認できます。
if (options.IncludeDebugInformation) {
sb.Append("/D:DEBUG=1 ");
sb.Append("/debug+ ");
}