Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

source / header files not being created when I export a template containing them

  1. Create a new project
  2. add 2 files, driver.h (under header files) and a driver.cpp (under source files)
  3. Add content such as #include's to the header file, and include that header file to the .cpp file
  4. file < export template
  5. project template, click next.
  6. add template name, description, don't care for icon or image so leave blank.
  7. finish, then create a project using the above template.

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: enter image description here

And if I try clicking on driver.cpp or driver.h, I get the following error enter image description here

But if I paste in the driver.h and driver.cpp files into this location, they work enter image description here

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?

like image 272
JORDANO Avatar asked Nov 16 '16 10:11

JORDANO


People also ask

Do templates go in header 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.

Why template function only defined 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.

Do I include the header file in a source file?

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.

How do I include a .h file in CPP?

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.


2 Answers

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

  1. 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.

  2. Close and ReOpen Visual Studio. (you can check if the templates are gone - File/New/Project ...

  3. Create your project as you would like.

  4. Click and drag all the headers and source files to the project root

  5. File/Export Template . . .

  6. 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!

like image 171
Fareed Avatar answered Nov 03 '22 19:11

Fareed


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.

like image 41
Valrog Avatar answered Nov 03 '22 17:11

Valrog