I'm trying to create a Visual Studio template that should appear in the New File dialog of Visual Studio 2010. No solution or project needs to be opened in order for my template to appear.
So far I know how to place my template in the Add New Item dialog, but can't find info on how to place it in New File dialog.
How can this be achieved?
Solved this by making my WiX installer put my template (a .mysql file) in a subfolder of my vsix extension folder (which goes a couple of levels below C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions) and then modifyied my .pkgdef file to add an entry to the Windows Registry that will specify that same dir as the TemplatesDir for this template:
[$RootKey$\Projects\{A2FE77E1-B743-11D0-AE1A-00A0C90FFFC3}\AddItemTemplates\TemplateDirs\{79a115c1-b133-4891-9e7b-242509dad272}\/1]
#="#105"
"Package"="{79a115c1-b133-4891-9e7b-242509dad272}"
"TemplatesDir"="$PackageFolder$\\Templates"
"SortPriority"=dword:00000020
Related
When I select menu add - new item in my project on solution explorer in Visual Studio 2015 and want select new class template i see duplication this template. How to fix it?
Besha,
I've encountered the same problem, which as I'm sure is caused by Xamarin item templates. These templates use the same definitions as native VS studio templates, e.g.:
Name Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="2245"
Thus, when VS shows you the items it ends up with duplicate names.
To fix the problem I've scanned all the template files (*.vstemplate) containing the mentioned above GUID and replaced the Name element with a text that suites my needs. E.g. for the Xamarin class I've changed it to be:
Xamarin C# class
instead of Package=".....
Note, that VS uses caching of templates and the caching is different for VS native templates and third party templates. In case of Xamarin, there will be ZIP files containing the templates and cached files with templates extracted from the archives. E.g.:
c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Xamarin\Xamarin\3.11.785.0\T\~IC\IT\Code\GeneralClass.zip\
will contain the extracted templates, while the original archive is there:
c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Xamarin\Xamarin\3.11.785.0\T\IT\Code\GeneralClass.zip
Your goal is to find the non-cached templates and change the Name element there.
Once you've found and fixed the name element, close Visual Studio, launch the command prompt as administrator, go to the
c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE folder
and run the following command:
devenv /installvstemplates
It will take a while.
Hopefully, after that you won't see duplicated class items.
Regards.
If you have Xamarin/Xamarin Studio installed (and don't use it), you can also just simply uninstall it, removing the class templates. Unity by default installs Xamarin Studio, and I simply remove it as I develop Unity projects with Visual Studio.
After creating a solution for a project, I exported it as a template. Now after exporting it automatically adds the template to my IDE and creates a ZIP file with all the project files and a .vstemplate extension file.
Now i am on another computer with visual studio and i wish to load this template and save it in the IDE, but i cannot find this option anywhere. The temporary solution i have is to open an empty web application and copy all the contents of the ZIP file not including the .vstemplate file. So my question is how can i load this template into my IDE?
When opening the vstemplate file in Visual Studio all i get is a text editor and XML data.
I am using Visual studio 2013 with Update 4.
Once you've exported your template, copy the entire ZIP file that was created to the folder C:\Users\[User Name]\Documents\Visual Studio 2013\Templates\ProjectTemplates. (You might want to use one of the provided subdirectories to keep your template organized.)
Restart Visual Studio, and then use the search bar in the New Project dialog to help you find the project template you just added.
For the record, it looks like using templates changes with VS2017. Your project template provider will have to publish via a new build mechanic, and it'll be a bit different than just dumping a .zip into a user folder:
Using Project/Item Templates:
https://learn.microsoft.com/en-us/visualstudio/extensibility/upgrading-custom-project-and-item-templates-for-visual-studio-2017
Create Project/Item Template:
https://learn.microsoft.com/en-us/visualstudio/extensibility/creating-custom-project-and-item-templates
When you right click a project in visual studio, there is an option "Open folder in File Explorer". How can the same be done from the automation model (EnvDTE) of visual studio? I thought I could use Project.FullName but that didn't work for our auto generated project files that have the .vcxproj file in a different folder than the actual .cpp files.
You can use
Project.Properties.Item("FullPath").Value
to get the correct path.
I've been modifying the VS2010 item and project templates so each time we do a "new project" or "new item" we get it created in a format that works for us. This is all working fine; if we create a new class library we get it with the references we've set up and it doesn't create the "class1.cs" file - that all works. We've made a similar change to the TestProject.zip file that lives in:
C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\ProjectTemplates\CSharp\Test\1033
Gone through the same process of zipping it back up, copying it over top of the original and refreshing the cache. However for the test project we can't stop it creating the default "unittest1.cs" file. All of our other changes to the test project are working fine but we just can't stop it creating the "unittest1.cs" file. It was never in the template or csproj file originally so I'm not sure what is creating it.
Can anyone help? What creates the default test file for the test project - I'm wondering if it's a reference to the wizard that is in the template file but have no idea what changes would be needed.
Close Visual Studio
Extract BasicUnitTest.zip from:
C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\ItemTemplates\CSharp\1033
Open BasicUnitTest.vstemplate
Remove <ProjectItem ReplaceParameters="true">UnitTest.cs</ProjectItem>
Zip BasicUnitTest.vstemplate into BasicUnitTest.zip (excluding UnitTest.cs)
Go to:
C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\ItemTemplatesCache\CSharp\1033
Delete UnitTest.cs and replace BasicUnitTest.vstemplate with your modified copy
On the next run of Visual Studio you should see the modified UnitTest
Though you can do this for every default template, I recommend creating a new template based on the BasicUnitTest.zip instead of overriding the ones shipped with Visual Studio. It's easier, safer and won't be overwritten by future service packs.
I have the source code and hope to add the file xxx.c to source files of the project created by Visual Studio 2010. However, the source file is still in the original location even if I right click add --->existing item. What is added is actually just a link. What is the simpe way to adding the item (but not a link) to the project?
Copy the source file into the same folder along with your other source/project files using Windows Explorer. Then use Add -> Existing Item.