如何在VC项目模板中包含属性表 [英] How to include a property sheet in VC project template

查看:136
本文介绍了如何在VC项目模板中包含属性表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2013解决方案中有很多VC项目.对于每个项目,我将其大多数属性保留在属性表AllConfigurations.props中,该属性表属于项目的文件夹. 我正在尝试为此类项目创建项目模板.我将AllConfigurations.props添加到模板zip文件中,并在.vstemplate中引用它:

I have a lot of VC projects in Visual Studio 2013 solution. For each project I keep most of it's properties in property sheet AllConfigurations.props, belonging to project's folder. I'm trying to create a project template for such project. I add AllConfigurations.props to template zip file and reference it in .vstemplate:

  <Project TargetFileName="Test.vcxproj" File="Test.vcxproj" ReplaceParameters="true">
  <ProjectItem ReplaceParameters="false" TargetFileName="AllConfigurations.props">AllConfigurations.props</ProjectItem>

但是当使用此模板创建新项目时,Visual Studio显示错误:

But when creating new project with this template, Visual Studio displays an error:

无法读取项目文件"Test1.vcxproj". Test1 \ Test1.vcxproj(76,5):找不到导入的项目"Test1 \ AllConfigurations.props".确认声明中的路径正确,并且文件在磁盘上.

Unable to read the project file "Test1.vcxproj". Test1\Test1.vcxproj(76,5): The imported project "Test1\AllConfigurations.props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

该项目未添加到解决方案中.似乎VS尝试在从模板解压缩所有文件之前加载新项目.

The project is not being added to the solution. It seems that VS tries to load new project before unpacking all files from the template.

我该如何处理?

推荐答案

这里是创建包含用户属性表的Visual Studio C ++项目模板的方法.

Here is how you can create a Visual Studio C++ project template that includes your user property sheets.

  1. 创建要导出到模板的项目,然后在 Property Manager 窗口中添加属性表.您的情况是 AllConfigurations.props 文件.
  2. Solution Explorer 窗口中,将属性表文件添加到项目中.您必须执行此操作才能将文件保存到模板档案中,并自动将其复制到新项目中.
  3. 使用文件->导出模板导出项目模板.在向导的第二页上,取消选中自动将模板导入Visual Studio 选项.
  4. 从模板zip文件中提取 .vcxproj 文件,然后在文本编辑器中打开.搜索包括您的属性表文件的行.项目中的每个构建配置都会有一个.在您的情况下,它们应如下所示: <Import Project="AllConfigurations.props" />. 将行更改为此:<Import Project="AllConfigurations.props" Condition="exists('AllConfigurations.props')" />.即使文件不可用,这也将允许项目打开.
  5. 保存文件,并将其添加回模板zip文件中.
  6. 将zip文件复制到 我的文档> \ Visual Studio 版本 \ Templates \ ProjectTemplates 目录中.
  1. Create a project that you want to export to a template and add the property sheet in the Property Manager window. In your case, the AllConfigurations.props file.
  2. In the Solution Explorer window, add the property sheet file to the project. You must do this to get the file into the template archive and be automatically copied to the new project.
  3. Export the project template using File->Export Template. On the second page of the wizard, un-check the Automatically import the template into Visual Studio option.
  4. Extract the .vcxproj file from the template zip file and open in a text editor. Search for the lines that include your property sheet file. There will be one for each build configuration in your project. In your case they should look like this: <Import Project="AllConfigurations.props" />. Change the lines to this: <Import Project="AllConfigurations.props" Condition="exists('AllConfigurations.props')" />. This will allow the project to open even if the file is not available yet.
  5. Save the file and add it back to the template zip file.
  6. Copy the zip file to the <My Documents>\Visual Studio version \Templates\ProjectTemplates directory.

关闭并重新打开Visual Studio,您应该能够使用新模板创建一个新项目.您可能必须关闭解决方案并重新打开它,以使属性表在 Property Manager 窗口中的所有配置下可见.如果您不希望在其中看到 .props 文件,可以在 Solution Explorer 窗口中从新项目中删除它.它仍将在属性管理器中使用.

Close and re-open Visual Studio and you should be able to create a new project with your new template. You may have to close the solution and re-open it for the property sheet to be visible under all the configurations in the Property Manager window. You can remove the .props file from your new project in the Solution Explorer window if you don't want it visible there. It will still be used in Property Manager.

这篇关于如何在VC项目模板中包含属性表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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