有没有办法在不使用IDE的情况下创建新的visual studio项目,而是使用命令提示符??
我正在开发一个将生成小型C ++程序的项目,所以我想创建一个新项目,将该C ++文件添加到该项目,编译并运行它,所有这些只使用命令提示符(批处理文件)。 / p>
所以有人可以让我知道如何做到这一点..提前致谢..
答案 0 :(得分:4)
Visual Studio项目只是XML文件,因此您可以只研究它们的格式并将其写出来。 (格式从2008年改为2010年。) 解决方案文件是一种自定义文本格式,但也不是那么复杂。
最后,devenv.exe有一个“不启动IDE,只需在命令行上编译此解决方案”的开关,您可以使用它来编译生成的解决方案。
答案 1 :(得分:2)
让CMake为您制作项目文件。它使用更清晰的语法,您还可以为各种其他构建系统生成项目文件。
例如,这是一个非常基本的CMake文件:
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})
这是它生成的解决方案文件。
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
项目文件同样丑陋,长294行。
添加依赖项也很简单,这里是你添加boost的方法:
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Boost_LIBRARIES})