Can I code and compile all type of Visual Studio Application from Command line?

独自空忆成欢 提交于 2020-01-21 05:29:05

问题


I am in the very first step of using Emacs as my programming environment. I run it in DOS Prompt using emacs -nw and do the development there. It's quite unbelievable, that I can do coding of J2EE and J2ME just using Emacs and its Eshell/Shell.

And now about using it for Visual Studio development. Currently, I am working in a simple OpenGL application using Visual C++.NET 2008. I haven't try to build that application from command line, is it possible?

If in J2EE and J2ME, we had the build.xml (that is an ant build file), but what is the analogue of that in Visual Studio.NET solution?

I already compiled a simple Visual Studio Console program using Command Line. It works, but what about a complete set of project???

Thanks!


回答1:


Lots of comments:

  1. There's no need for you to use -nw; Emacs works fine with windows.

  2. The analogue to build.xml is xxxxxx.sln, combined with the dependent project files, which are zzzzzzz.csproj. OF course replace xxxx and zzzzz with your solution and project names.

  3. you don't need the eshell or shell to compile. You can run the compile from within emacs using M-x compile which is often bound to a key combo for easy access. Mine is C-xC-e but I don't know if that is a broad convention or just my choice.

  4. The next-error function works fine to move point to the next error that is reported in the compiler output. You may need a regex for error strings. I use this:

    (add-to-list 'compilation-error-regexp-alist-alist '(msvc "^[ \t]\([A-Za-z0-9\.][^(]\.\(cpp\|c\|h\)\)(\([0-9]+\)) *: +\(error\|fatal error\|warning\) C[0-9]+:" 1 3)))

When there is already an msvc entry, you may need to

(let ((msvcentry (assoc 'msvc compilation-error-regexp-alist-alist )))
  (when msvcentry 
    (setcdr msvcentry '(msvc ....)))))
  1. CEDET. I don't have any experience using CEDET with C++ on Windows, but many people use CEDET with C++ in other environments, for code completion, code analysis, that sort of thing.



回答2:


you have several command line tools at your service:

  • msbuild which builds your project from .sln files (which are like ant's build.xml files)
  • nmake which is an older build-system based upon Makefile files
  • pure cl.exe and link.exe

all you have to do is launch the visual-studio-commandline prompt OR incoporate the environment of that prompt into your own shell/powershell/emacs-environment. have a look at the vcvars32.bat file and what it does, it is located somewhere in the installation folder of visual2008.

you could also use other build systems (scons, cmake etc) which either are standalone (scons) or create native buildscripts for your compiler (cmake, would creates .slnin your case).

to compile (and link) a simple binary which uses opengl you can do this:

 % cl /nologo opengl.cpp /link OpenGL32.lib GLu32.lib and GLaux.lib

take a look at a nehe-tutorial.




回答3:


In another answer to this question, @akira said:

All you have to do is launch the visual-studio-commandline prompt OR incorporate the environment of that prompt into your own shell/powershell/emacs-environment. Have a look at the vcvars32.bat file and what it does; it is located somewhere in the installation folder of visual2008.

Taking that suggestion, I have created an Emacs lisp file to set up my environment in Emacs for Visual Studio 2010. To create this file, I first captured the environment settings from an ordinary command prompt and then did the same from the Visual Studio Command Prompt:

set > set_ordinary.txt
set > set_vs2010.txt

Then, I found the differences between the two using a file differencing tool for Windows. The following emacs lisp code is the result of my effort. Just copy its content into your .emacs file, or better, save its content to vcvars32-2010.el and place it in your load-path.

;;; vcvars32-2010.el --- Create Visual Studio Command Prompt (2010) environment settings

;; Environment settings for:
;;   Visual Studio 2010 Professional
;;   Version 10.0.40219.1 SP1Rel
;;
;;   Microsoft .NET Framework
;;   Version 4.5.50938 SP1Rel

;; Reference:
;;   C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat
;;    -and-
;;   C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\bin\\vcvars32.bat

;;; Usage:

;; Place this file somewhere in your `load-path' and add the following line
;; to your `.emacs' file:
;;
;;    (load "vcvars32-2010.el")

;;; Code:

(setenv "CommonProgramFiles" "C:\\Program Files\\Common Files")
(setenv "DevEnvDir" "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\")

(setenv "Framework35Version" "v3.5")
(setenv "FrameworkDir" "C:\\Windows\\Microsoft.NET\\Framework\\")
(setenv "FrameworkDIR32" "C:\\Windows\\Microsoft.NET\\Framework\\")
(setenv "FrameworkVersion" "v4.0.30319")
(setenv "FrameworkVersion32" "v4.0.30319")

(setenv "INCLUDE"
        (concat
         "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\INCLUDE;"
         "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\ATLMFC\\INCLUDE;"
         "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\include;"))

(setenv "LIB"
        (concat
         "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\LIB;"
         "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\ATLMFC\\LIB;"
         "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\lib;"))

(setenv "LIBPATH"
        (concat
         "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319;"
         "C:\\Windows\\Microsoft.NET\\Framework\\v3.5;"
         "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\LIB;"
         "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\ATLMFC\\LIB;"))

(setenv "Path"
        (concat
         "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VSTSDB\\Deploy;"
         "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\;"
         "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\BIN;"
         "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\Tools;"
         "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319;"
         "C:\\Windows\\Microsoft.NET\\Framework\\v3.5;"
         "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\VCPackages;"
         "C:\\Program Files (x86)\\HTML Help Workshop;"
         "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\bin\\NETFX 4.0 Tools;"
         "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\bin;"
         (getenv "Path")))

(setenv "PROCESSOR_ARCHITECTURE" "AMD64")
(setenv "ProgramFiles" "C:\\Program Files")

(setenv "VCINSTALLDIR"
        "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\")

(setenv "VSINSTALLDIR"
        "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\")

(setenv "WindowsSdkDir"
        "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\")

;;; vcvars32-2010.el ends here


来源:https://stackoverflow.com/questions/5016440/can-i-code-and-compile-all-type-of-visual-studio-application-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!