How to create a Visual Studio 2008 C++ project template? - c++

I've used the "Export Template" feature numerous times for C#, ASP.NET, WinForms, etc. projects. Today I tried to do it for a C++ project and noticed "Export Template" was grayed out in the File-menu.
Is it not possible to create C++ template projects in VS 2008 ?

yes it is: the ones you see already when creating a new project are in $VsInstallDir)/vcprojects. To create one yourself, you basically create a .vsz and a.vsdir file in which you describe your project template, a bunch of script/html files for your own wizard, and the template files itself (.vcproj, additional content etc.). It is not very easy, but it is possible and very handy once done. Complete explanation is on MSDN, it's too much to elaborate on here.
Same goes for project items/classwizards, they all can be customised.

Related

How to: Create Item Templates in Visual Studio 2017

How to: Create Item Templates in Visual Studio 2017. In VS 2015 from the File menu there was an Export Templates item from which projects or item could be created. Is this feature still available or just moved? thx
As stated by Guru Stron above, the template will be exported to the "C:\Users\[UserName]\Documents\Visual Studio 2017\My Exported Templates" folder as a zip file. In order to use this template, you will have to move or copy it to the following folder... C:\Users\[UserName]\Documents\Visual Studio 2017\Templates\ProjectTemplates. Additionally, if you want to further define where in the New Projects dialog box your template will appear, you will need to dig deeper in the path.
For example, if you have a .NET core template written in C#, you will want to place your template in this path... C:\Users\[UserName]\Documents\Visual Studio 2017\Templates\ProjectTemplates\Visual C#\.NET Core. Of course, you may need to add the last folder (.NET Core).
The coolest thing about this is that you can create a collection of templates for your own organization, you could place the templates in a path such as... C:\Users\[UserName]\Documents\Visual Studio 2017\Templates\ProjectTemplates\Visual C#\Daffitt Technologies\.NET Core. This will look something like this:
One thing to note, is that there may be other tweaks you’ll have to do to the files contained in the zip file – particularly the MyTemplate.vstemplate file. I noticed that the created project templates don’t always create the results I expected.
I did find Create Item Templates in Visual Studio 2017 under the Projects menu. And I am able to export items and import them in to other projects.
it moved to project menu however I have exported several things and none of them show up haven't figured out how to make it work
As stated in other answers, the option is in the Project menu. The documentation for this is now at https://learn.microsoft.com/en-gb/visualstudio/ide/how-to-create-item-templates

Create "Add New Item Wizard" in Visual C++

Maybe I'm not searching with the right keywords, but I'm unable to find documentation on how to make your own "Add New Item Wizard" in Visual Studio Community 2013 for C++ projects.
What I want to achieve is to be able to add new extensionless source files to my C++ projects from Project > Add New Item... instead of adding a C++ Source File and deleting the .cpp extension in the Solution Explorer afterwards.
First I tried to make my own template, but it turns out, that that is not possible with C++ Projects in Visual Studio.
Second I tried to see if I can modify one of the default templates (Stack Overflow post), but that is also not possible.
I'm reading this documentation: MSDN: Walkthrough: Creating a Wizard, but I can only find instructions on how to make a "New Project Wizard" and not an "Add New Item Wizard".
What I am missing here?
Well, it seems that the solution for what I specifically wanted to do was quite simple after all:
Instead of exporting and adding an "Item Template" (a feature that in the last version of VS does not work for C++ projects) or modifying the default item templates, or trying to make my own Wizard; You can just go to: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcprojectitems and copy your custom template files there. You should also modify the .vsdir files in that directory by hand for further customization. I used this reference to specify an icon and change the sorting order.
It's not so nice like in the C# or VB parts of Visual Studio where you can just use the Export Wizard to add new project and item templates to the corresponding dialogs and have them stored in your templates folder. I will write some feedback to the VS team and hope they fix this in the next version.

Highlight selected C/C++ file at the right place in other project in the same solution

I'm trying to understand a framework in C++, Visual studio by studying this framework's examples. All of such examples and framework are projects, and grouped in a solution in Visual Studio 2012. And each time, while reading an examples, I want to go into some classes the framework for more understanding and see where such classes located in filters in framework.
I searched in stackoverflow for highlighting filter in Visual Studio and I got two answers: link 1 and link2.
But my problem is I followed instructions in these two links, and they helped me highlight selected files, but they only highlight the selected file in the filter "External Dependencies". It do not highlight the source file at the right places, which is in other projects but in the same solution.
There's any way to do it?
If you would like to examine the declaration or definition (implementation) of a particular type you can right click on the name and select "Go To Declaration" or "Go To Definition". If they are available Visual Studio will open the appropriate file and take you directly to the item you want to examine. It may display multiple choices (i.e. there are a few forward declarations of a type) that will allow you to select which one to view. As long as the source for the framework is in a project loaded in the solution this should be more than sufficient for your needs. If the framework doesn't have a Visual Studio project it's quite easy to create one and add the source files to it. Features like Intellisense, class browsing, etc. will be available for the framework and the project doesn't even have to build without errors.

Compiling and Running MFC Applications with Visual Studio 2008?

I was wondering if anyone can provide a detailed explanation on how I can compile and execute a C++ MFC application in Visual Studio 2008 given that I already have a .h and .cpp file only.
I couldn't find a decent and up to date explanation anywhere and when I try to create a plain MFC project in VS08 I get a bunch of xxx.h xxxDoc.h xxxView.h files, I try and replace those files with my own .cpp and .h files but i get a ton of errors when I run it.
So just to summarize, how do I compile and run my MFC project's .h and .cpp files in Visual Studio 2008 and create an .exe?
Thanks in advance.
See here: Creating an MFC Application
This tutorial may help you as well: Introduction to MFC Applications
It depends on what you are trying to do, but deleting the files the wizard creates is not a good idea. They are there because you told it to put them there (by selecting MFC-SDI/MDI), so they are necessary for the basic initialization and such.
If you don't need the Doc/View architecture, you can create a Dialog Based application. Or, you can even use an MDI or SDI app, and not use the Doc and the View, but if you want to delete them you'll have to make sure there are no references to them. What you cannot delete is the "MyProject.cpp" (where the CWinApp derived class lays), which does the initialization of the application.
Another option is to create a Console application with MFC support. To do so, you have to select "Win32 console application" in the wizard and then check "Add headers for MFC".

Import Existing C++ Source Code into Visual Studio

I am trying to import an existing c++ application's source into visual studio to take advantage of some specific MS tools. However, after searching online and playing with visual studio, I cannot seem to find an easy way to import existing c++ source code into visual studio and keep it structurally intact.
The import capacity I did find flattens out the directories and puts them all into one project. Am I missing something?
(This is all unmanaged C++, and contains specific builds for win/unix)
With no project/solution loaded, in Visual Studio 2005 I see this menu item:
File > New Project From Existing Code...
After following the wizard, my problem is solved!
Switching the "Show All Files" button shows the complete hierarchy with all directories and files within.
If the New Project From Existing Code... option isn't available, you'll need to add it in Tools > Customize...
I am not aware of any general solution under the constraints given - specifically having to create many projects from a source tree.
The best option I see is actually creating the project files by some script.
Creating a single project manually (create empty project, then add the files),
Configure it as close as possible as desired (i.e. with precompiled headers, build configurations, etc.)
Use the .vcproj created as skeleton for the project files to be created
A very simple method would file list, project name etc. with "strange tokens", and fill them in with your generator. If you want to be the good guy, you can of course use some XML handling library.
Our experience: We actually don't store the .vcproj and .sln in the repository (git) anymore, but a python script that re-genrates them from the source tree, together with VS 2008 "property sheet templates" (or whatever they are called). This helps a lot making general adjustments.
The project generation script contains information about all the projects specialties (e.g. do they use MFC/ATL, will it create DLL or an EXE, files to exclude).
In addition, this script also contains dependencies, which feeds the actual build script.
This works quite well, the problems are minor: python requried in build systems, not forgetting to re-gen the project files, me having to learn some python to make adjustments to some projects.
#Michael Burr "How complex are the python scripts and whatever supporting 'templates' you might need?"
I honestly can't tell, since I gave the task to another dev (who picked python). The original task was to provide a build script, as the VS2008 solution build was not good enough for our needs, and the old batch file didn't support parallelization. .vcproj generation was added later. As I understand his script generates the .vcproj and .sln files from scratch, but pulls in all the settings from separate property sheets.
Pros:
Adding new configurations on the fly. Some of the projects already had six configurations, and planning for unicode support meant considering doubling them for a while. Some awkward tools still build as MBCS, so some libs do have 8 configs now. Configuring that from hand is a pain, now it just doesn't bother me anymore.
Global changes, e.g. moving around relative project paths, the folder for temp files and for final binaries until we found a solution we were happy with
Build Stability. Merging VC6 project files was a notable source of errors for various reasons, and VC9 project files didn't look better. Now things seem isolated better: compile/link settings in the property sheets, file handling in the script. Also, the script mostly lists variations from our default, ending up easier to read than a project file.
Generally: I don't see a big benefit when your projects are already set up, they are rather stable, and you don't have real issues. However, when moving into the unknown (for us: mostly VC6 -> VC9 and Unicode builds), the flexibility reduced the risk of experiments greatly.
Create a new empty solution and add your source code to it.
For example,
File>New>Project...
Visual C++>Win32>Win32 Console Application
Application Settings>
- Uncheck "Precompiled Header"
- Check "Empty Project"
Project is then created. To add existing code:
Project>Add Existing Item...>
- Select file(s) to add
Recompile, done!
In the "Solution Explorer" you can click on the "Show All Files" button to have Visual Studio display the files as they exist on the file system (directories and all).
In my opinion this is an imperfect workaround, but I believe it's the best available. I'm unaware of a plug-in, macro or other tool that'll import a directory into an actual project with folders that mirror the file system's.
I know this question is already marked correct, but I was able to import existing code into a project with Visual Studio 2008 by doing "File" -> "New Project from existing code". The directory structure of my code was retained.
You can always switch view from project menu
For eg. Project->Show All Files
The above will display the files in unformated raw file system order
Not sure of older versions but it works on VS 2010
I understand you, I have the same problem: many .cpp and .h files organized in many folders and subfolders with include paths written for this folder structure. The only way you can do to import this folder structure together with the source files is to use "Show All Files" and then right-click on folders and select "Import in Project". This works for me when I am using C-Sharp projects. But it does not work for my C++ Projects. I am still searching for a solution...