How to include a property sheet in VC project template

我只是一个虾纸丫 提交于 2019-12-01 12:06:11

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

  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.

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.

I had the same problem. I was unable to actually add the property sheet to the project, since it looks like Visual Studio (2013 in my case) treats property sheets as projects. I expect that I could have used some combination of ProjectCollection and a second vstemplate file to create the project that consists of the property sheet first, followed by my actual project. However, I ended up hacking a solution together instead because it was much less work.

  1. Open up the .vcxproj file and find the first line that looks like <ImportGroup Label="PropertySheets" />

  2. Open up your custom property sheet file that contains the properties you're interested in adding. Copy all elements under (but not including) the Project element.

  3. Paste all of that content immediately before the location you found in step (1).

  4. Comment out or remove all sub-elements of ImportGroup elements that reference your custom property sheet (it should now look like <!-- <Import Project="whatever.props" /> -->).

Re-zip and install the template. Now you should be able to create a project with the properties you're interested in. The downsides are that the resulting .vcxproj is kind of ugly and you won't have a separate property sheet, but you should at least be able to distribute and reference your properties in a new project type.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!