Search code examples
visual-studiodos

Visual Studios 2008: Project output .com file


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.


Solution

  • 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:

    copy ProjectNameConsole.exe ..\..\ProjectName.com
    

    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:

    $(OutDir)\$(ProjectName).exe
    

    to

    $(OutDir)\ProjectName.com
    

    and you won't need that intermediate step