Hawkeye5450
Hawkeye5450

Reputation: 672

Visual studio 2017 Community project template

I have tried to create a custom project template for Visual Studio Community 2017 for c++. I have exported the project as a template, however when I try to access the files I added in a new project, they are not created in the project folder. I can try to open them in the Solution Explorer, but the files themselves are not being created. I have tried to add <CreateinPlace>true</CreateInPlace> as well as adding the .zip files to the VS template directory, but these had no effect. How would I be able to add the files to the template and get them to show up in a new project?

Upvotes: 1

Views: 223

Answers (2)

Hawkeye5450
Hawkeye5450

Reputation: 672

What it actually was is that the .vstemplate wasn't adding the files as project items, so when I exported the project, it didn't know to look for them. To fix it I just added

<TemplateContent>
        <Project TargetFileName="CS235-Template.vcxproj" File="CS235-Template.vcxproj" ReplaceParameters="true">
            <ProjectItem ReplaceParameters="false" TargetFileName="$projectname$.vcxproj.filters">CS235-Template.vcxproj.filters</ProjectItem>
            <ProjectItem ReplaceParameters="true" TargetFileName="main.cpp">main.cpp</ProjectItem>
            <ProjectItem ReplaceParameters="true" TargetFileName="Debug.h">Debug.h</ProjectItem>
            <ProjectItem ReplaceParameters="true" TargetFileName="input.txt">input.txt</ProjectItem>
        </Project>
    </TemplateContent>

After doing this they worked just fine.

Upvotes: 1

Troy Turley
Troy Turley

Reputation: 723

Visual Studio stores the template in 3 different locations. The folder that VS tells you is only one of the 3 options. I finally modified the .vstemplate file in:

Libraries\Documents\Visual Studio 2017\Templates\ProjectTemplates
  • Unzip the file (Right-Click->Extract All)
  • Open the .vstemplate file
  • Add <CreateInPlace>true</CreateInPlace> to the <TemplateData> section
  • Save the file
  • Rezip the file (or don't. It works either way but if you leave the zip file the template will show up twice)

The following answer is a little off topic but it's the one that helped me solve the problem. [Answer][https://stackoverflow.com/a/48274550/4892466]

Upvotes: 0

Related Questions