4

is there any way to create a new visual studio project without using IDE, Instead use command prompt??

I am working on a project which will generate small C++ program, so i want to create a new project, add that C++ file to that project, compile and run it, all using command prompt (batch file) only..

so could anyone please let me know how to do this.. Thanks in advance..

Vinay C
  • 387
  • 1
  • 7
  • 16

2 Answers2

4

Visual Studio projects are just XML files, so you can just study their format and write them out. (The format changed from 2008 to 2010.) Solution files are a custom text format, but not that complicated either.

Finally, devenv.exe has a switch for "don't start the IDE, just compile this solution on the command line", which you can use to compile the resulting solution.

Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157
  • thanks for quick reply..! can you give some links regarding those formats?? – Vinay C Oct 23 '11 at 10:58
  • 1
    Project files are more specific than XML: they're MSBuild build files, the format of which is [documented](http://msdn.microsoft.com/en-gb/library/0k6kkbsd.aspx). However VS supports a subset of MSBuild so one could create a file that VS cannot use but MSBuild can. – Richard Oct 23 '11 at 11:07
2

Let CMake make your project files for you. It uses a much more legible syntax, and you can also generate project files for a variety of other build systems.

As an example, here's a very basic CMake file:

project(Foo)
cmake_minimum_required(VERSION 2.8)

#project source files
file (GLOB HEADER_FILES "*.h" "*.hpp")
file (GLOB SOURCE_FILES "*.cpp")

# build
add_executable(Foo ${SOURCE_FILES})
target_link_libraries(Foo ${LIBS})

And here's the solution file it generates.

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ALL_BUILD", "ALL_BUILD.vcxproj", "{66E5A2EB-A802-44A1-AC9C-906752330405}"
    ProjectSection(ProjectDependencies) = postProject
        {1A246EDB-1F39-4776-A9C0-C81AC67D1924} = {1A246EDB-1F39-4776-A9C0-C81AC67D1924}
        {A0601C1A-BC0F-45D0-BDB1-C5056BD69958} = {A0601C1A-BC0F-45D0-BDB1-C5056BD69958}
    EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Foo", "Foo.vcxproj", "{1A246EDB-1F39-4776-A9C0-C81AC67D1924}"
    ProjectSection(ProjectDependencies) = postProject
        {A0601C1A-BC0F-45D0-BDB1-C5056BD69958} = {A0601C1A-BC0F-45D0-BDB1-C5056BD69958}
    EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZERO_CHECK", "ZERO_CHECK.vcxproj", "{A0601C1A-BC0F-45D0-BDB1-C5056BD69958}"
    ProjectSection(ProjectDependencies) = postProject
    EndProjectSection
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Win32 = Debug|Win32
        Release|Win32 = Release|Win32
        MinSizeRel|Win32 = MinSizeRel|Win32
        RelWithDebInfo|Win32 = RelWithDebInfo|Win32
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {66E5A2EB-A802-44A1-AC9C-906752330405}.Debug|Win32.ActiveCfg = Debug|Win32
        {66E5A2EB-A802-44A1-AC9C-906752330405}.Release|Win32.ActiveCfg = Release|Win32
        {66E5A2EB-A802-44A1-AC9C-906752330405}.MinSizeRel|Win32.ActiveCfg = MinSizeRel|Win32
        {66E5A2EB-A802-44A1-AC9C-906752330405}.RelWithDebInfo|Win32.ActiveCfg = RelWithDebInfo|Win32
        {1A246EDB-1F39-4776-A9C0-C81AC67D1924}.Debug|Win32.ActiveCfg = Debug|Win32
        {1A246EDB-1F39-4776-A9C0-C81AC67D1924}.Debug|Win32.Build.0 = Debug|Win32
        {1A246EDB-1F39-4776-A9C0-C81AC67D1924}.Release|Win32.ActiveCfg = Release|Win32
        {1A246EDB-1F39-4776-A9C0-C81AC67D1924}.Release|Win32.Build.0 = Release|Win32
        {1A246EDB-1F39-4776-A9C0-C81AC67D1924}.MinSizeRel|Win32.ActiveCfg = MinSizeRel|Win32
        {1A246EDB-1F39-4776-A9C0-C81AC67D1924}.MinSizeRel|Win32.Build.0 = MinSizeRel|Win32
        {1A246EDB-1F39-4776-A9C0-C81AC67D1924}.RelWithDebInfo|Win32.ActiveCfg = RelWithDebInfo|Win32
        {1A246EDB-1F39-4776-A9C0-C81AC67D1924}.RelWithDebInfo|Win32.Build.0 = RelWithDebInfo|Win32
        {A0601C1A-BC0F-45D0-BDB1-C5056BD69958}.Debug|Win32.ActiveCfg = Debug|Win32
        {A0601C1A-BC0F-45D0-BDB1-C5056BD69958}.Debug|Win32.Build.0 = Debug|Win32
        {A0601C1A-BC0F-45D0-BDB1-C5056BD69958}.Release|Win32.ActiveCfg = Release|Win32
        {A0601C1A-BC0F-45D0-BDB1-C5056BD69958}.Release|Win32.Build.0 = Release|Win32
        {A0601C1A-BC0F-45D0-BDB1-C5056BD69958}.MinSizeRel|Win32.ActiveCfg = MinSizeRel|Win32
        {A0601C1A-BC0F-45D0-BDB1-C5056BD69958}.MinSizeRel|Win32.Build.0 = MinSizeRel|Win32
        {A0601C1A-BC0F-45D0-BDB1-C5056BD69958}.RelWithDebInfo|Win32.ActiveCfg = RelWithDebInfo|Win32
        {A0601C1A-BC0F-45D0-BDB1-C5056BD69958}.RelWithDebInfo|Win32.Build.0 = RelWithDebInfo|Win32
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
    EndGlobalSection
    GlobalSection(ExtensibilityAddIns) = postSolution
    EndGlobalSection
EndGlobal

The Project file is similarly ugly and 294 lines long.

Adding dependencies is pretty simple too, here's how you add boost:

find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Boost_LIBRARIES})
Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274
  • Hey benjamin lindley, How do i run this file?? Could you please help me out, i'm not familiar with CMake! – Vinay C Oct 24 '11 at 15:00
  • Hey @Benjamin Lindley it says "You must have 20 reputation on Stack Overflow to talk here".. i have only 15.. so could u just give me a syntax how to run this file? i created a file CMakeLists.txt with the appropriate content.. how do i run?? plz help me out.. – Vinay C Oct 24 '11 at 15:26
  • @user737415: Oh, sorry. I didn't realize that, it's just that the moderators are constantly hounding us to not have discussions in the comments. Oh well. Description follows. – Benjamin Lindley Oct 24 '11 at 15:31
  • 1
    Create a base directory for your project. Then create two sub-directories. One named "source" and one named "msvc10". Put CMakeLists.txt inside the "source" directory along with any source files. Navigate to the "msvc10" folder. Then type "cmake ../source". – Benjamin Lindley Oct 24 '11 at 15:31