Visual Studio 2008: How to install an item template - visual-studio

I have created an Item Template using the "Export Template" wizard. I opened up the XML file and made a couple of minor changes, then rezipped the package. Then I checked the item template into source control so that everyone on the team can access it if they want.
But for the life of me I can't get the template to show up under My Templates when I go to Add->New Item.
I have tried copying the zip file into every conceivable directory:
The template directories listed under Tools->Projects and Solutions->General
All the subfolders of these directories (i.e. /Visual C#/, /Visual Web Developer/ etc)
But nothing shows up. Has anyone else managed to distribute Item Templates to their team mates before?

In order to have a VS item template appear, you need to make sure that you run "devenv.exe /installvstemplates" after you have copied the .zip file containing your .vstemplate and template code file into the %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\<Project Type> folder.
I've found that it's useful to wrap the whole thing up into an MSI that discovers the VS9 path, copies the Item/Project template to the necessary folder, and calls a custom action that shells out to devenv.exe passing the "/installvstemplates" switch. That way your colleagues just need to install the package and they are up and running!
Hope this helps.

Here are the two articles I found online:
First the one on how to create an item template:
http://msdn.microsoft.com/en-us/library/ms247113(VS.80).aspx
Second is how to get VS to locate the item template.
http://msdn.microsoft.com/en-us/library/y3kkate1(VS.80).aspx
As far as I can see you have to place your custom templates in:
My Documents\Visual Studio 2005\Templates\ProjectTemplates\Language\
Adam Berent

Related

Visual Studio: How to add linked item between folders within the same project?

I'd like to share a common .targets file between different folders within the same project (using Visual Studio 2015):
MyProject
MyNupkgContent1
build
MyNupkgContent1.props
Common.targets
MyNupkgContent2
build
MyNupkgContent2.props
Common.targets <-- should be added as link
When I try to "add as linked" Common.targets to MyNupkgContent2/build, the dialog closes but does not actually add the link. Adding files as links from a different project works fine. Is it possible to link files between folders in the same project?
I'm not certain as to how you should go about linking it but depending on contents and size of application, your best bet may be simply going into your packages and manually copying + pasting them into MyNupkgContent2

Create Visual Studio Solution from Batch File

Visual Studio seems to consist of a single solution file (*.sln) along with one or more project files (a C# project would have the *.csproj extension).
I have been playing around with a console application that parses existing directory entries to create solution files with the associated project files.
It works, but every time I run into a new project here at work I find myself spending a week or more debugging my console project so that it can churn out a solution for that particular work project.
Is there something out there already that can create a VS solution out of an existing file structure?
As you can tell from my screen capture below, these projects are nested very deep, so it would take a very long time to do this with the apps folder below with the "by mouse" technique in the Visual Studio IDE.
I created the custom console application that is posted in this post:
https://stackoverflow.com/a/22153536/153923
I invite others to contribute how they approached this solution, though.
So, I found out today that this feature already exists in Visual Studio.
Link 1: How to: Create a Project from Existing Code Files
Link 2: How to: Create a Project from Existing Code Files
Basically, though, it says this (just in case the MSDN links get changed or deleted):
You can create a Visual Studio project from an existing app—for example, an app that you obtained from an online source. Project and solution files are created on your computer and the other relevant files are added. A project can be created from Visual C++, Visual Basic, or Visual C# code files.
Security note Security Note
We recommend that you determine the trustworthiness of existing code files before you import them into Visual Studio, because Visual Studio will execute some of the code in a fully trusted process when you open the newly created project.
To create a project from existing code files
On the menu bar, choose File, New, Project From Existing Code.
The Create New Project from Existing Code Files wizard opens.
Use the wizard to specify the details of the existing code files that will be added to the project and the application that will be created when you build the project.
Another good answer was given by cbp in Visual Studio: Create a web application from existing code:
--
OK I figured it out. It's weird, but the following steps will work:
Open fresh copy of Visual Studio
File->New Project, select Web Application
Use the following settings:
Name: Website (this is the name of the existing folder with the website files in it)
Location: C:\Temp\ (anywhere will do for now)
Solution Name: TheProject (name of the existing project's root folder)
Check "Create directory for solution"
Delete the auto-created Default, Global and Web.config files
Save All and close Visual Studio
In Windows Explorer, copy the new folder on top of the existing folder so that the files are merged.
Double click on the sln file to open Visual Studio again.
Select "Show all files" (at the top of Solution Explorer)
Right click on any files or folders you want to add and select Include in Project.
Great idea!

creating custom templates in visual studio & resharper

I would like to create custom templates for c# files, unit test classes, .aspx.cs etc so that common items to all files are included once they are created eg file headers. I am working with visual studio 2010 and resharper 6. What is the easiest way to create these files and is it possible to be able to share them a team of developers easily? Appreciate any assistance or information as to how I might achieve this.
Visual Studio templates are simple enough to create - you can distribute them to your colleagues to setup in the same location on their computers (or even create an installer, if you want to makes things even easier).
See Creating Project and Item Templates and the Introduction to Visual Studio Templates on MSDN.
Contents of a Template
All project and item templates, whether installed together with Visual Studio or created by you, function by using the same principles and have similar contents. All templates contain the following items:
The files to be created when the template is used. This includes source code files, embedded resources, project files, and so on.
One .vstemplate file. This file contains the metadata that provides Visual Studio the information it needs to display the template in the New Project and Add New Item dialog boxes and create a project or item from the template. For more information about .vstemplate files, see Visual Studio Template Metadata Files.
When these files are compressed into a .zip file and put in the correct folder, Visual Studio automatically displays them in the My Templates section of the New Project and Add New Item dialog boxes. For more information about template folders, see How to: Locate and Organize Project and Item Templates.
You should open Templates Explorer from ReSharper | Templates Explorer. Then select the File Templates tab. There are default templates that comes with ReSharper. You can examine them and see how you can write your own. Here's the documentation and there's a question for useful examples.

How do I use a Visual Studio 2010 Project Template I created

I followed the steps on MSDN for creating a template. I created a new project in VS2010 and then used the File->Export Template... option to create my template. I went through the wizard and everything seemed to make sense. I left the default Output location alone (it was:
...Documents\Visual Studio 2010\My Exported Templates\MyProject.zip)
and I left the Automatically import the template into Visual Studio checked. I can see the exported zip file (and I tried moving a copy to the:
Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual C#
folder. But when I start up a new instance of VS2010 and use File->New Project I don't see my template. I was expecting that in addition to RecentTemplates/ Installed Templates/ Online Templates I might get a new category for User Templates. Failing that I thought it might be under Installed Templates but there is nothing new there. Where is my template supposed to appear? Did I miss a step?
Duh, It was working I just didn't know where to look. I would bring up the new project template and search through all the leaf nodes. Turns out I had to click on the Visual C# root in the tree view (it appears to not be in any of the leafs). This always trips me up in tree views, I never expect the root to have options, let alone be the only place that has an option.
I think you should restart( quit and run again) your visual studio!

Create visual studio solution template - multiple projects

I'm stuck on this tutorial for creating a multi-project visual studio template. I'm specifically stuck on this line:
Select the files and folders to include in your template, right-click the selection, click Send To, and then click Compressed (zipped) Folder. The files and folders are compressed into a .zip file.
I did the following steps:
Create 2 projects. (MyProj.Web and MyProj.Service)
Reference MyProj.Service in MyProj.Web.
Export both. They are now in a .zip file.
What do I do from here?
My intentions are: Make solution folders where some dlls will be (DI, unit testing frameworks, etc). Have these dlls referenced. Reference projects in other projects. Rename part of the projects. For eg. the ability to replace {MyProj}.Service with NewName.Service
The other parts includes making the .vstemplate xml file and placing the zip in the ProjectTemplates.
Per the article:
Put the .zip template file in the Visual Studio project template
directory. By default, this directory is \My Documents\Visual Studio
2010\Templates\ProjectTemplates\
The Visual Studio template will then be available from File > New Project. If making a template for a single item, place it in the \ItemTemplates folder instead to make it available from the Add New Item context menu in Solution Explorer.

Resources