Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exported project template in VS2017 misses source files

When I use the Project -> Export template option in Visual Studio 2017, the resulting ZIP file includes the main project files, but not any of the *.cpp and *.hpp files that I've added. How do I include everything with the template? I should also note that this behavior seems to have changed in an update at some point.

like image 974
Overv Avatar asked Jan 31 '18 23:01

Overv


People also ask

How do I save a Visual Studio project as a template?

On the Project menu, choose Export Template. The Export Template Wizard opens. On the Choose Template Type page, select Project Template. Select the project you want to export to a template, and then choose Next.

How do I find my Visual Studio project Template?

For example, you can right-click the project > click properties > select Application and see(refer to) the related information, for example, Output type -- Windows Application, Console Application, Class Library… Or you can find some related information about the project type from items, files etc.


2 Answers

You need to manually edit the .vstemplate file and add <CreateInPlace>true</CreateInPlace> in the <TemplateData> tag so it looks like this:

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
    <TemplateData>
        <Name>TemplateTest</Name>
        <Description><No description available></Description>
        <ProjectType>JavaScript</ProjectType>
        <ProjectSubType>
        </ProjectSubType>
        <SortOrder>1000</SortOrder>
        <CreateNewFolder>true</CreateNewFolder>
        <CreateInPlace>true</CreateInPlace>
        <DefaultName>CodovaTemplateTest</DefaultName>
        <ProvideDefaultName>true</ProvideDefaultName>
        <LocationField>Enabled</LocationField>
        <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
        <Icon>__TemplateIcon.ico</Icon>
  </TemplateData>
like image 50
King Henry Avatar answered Nov 15 '22 13:11

King Henry


The problem is in your .vstemplate file. What you need to do is edit it so that VS knows that there is supposed to be additional files. Unzip the file that was exported, add the files you want, then open the .vstemplate file. The part of the .vstemplate you should change is between the <TemplateContent> tags:

    <TemplateContent>
                <Project TargetFileName="project.vcxproj" File="project.vcxproj" ReplaceParameters="true">
                    <ProjectItem ReplaceParameters="false" TargetFileName="$projectname$.vcxproj.filters">project.vcxproj.filters</ProjectItem>
                    <ProjectItem ReplaceParameters="true" TargetFileName="file1.cpp">file1.cpp</ProjectItem>
                    <ProjectItem ReplaceParameters="true" TargetFileName="file2.h">file2.h</ProjectItem>
                    <ProjectItem ReplaceParameters="true" TargetFileName="input.txt">input.txt</ProjectItem>
                </Project>
    </TemplateContent>

This tells VS to add the files file1.cpp, file2.h and input.txt to the project when you make it. Just change the names to the files you want, save everything and rezip the folder.

like image 42
Hawkeye5450 Avatar answered Nov 15 '22 12:11

Hawkeye5450