molonepa
molonepa

Reputation: 63

Missing .lib files from exported Visual Studio template

I'm creating a template C++ project for Visual Studio that requires some .lib and .dll files. The files are linked to in the project properties linker settings and included in the dependencies and also included in the project via the Solution Explorer. Everything runs fine, but when I export the project to a template and use that template to create a new project the .lib files are the only ones missing.

I've tried extracting the .zip of the exported template, adding the .lib files manually and their paths to the .vstemplate, then re-zipping the project, but this hasn't worked either.

I'm using Visual Studio 2019 on Windows 10 if that's relevant.

Upvotes: 2

Views: 460

Answers (2)

Jorge Martins
Jorge Martins

Reputation: 340

  1. create the exported template and then navigate to C:\Users%UserName%\Documents\Visual Studio 2022\Templates\ProjectTemplates and find the .zip file with your template.
  2. unzip the template.
  3. add the missing .lib files to their location inside the template folder structure.
  4. open with a text editor the MyTemplate.vstemplate file.
  5. locate <ProjectItem ReplaceParameters="false" TargetFileName="main.cpp">main.cpp</ProjectItem>
  6. using the same format include a line for each .lib file you need to include, e.g. <ProjectItem ReplaceParameters="false" TargetFileName="glfw3.lib">DEPENDENCIES\GLFW\lib-vc2022\glfw3.lib</ProjectItem>
  7. open with a text editor the Template.vcxproj file.
  8. find where the Include files are referenced and add a line for each .lib file, e.g. <ClInclude Include="Dependencies\GLEW\lib\Release\x64\glew32.lib" />
  9. save the files, recompress to a zip file and replace the template zip in the initial location.

Now you will be able to create a new project from this template and it will include the .lib files

Upvotes: 0

Barrnet Chou
Barrnet Chou

Reputation: 1923

In my opinion, as mentioned in the link, the best way is to create a nuget package which contains all your 'content' - such as DLLs.

Of course, there is another way:

  1. Create a Dependencies folder under the project directory, put the required dlls and libs.

  2. Set Proeperties->C/C++->General->Additional Include Directories->(SolutionDir)Dependencies\.. and Proeperties->Linker->General->Additional Library Directories->$(SolutionDir)Dependencies\.. in your project template.

For example: enter image description here

enter image description here

  1. When you use the project template, copy the Dependencies folder to your new project directory.

Upvotes: 1

Related Questions