Now I have a zip folder in my exported templates containing the template we named above (we'll just say project template). The problem is, when I create a new project using this template, the .h and .cpp files are referenced in the solution explorer, but they do not exist:
And if I try clicking on driver.cpp or driver.h, I get the following error
But if I paste in the driver.h and driver.cpp files into this location, they work
It defeats the purpose of having a template if I have to paste in the files for this to work, why is it that these files are missing and yet exist in file explorer? Why is this not saving the contents of the template I exported? What do I need to do to make the template create the two missing driver.cpp and driver.h files automatically so I don't have to go through this process every time I create a project that needs these same files?
To have all the information available, current compilers tend to require that a template must be fully defined whenever it is used. That includes all of its member functions and all template functions called from those. Consequently, template writers tend to place template definition in header files.
A template is not like a function which can be compiled into byte code. It is just a pattern to generate such a function. If you put a template on its own into a *. cpp file, there is nothing to compile.
A header file should be included only when a forward declaration would not do the job. The header file should be so designed that the order of header file inclusion is not important. This is achieved by making sure that x.h is the first header file in x.
You make the declarations in a header file, then use the #include directive in every . cpp file or other header file that requires that declaration. The #include directive inserts a copy of the header file directly into the . cpp file prior to compilation.
I had the same problem. The issue is that there is a bug in the VS Export Template routine that is not copying files that are organized in project subfolders. ex. ..\Source Files\driver.cpp
This is what I did as a workaround
Delete the old (messed up) templates: goto -> C:\Users\xxxx\AppData\Roaming\Microsoft\VisualStudio\14.0\ProjectTemplatesCache Delete the xxxx.zip directories you don't want anymore.
Close and ReOpen Visual Studio. (you can check if the templates are gone - File/New/Project ...
Create your project as you would like.
Click and drag all the headers and source files to the project root
File/Export Template . . .
Now when you open a project based on the template all the files will be there and you can simply click and drag them under the appropriate subfolder.
Cheers!
Rather than using Add
-> New Item...
, I've found that a somewhat clean workaround is to simply drag and drop the files you need into the project. Doing this will include them when exporting the template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With