Visual Studios 2008:项目输出 .com 文件
Visual Studios 2008 有没有办法为控制台项目创建 .com 文件而不是 .exe ?现在我必须这样做:
if $(ConfigurationName) == Debug goto :debug
:release
copy ProjectNameConsole.exe ProjectName.com
goto :exit
:debug
:exit
然后对于安装程序,我必须添加复制的 .com 对象,而不是添加项目输出。使用此方法,我无法调试安装程序,除非我创建用于调试的 .com 对象,并更新安装程序以复制该文件而不是发行版本。
如果您想知道,我们有一个同时具有 GUI 和控制台版本的应用程序。可执行文件的 .com 版本充当应用程序的控制台版本。如果exe和com文件同名,用户在调用“ProjectName”时会在控制台窗口中自动使用com文件。
更新:我想我的问题有点误导。我想创建一个 Windows exe,但我希望项目输出能够将对象命名为“ProjectName.com”而不是“ProjectName.exe”。正如 shf301 指出的那样,我基本上正在做 Visual Studios 正在做的事情。
Is there a way for Visual Studios 2008 to create a .com file instead of .exe for a console project? Right now I have to do this:
if $(ConfigurationName) == Debug goto :debug
:release
copy ProjectNameConsole.exe ProjectName.com
goto :exit
:debug
:exit
And then for the installer I have to add the copied .com object instead of adding the project output. Using this method, I can't debug the installer unless I create the .com object for debug, and update the installer to copy that file instead of the release version.
If you are wonder, we have an application that has both a GUI and console version. The .com version of the executable acts as the console version of the application. If the exe and the com file have the same name, the user will automatically use the com file in the console window when they call "ProjectName".
UPDATE: I guess I was a little misleading with my question. I want to create an windows exe, but I was hoping to have the project output to name the object "ProjectName.com" instead of "ProjectName.exe". Just as shf301 pointed out, I am basically doing what Visual Studios is doing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,这有点痛。不可以,您无法使用 Visual Studio 创建 MS-DOS 程序。根本就没有编译器后端。
.com 文件实际上不是 Win32 PE。重命名它对这个事实没有帮助。
如果您需要将应用程序同时作为 (Windows) 控制台应用程序和 GUI 变体,那么只需创建两个不同的可执行文件(在 Windows 中将两者放在一个程序中会有点问题)。
This hurts a little, actually. No, you can't create MS-DOS programs with Visual Studio. There is simply no compiler backend for that.
A .com file is actually not a Win32 PE. Renaming it doesn't help that fact.
If you need to have the application both as (Windows) console application and a GUI variant then just have two different executables created (having both in a single program is a little problematic in Windows).
不,你不能用 Visual Studio 创建 MS-DOS 程序,你只能创建 32 位和 64 位 Windows 应用程序,但我认为你并不真正想要 MS-DOS 程序。您需要的是 Windows 控制台应用程序。控制台应用程序(例如 ipconfig.exe、findstr.exe)不是 MS-DOS 程序,而是使用 32 位控制台且永远不会在 MS-DOS 中运行的 32 位 Windows 应用程序。
您只需将 .exe 文件重命名为 .com,Windows 就会处理这个问题,所以您所要做的就是将控制台应用程序重命名为您想要的文件名。这正是 Visual Studio 本身所做的,请参阅 这个。
编辑:现在我更仔细地阅读了您的问题,您确实已经这样做了,您的问题是关于将调试版本放入安装程序中。为什么不总是在构建后步骤中将 .exe 重命名为 .com 并将其复制到像这样的公共位置:
而不是使用不同的情况进行调试和发布。然后将安装程序指向生成发生的位置。要获得调试版本,请在调试中构建项目,然后重建安装程序。
编辑 2:如果您使用 Visual C++,则有一种更简单的方法。在项目属性中,单击链接器选项并将输出文件从:更改
为
,您将不需要中间步骤
No you can't create an MS-DOS program with Visual Studio, you can only create 32bit and 64 bit Windows applications, but I don't think you really want a MS-DOS program anyway. What you want is a Windows console application. Console applications (e.g. ipconfig.exe, findstr.exe) are not MS-DOS programs, then are 32 bit Windows applications that use the 32 bit console and would never run in MS-DOS.
You can just rename and .exe file to .com and Windows will handle that fine, so all you should have to do is to rename your console application to the file name you want. This is exactly what Visual Studio itself does, see this.
Edit: Now that I read your questions more closely you're really already doing this, you question is about getting the debug version into the installer. Why don't you always rename the .exe to .com in your post build step and copy it to a common location like this:
Instead of having different cases for debug and release. Then point your installer to the location with the build occurs. To get a debug version build your project in debug and then rebuild the installer.
Edit 2: If you are using Visual C++ there is an easier way. In the Project Properties, click the Linker option and change the Output File from:
to
and you won't need that intermediate step