微软在近期正式发布了Visual Studio 2008,图新鲜 下了个90天试用版(输入正式序列号即可升级为正式版,与Visual Studio 2005的180天试用版类似),结果第一次启动的时候就挂了,看来程序的稳定性还不是特别好。从界面上看,跟Visual studio 2005好像没有多大差别:
我主要用C++开发,所以就找了个vs 2005的C++工程做迁移尝试,这个工程一共包含30个项目,迁移成功没有任何错误,然后rebuild整个解决方案,只有四个工程编译失败。仔细检查一下,发现其中一个编译失败的原因是因为语法错误,在某个函数的参数中使用标准库的wstring类型时没有加命名空间std::,这本是很平常的拼写疏漏导致的错误,但让我感到很惊讶的是这样的错误在visual studio 2003和visual studio 2005下均没有检测到,程序均能正常编译和运行,这也太搞笑了吧?至于另外三个工程编译失败的原因则是一样的,这三个工程都是Windows服务程序,均带有消息文件*.mc,错误是发生在编译mc文件时:
检查发现原来的编译命令是: mc -v -w $(InputName),又检查了下vs2005和vs2008所带的MC的不同,发现问题原来是微软修改MC(Message Compiler)所导致,以下是VS2005所带的MC输出:
Microsoft (R) Message Compiler Version 1.12 . 2505
Copyright (c) Microsoft Corporation. All rights reserved.
usage: MC [ -? aAcdnosuUvw] [ - m maxmsglen] [ - h dirspec] [ - e extension] [ - r dirspec
] [ - x dbgFileSpec] filename.mc
-? - displays this message
- a - input file is ANSI ( default ).
- A - messages in .BIN file should be ANSI.
- b - .BIN filename should have .mc filename_ included for uniqueness.
- c - sets the Customer bit in all the message Ids.
- d - FACILTY and SEVERITY values in header file in decimal .
Sets message values in header to decimal initially.
- e extension - Specify the extension for the header file.
From 1 - 3 chars.
- h pathspec - gives the path of where to create the C include file
Default is .
- m maxmsglen - generate a warning if the size of any message exceeds
maxmsglen characters.
- n - terminates all strings with null ' s in the message tables.
- o - generate OLE2 header file (use HRESULT definition instead of
status code definition)
- r pathspec - gives the path of where to create the RC include file
and the binary message resource files it includes.
Default is .
- s - insert symbolic name as first line of each message.
- u - input file is Unicode.
- U - messages in .BIN file should be Unicode ( default ).
- v - gives verbose output.
- w - warns if message text contains non - OS / 2 compatible inserts.
- x pathspec - gives the path of where to create the .dbg C include
file that maps message Ids to their symbolic name.
filename.mc - gives the names of a message text file
to compile.
Generated files have the Archive bit cleared.
而以下则是VS2008所带的MC的输出:
Microsoft (R) Message Compiler Version 1.12 . 5489
Copyright (c) Microsoft Corporation. All rights reserved.
usage: MC [ -? aAcdnosuUvw] [ - m maxmsglen] [ - h dirspec] [ - e extension] [ - r dirspec
] [ - x dbgFileSpec] [ - z outputFileBasename ] filename
-? - displays this message
- a - input file is ANSI ( default ).
- A - messages in .BIN file should be ANSI.
- b - .BIN filename should have .mc filename_ included for uniqueness.
- c - sets the Customer bit in all the message Ids.
- d - FACILTY and SEVERITY values in header file in decimal .
Sets message values in header to decimal initially.
- e extension - Specify the extension for the header file.
From 1 - 3 chars.
- h pathspec - gives the path of where to create the C include file
Default is .
- m maxmsglen - generate a warning if the size of any message exceeds
maxmsglen characters.
- n - terminates all strings with null ' s in the message tables.
- o - generate OLE2 header file (use HRESULT definition instead of
status code definition)
- r pathspec - gives the path of where to create the RC include file
and the binary message resource files it includes.
Default is .
- s - insert symbolic name as first line of each message.
- u - input file is Unicode.
- U - messages in .BIN file should be Unicode ( default ).
- v - gives verbose output.
- W - specifies path to winmeta.xml file.
- w - specifies path to eventman.xsd file.
- x pathspec - gives the path of where to create the .dbg C include
file that maps message Ids to their symbolic name.
This option can only be used with message text file.
- z outputFileBasename - gives the base name of the generated files.
Default is basename of input file.
filename - gives the name of a message text file or manifest
to compile.
Generated files have the Archive bit cleared.
很显然,VS2008所带的MC进行了少量的修改,主要表现在-w -W -z三个命令项上的不同,这是导致出现上述错误的原因之一;但还有另外一项改动也会导致上述编译命令出错,那就是vs2008的MC要求输入的文件名必须带上.mc后缀,而VS2005则是可以省略该后缀。所以在两种环境下都能正确编译的命令应该是:
MC -v $(InputFileName)
改完之后,果然一切正常,完全编译成功。回头又仔细查找了下Visual studio 2008下对C++的修改说明,发现改动很少(但是没有找到关于上述MC变动的说明,这应该是微软的疏漏吧!)。不过对于C++开发者而言,有个好消息是在C++中也可以像C#中一样查看类图了(如下图所示),不过据微软说是只读的,我还没有验证。
总体来说,Visual Studio 2008用起来还不错,大家不妨一试。对于C++的使用者,可以期待的好消息还有两条:(1)微软已经决定和BCGSoft合作,将BCGSoft的MFC扩展类库整合进MFC,以便开发者能够很容易的使用MFC开发出Office 2007或Visual Studio式样的界面;(2)被称作TR1的针对标准C++库的扩展,主要包括智能指针、正则表达式、新的容器类和随机数生成器等。如果一切顺利的话,开发者可以期待在2008年中期就可以使用这些新增特性了。