How to: Create Item Templates in Visual Studio 2017 - 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

Related

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.

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

How do you create a simple comment header template for all new classes in Visual C++ 2010?

This may be a duplicate, but I haven't found anything that answers it thus far. My company passed a resolution that all files need to have a boilerplate comment header, with file name and copyright date among other things. I was hoping there would be an easy way to just create a header template that is added to the top of every new class (.cpp and .h files) added to the project with a couple of variables that are replaced based on the date, file name, etc.
Unfortunately, it seems like this is a much larger task that it seems it should be. I've looked into Manipulating Code using the Visual C++ Code Model and Manually Creating an Item Template and can't seem to get any of them to do what I want.
Sorry if this sounds like a "do my work for me" post, but to me this just isn't worth spending that much time on. If it's going to take a day to figure out the subtleties of extending Visual Studio, I can just manually add and edit the header for each new file, as it isn't done that often. Is there an easier method than those I was looking at, or a simple example on how to utilize those methods for my purpose?
This may not get you any further than you have already got, but Simon is close in that you can create C++ file templates in the way that he suggests, but the path to the C++ templates is C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcprojectitems (note that on 32-bit machine it will just be Program Files).
If you edit the file NewC++File.cpp, the next time you add a new C++ file to a project your template will be used. Alternatively you can create your own files in this folder and they will appear in the Add New Item dialog.
This won't solve your problem around inserting the current date in the header (assuming you want that to be automatically determined), but you could update the template that you're using once a year, and that would be slightly less of a chore.
HTH
What you are looking for is called : Code Snippets
I personnaly use the snippets provided into VAssistX but it's a shareware so it's might not be a good solution for your company.
By the way if you are developing application on Visual C++ without VAssistX you are wasting a lot of time ;)
There is also a code snippets manager into Visual Studio, i never used it but i found some documentation on google :
http://msdn.microsoft.com/en-us/library/d60kx75h(VS.80).aspx
and
http://blogs.microsoft.co.il/blogs/gilf/archive/2009/01/17/how-to-write-your-own-code-snippets.aspx
I hope it's will be helpfull.
Update: Unfortunately, the C++ templates do not work in the same way.
I have left the text below as a reference to anyone who finds this, but it only works for C#/VB.
You can definitely edit the class template for C# (we have done it for exactly the same reason as you - to include a standard header), I would assume you can do it for C++ too.
Check out these two directories:
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\"
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache\"
Somewhere in each of those directories will be a class template folder. For C# it's in a zip file here:
...\ItemTemplates\CSharp\Code\1033\Class.zip
Extract the zip, edit the template to include your header and re-zip it. You will also then need to place an unzipped copy under the ItemTemplatesCache folder, (following the same path - ...\ItemTemplatesCache\CSharp\Code\1033\Class)
There are more details here.
(Sorry, I'm on my Linux PC now so I can't check if these paths exist for C++. If you get it to work, post the correct C++ paths back here, and I'll update this answer to reference them)

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

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.