创建新的 Visual Studio 项目,添加文件并运行它 - 命令行

发布于 2024-12-11 13:43:45 字数 181 浏览 0 评论 0原文

有没有办法在不使用 IDE 的情况下创建新的 Visual Studio 项目,而是使用命令提示符?

我正在开发一个将生成小型 C++ 程序的项目,所以我想创建一个新项目,将该 C++ 文件添加到该项目中,编译并运行它,所有这些都仅使用命令提示符(批处理文件)..

所以任何人都可以请让我知道该怎么做..提前致谢..

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..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

゛清羽墨安 2024-12-18 13:43:45

Visual Studio 项目只是 XML 文件,因此您只需研究它们的格式并将其写出来即可。 (格式从 2008 年到 2010 年发生了变化。)
解决方案文件是自定义文本格式,但也没有那么复杂。

最后,devenv.exe 有一个“不启动 IDE,只需在命令行上编译此解决方案”的开关,您可以使用它来编译生成的解决方案。

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.

时光病人 2024-12-18 13:43:45

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})

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})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文