Generated T4 Files Not Added to Project from Visual Studio Extension - visual-studio-2013

I am trying to generate code scaffolding for an in-house API. I created a T4 template which includes several other templates for each code file to be generated. I then wrote a Visual Studio Extension (VSIX) with a WPF form to capture user input and initiate the transforming of the T4 template. I am doing all of this in Visual Studio Professional 2013.
This is what I followed to Invoke the Text Transformation in a VS Extension
https://msdn.microsoft.com/en-us/library/gg586947%28v=vs.120%29.aspx?f=255&MSPPError=-2147217396
When testing the templates locally using Run custom tool, everything works perfectly. However, when testing the VS extension in an Experimental Instance of Visual Studio, the problem I am having is that after the transformation has been invoked [calling ITextTemplating.ProcessTemplate], the generated files are not placed into my open project. I verified that they exist in their appropriate folders in File Explorer.
I have searched high & low and can't find anything that talks about this. Any ideas?

The custom tool is using the Visual Studio API (DTE object) to add the generated files to the projects. I built something very similar and that is what I had to do. This project is a bit old but it is a great starting point for seeing how this can be done.
Basically you need to get a reference to the folder you want to add the new item to and then call AddFromFile. Also don't forget to save the project after you add all the items.

Related

How to share an SSRS Report Template across TFS?

The standard method of implementing a Reporting Services report template is to create an .RDL (report file) and place it in the Visual Studio Report Project template folder at C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\ProjectItems\ReportProject
Since this is a purely local approach, is there a way to implement a shared and source controlled template that can be used from the new item menu?
Our current solution for this issue is to store our templates in our report solution, and copy/paste them for new reports. Just wondering if there's a better alternative.
You need to create this as a .vsix extension and then share it. If you update the package and version all Visual Studio instanced that have it installed will prompt the user to update.
How to: https://blogs.msdn.microsoft.com/vsx/2014/06/10/creating-a-vsix-deployable-project-or-item-template-with-custom-wizard-support/
Although you can setup your own repo to load it from, It's much easyer to use http://marketplace.visualstudio.com for distribution.

Deploy a VSPackage to create a new project type using Setup Project

I create a new custom project type using a VSPackage project inheriting of MPF library (http://mpfproj11.codeplex.com/). As a result I obtain a .vsix but I need add this project type using a .msi. I'm using the Visual Studio 2010 Setup projet for it. In my setup project I add the content of the VS Package in the same directory where the .vsix put then, but I think Ineed to put in the registre the new type of project because when I use the setup , the project template does not come out in Visual Studio and when I give double click the file with extension of the type of new project and does not recognize it. When I look the registry after install the vsix, this was one of the things that I found diferent. I add this entries in my setup project but It's not working yet.I'm missing something else?
In the projecttemplatedir is the directory where I put the .dll of the project type, the vsixmifest and pkgdef. The project template is in [User]\Documents\Visual Studio 2013\Templates\ProjectTemplates\[Name of new Project Type]\[projecttemplate.zip]
Best Regards
PS: The project type is for VS 2013 but I'm using the VS 2010 Setup project ;)
OK, so first the "don't"s of doing this:
In general, if you are installing via MSI you shouldn't be doing anything user-specific -- no writing in HKEY_CURRENT_USER, nor writing within their Documents folder, LocalAppData, or Visual Studio folders, etc. If you see yourself writing files or registry keys in either of those places, that should be your hint that there's a better way to do what you're trying to do. For what you've shown so far, this raises more than a few red flags for me.
Second, don't ever go writing keys into 12.0_Config. That part of the hive is nothing more than a cache that's built up from other parts of the registry and on-disk .pkgdef files from extensions. It's rebuilt in any number of senarios, including installing new extensions. Any writes there you should presume will get blown away at any time. If you need to write things there you should either (a) write in HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\[version] and run devenv /setup or (2) [preferred] put your keys in a .pkgdef inside your extension which gets merged into 12.0_Config for you automatically.
Now the dos:
You said you already had a .vsix produced by the SDK: you can put project templates in there. You can then register those templates in the .vsixmanifest and those will pull in. That's far easier than mucking around with files in Documents -- that's the user's directory...don't go playing with that.
Once you have a .vsix that does most of what you need, you should simply take the files within that and install the files in a folder within C:\Program Files [(x86)]\Microsoft Visual Studio 12.0\Common7\IDE\Extensions. Even better, you might just want to WiX toolset to build your installer, since it has built-in support for installing extensions. It also has built-in support for invoking the "/setup" process if that's what you need to do as well. Visual Studio Setup projects are no longer supported in newer versions of Visual Studio, so you're better off starting with a technology that isn't already obsolete. WiX is even what we use at Microsoft to do the setup work for Visual Studio itself, so it's definitely up to the task.
Last point: almost everything when it comes to Visual Studio extensibility can be done with a VSIX directly, so presume there's a good way to do something that way before falling back to an MSI. Internally, we can register the entire C# and VB language services with just a VSIX -- they're quite powerful.
I found the answer in this link Registering Project and Item Templates. I set projecttemplatedir entry with
[User]\Documents\Visual Studio 2013\Templates\ProjectTemplates[Name of new Project Type][projecttemplate.zip] that is where i put the project template.

Is it possible to provide custom content for the VS2012 Start Page?

Visual Studio 2012 (and 2010, too) has a Start Page that has links and streamed videos. Is it possible for my package to provide content on this page, e.g., create a separate section next to Welcome/Windows 8/etc.?
I finally got a custom start page working in VS2012 - my issue was I could not install the Start Page Project Template in 2012 as the extension only installs on 2010 (which I don't have access to) and my My Documents folder is mapped to a network drive, so putting the raw XAML file in My Documents/Visual Studio 2012/Startpages didn't work as Visual Studio refused to use this "untrustworthy file".
Download the Start Page Template from here.
Rename the file to .zip and extract it.
Copy the "\Solution\CSharp\Extensibility\StartPage.zip" file to your project template folder (by default "My Documents\Visual Studio 2012\Templates\ProjectTemplates\Visual C#").
Create a new project using this template.
Follow the instructions here to upgrade from 2010 to 2012 start page.
Update the project properties target framework to 4.5.
Update the project references in the Control project by removing the Microsoft.VisualStudio.Shell.10.0 reference and adding the Microsoft.VisualStudio.Shell.11.0 and Microsoft.VisualStudio.Shell.Immutable.11.0 references.
Update the namespaces references in the xaml file by replacing the existing ones with the two below.
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.11.0"
xmlns:vsfxim="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.Immutable.11.0"
Replace the references to vsfx:VsBrushes keys to vs:EnvironmentColors keys, e.g. vsfx:VsBrushes.StartPageBackgroundKey to vs:EnvironmentColors.StartPageTabBackgroundBrushKey
In the VSIX project, make the following changes to the source.extension.vsixmanifest file (values depending on if 2010 support is desired, it is not for me):
Add an author, the default empty tag is not allowed: <Author>Ken</Author>
Change/add the visual studio support version to 11.0: <VisualStudio Version="11.0">
Change the supported runtime edition to include 4.5: <SupportedFrameworkRuntimeEdition MinVersion="4.5" MaxVersion="4.5" />
The VSIX solution should now build and spit out a VSIX file in the project bin folder. Install this and you can now choose your Start Page from the drop down list in the visual studio options.
I haven't actually developed my custom start page beyond this, but hopefully it is a helpful to people wanting to get started developing them with VS2012
EDIT: A project which includes a basic 2012 start page, custom control and can be deployed via VSIX: template
Custom Start Pages, via google:
http://msdn.microsoft.com/en-us/library/aa991992.aspx

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.

Visual Studio SDK - Handle File Save Event

I would like to run a script after files with certain extensions are saved in visual studio. I am wondering where the event handler for saving a file is located in the Visual Studio SDK API.
Can anyone point me in the right direction in terms of API documentation for visual studio extensions. I have found the Visual Studio SDK Reference but some direction or sample examples would be helpful.
I want to create partial designer files that are usually generated when the project is built (Mono for Android Project), my files will have temporary values, but are only intended to enable intellisense without building the entire project. I can run the process manually right now, but I would like to trigger the script when .xml or .axml files are saved.
It think I need to work with IVsRunningDocTableEvents.OnAfterSave method, but I'm not sure about how I get the handle on the running doc table, or how I filter the files I want to run the event for. This is my first attempt at using the Visual Studio SDK.
The event handler for saving files is:
Dte.Events.DocumentEvents.DocumentSaved
Note you need to keep a reference to Events and DocumentEvents in order for it to actually work. Here is some information on that: http://social.msdn.microsoft.com/Forums/br/vsx/thread/0857a868-e650-42ed-b9cc-2975dc46e994
Here is a link to 30 sample projects that illustrate all kinds of functionality for Visual Studio Add-Ins:
http://code.msdn.microsoft.com/Visual-Studio-2010-SDK-ddfe1372
You can find some getting started informatin here:
http://msdn.microsoft.com/en-us/vstudio/ff677564.aspx

Resources