一个空的 Visual C++ 如何能?项目以编程方式创建?
我想知道如何使用空 Visual C++ 项目的模板以编程方式使用该空项目创建新的解决方案。我现在拥有的代码(C#)是:
string VSProgID = "VisualStudio.Solution.10.0";
Type solnObjType = System.Type.GetTypeFromProgID(VSProgID, true);
Solution4 soln = (Solution4) System.Activator.CreateInstance(solnObjType, true);
soln.Create(@"C:\NewSoln", "New");
soln.SaveAs(@"C:\NewSoln\New.sln");
string emptyVCProjPath = soln.GetProjectTemplate("General/Empty Project", "VC++"); // Here's where I need help
soln.AddFromTemplate(emptyVCProjPath, @"C:\NewSoln\NewProj", "New.vcxproj", false);
我无法在所有其他模板(C#/F#/VB)所在的位置找到 VC++ 空项目模板。当我通过 IDE 手动创建新项目时,VC++ 空项目模板确实出现在已安装的模板中。 soln.GetProjectTemplate()
的参数应该是什么?它似乎没有将 "VC++"
识别为一种语言。我知道 "CSharp"
和 "VisualBasic"
是有效的选项。但我想要一个 VC++ 空项目。任何帮助将不胜感激。
I wanted to know how to use the template for an Empty Visual C++ project to programmatically create a new solution with this empty project. The code (C#) I have right now is:
string VSProgID = "VisualStudio.Solution.10.0";
Type solnObjType = System.Type.GetTypeFromProgID(VSProgID, true);
Solution4 soln = (Solution4) System.Activator.CreateInstance(solnObjType, true);
soln.Create(@"C:\NewSoln", "New");
soln.SaveAs(@"C:\NewSoln\New.sln");
string emptyVCProjPath = soln.GetProjectTemplate("General/Empty Project", "VC++"); // Here's where I need help
soln.AddFromTemplate(emptyVCProjPath, @"C:\NewSoln\NewProj", "New.vcxproj", false);
I wasn't able to find the VC++ Empty Project template in the location where all the other templates (C#/F#/VB) are located. The VC++ Empty Project Template does appear in the installed templates when I create a new project manually through the IDE. What should the parameters be for soln.GetProjectTemplate()
? It doesn't seem to recognize "VC++"
as a language. I know that "CSharp"
and "VisualBasic"
are valid options. But I wanted a VC++ Empty Project. Any help will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发布这个答案是希望它可以帮助那些面临与我相同问题的人。
显然,Visual Studio 可扩展性框架 API 不提供以编程方式创建空 Visual C++ 项目的选项。我必须生成解决方案和项目文件才能实现此目的。具体来说,必须生成
[solution_name].sln
、[project_name].vcxproj
和[project_name].vcxproj.filters
文件。必须为新项目生成 GUID 并将其插入到适当的位置。如果需要向这个空项目添加文件,则需要为头文件生成ClInclude
标记,为源文件生成ClCompile
标记。这些标记将添加到[project_name].vcxproj
和[project_name].vcxproj.filters
文件中。请参阅现有 Visual C++ 项目的文件,以帮助您了解哪些内容在哪里。这非常简单。更新
由于某种原因,以这种方式生成的 VC++ 解决方案无法直接打开(通过在 Windows 资源管理器中双击解决方案文件)。我必须启动 Visual Studio 并从那里打开解决方案。
I am posting this answer in the hope that it may help someone facing the same problem that I was facing.
Apparently the Visual Studio Extensibility framework API doesn't provide an option to create an Empty Visual C++ project programmatically. I had to generate the solution and project files to achieve this. Specifically, the
[solution_name].sln
,[project_name].vcxproj
, and[project_name].vcxproj.filters
files had to be generated. A GUID had to be generated for the new project and inserted at the appropriate places. If one needs to add files to this empty project,ClInclude
tags need to be generated for header files, andClCompile
tags for source files. These tags are added to the[project_name].vcxproj
, and[project_name].vcxproj.filters
files. Refer to an existing Visual C++ project's files to help you figure out what goes where. It is pretty straightforward.UPDATE
For some reason, the VC++ solution generated this way does not open directly (by double-clicking the solution file in Windows Explorer). I have to launch Visual Studio and open the solution from there.