开发者

Visual Studio does not flag unterminated string constant in VB.Net

I noti开发者_JAVA技巧ced that if I leave off the terminating double quote for a string constant in Visual Studio 2010, there is no error or even a warning, i.e.

Dim foo as String = "hi

However, the continuous integration tool we are using flags an error:

error BC30648: String constants must end with a double quote.

What's going on here? Is there some language rule in VB.Net that makes a terminating double quote optional "sometimes"? Is there some setting in Visual Studio that will make it flag this as an error, so I can avoid "breaking the build" in this way?


Actually, historically, the BASIC language never REQUIRED a closing quote. This dates back to the 70's. GW-Basic, BasicA, QBASIC, QuickBasic, even older Tandy and TRS-80 computers NEVER required a closing quote. This is nothing new. The reason for this is because BASIC is not a free flow language, like C or C#. This means that whenever a newline is found, BASIC knows that your string must end, quoted or not. Microsoft has purposely not enforced this rule in order to be compatible with older code.


That's not according to spec as section 2.4.4 of the spec states:

A string literal is a sequence of zero or more Unicode characters beginning and ending with an ASCII double-quote character

http://msdn.microsoft.com/en-us/library/aa711651%28v=VS.71%29.aspx

Normally Visual Studio will automatically add the ending double quote if you don't type one in. I wouldn't be surprised if it's related to this (maybe the testing never picked it up because they always got added or similar).


Are you using MSBuild in your integrations tool? If you are, make sure you are pointing to the same MSBuild as Visual Studio is using.

There is a good article I found here: MSDN - MSBuild is now part of Visual Studio

Instead of using MSBuild from something like C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe use the following:

On 32-bit machines they can be found in: C:\Program Files\MSBuild\12.0\bin

On 64-bit machines the 32-bit tools will be under: C:\Program Files (x86)\MSBuild\12.0\bin

and the 64-bit tools under: C:\Program Files (x86)\MSBuild\12.0\bin\amd64

This has worked for us.


I noticed if you have this option on, "Pretty listing (reformatting) of code" Visual Studio will add the the terminating double quote for you, whether you want it or not.

With that option off it allows the, what seems to be, invalid syntax.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜