有没有办法从命令行添加源文件到visual studio项目? [英] Is there a way to add source files to visual studio project from command-line?

查看:289
本文介绍了有没有办法从命令行添加源文件到visual studio项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用sublime编辑一个视觉工作室项目。
我有一个自定义构建:

  {
cmd:[c:\\\ \\\\\\\\\\\\\\\\\\\v4.0.30319\\MSBuild.exe],
working_dir:$ {project_path:$ {folder:$ { file_path}}} /../项目
}

但是如果我添加新文件我还需要将它们包括在项目中。



有没有办法从命令行,也许在编译时?



我正在使用opengl使用c ++;



我基本上使用opengl网站上提供的示例之一设置了一个项目。 p>

然后我在sublime文本中打开项目文件夹,并使用自定义构建系统成功编译。



我添加新的源文件到项目(* .h和* .cpp)我得到一个链接错误。



当我在Visual Studio中创建相同的错误。



通过手动浏览并将其添加到项目中后,文件已包含,该错误消失。



我想要的是一种方法自动将一个文件夹中的所有源文件添加到项目(通过命令行,通配符或smth其他)。



这样,我可以很容易地在vs2010项目中工作,添加新的源文件并构建项目。



或者也许已经有更好的工作流程了?

解决方案

您可以尝试修改.vcxproj文件,以便在您的项目文件夹或下面的文件夹中包含任何.h和.cpp文件。



如果是c ++ VS项目可以尝试修改.vcxproj文件,如下所示:

 <?xml version =1.0encoding =utf-8 > 
< Project DefaultTargets =BuildToolsVersion =4.0xmlns =http://schemas.microsoft.com/developer/msbuild/2003>
<! - 项目文件的其余部分未处理 - >

<! - 修改部分的开始 - >

< ItemGroup>
< ClInclude Include =** \ * .h/>
< / ItemGroup>
< ItemGroup>
< ClCompile Include =** \ * .cpp/>
< / ItemGroup>

<! - 修改部分的末尾 - >

< Import Project =$(VCTargetsPath)\Microsoft.Cpp.targets/>
< ImportGroup Label =ExtensionTargets>
< / ImportGroup>
< / Project>

请注意,稍后从VS内部添加文件到您的项目将替换上述修改!



另外,您还可以创建一个外部项目文件,其中包含相同的< ItemGroup /> 元素



如果您有兴趣,我将添加此替代方案的示例。


I want to use sublime to edit a visual studio project. I have a custom build:

{
   "cmd": ["c:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe"],
    "working_dir": "${project_path:${folder:${file_path}}}/../Project"
}

But if I add new files I also need to include them in the project.

Is there a way to do this from the command line, maybe at compile-time?

I am working with opengl using c++;

I basically set up a project using one of the examples provided on the opengl website.

Then I opened the project folder in sublime text and successfully compiled it using the custom build system.

However, when I add NEW source files to the project (*.h and *.cpp) I get a linking error.

I get the same error when I build in visual studio.

The error disappeared after I had included the files by manually browsing and adding them to the project.

What I wanted was a way to automatically add all the source files in a folder to the project(via command line, or wildcard or smth else).

This way I can easily work on a vs2010 project in sublime, add new source files and build the project.

Or maybe there already is a better workflow for this?

解决方案

You could try to modify your .vcxproj file to include any .h and .cpp file in your project folder or folders below.

In case of a c++ VS project you can try to alter your .vcxproj file like this:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <!-- rest of project file untouched -->

    <!-- start of modified part -->

    <ItemGroup>
        <ClInclude Include="**\*.h" />
    </ItemGroup>
    <ItemGroup>
        <ClCompile Include="**\*.cpp" />
    </ItemGroup>

    <!-- end of modified part -->

    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    <ImportGroup Label="ExtensionTargets">
    </ImportGroup>
</Project>

Be aware that adding files to your project from inside VS at later point will replace the modification described above!

As an alternative you could also create an external project file holding the same <ItemGroup /> elements described above and include this project file into your .vcxproj.

I'll add an example of this alternative if you're interested.

这篇关于有没有办法从命令行添加源文件到visual studio项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆