I would like to create a Visual Studio add-in to generate files.
For example, I would like to create something similar to the "Add Controller" dialog in ASP.NET MVC. This appears when you right-click on the "Controller" folder in an MVC project in Visual Studio.
However, instead of creating a controller file, I would like to create "Handler", "Request", and "Reply" classes within a folder, for my implementation of a service bus.
Creating these classes over and over again is becoming a bit of a chore, so I'd like to automate it. Is an add-in the way to go here? Do I also need to use macros and/or T4 templates?
It would be nice I could run the add-in by right-clicking on a folder and then choosing Add->Handler or something similar. I'm sure there must be a way to do something like that, but I haven't found a good resource yet through Google.
For reference, I've already looked at these web pages for info:
http://msdn.microsoft.com/en-us/vstudio/bb968855.aspx
http://msdn.microsoft.com/en-us/library/80493a3w.aspx
http://msdn.microsoft.com/en-us/library/7k3w6w59.aspx
http://www.c-sharpcorner.com/UploadFile/mgold/AddIns11292005015631AM/AddIns.aspx
http://www.codeproject.com/Articles/16515/Creating-a-Custom-Tool-to-Generate-Multiple-Files
http://www.olegsych.com/2010/03/t4-tutorial-integrating-generated-files-in-visual-studio-projects/
You can create templates which could make you nearly everithing you would like to do.
Creating Vs-Templates
Item templates
You can use your custom templates with the built in way easily and you can extract them from
...\Documents\Visual Studio 20[XY]\Templates\
folder to migrate them by copying.
Related
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.
Heyy all =)
We create a custom project template in C# following This topic to force all developers to develop uniformly, all inherit from the same class and receive the same development tools we developed in four separate DLLs and all have the App.config file with default keys etc.
We work on vs2012 or vs2013.
Since I have put the DLLs manually and attach them to come into the same project ZIP file (are that is the right way to do it or somthing like this answare?) Now if there are any changes we will have time to re-export it, etc. So we thought the installation project.
Now I'm not sure what type of project to use.
I saw that there are a number of options I will list below and I would love advice about the right, the best, and most appropriate way to do it:
Creating Extensions By Using the VSIX Project Template or other Extensibility projects
The WIX way
Using Wizards somthing like this perfect answare
One of the project from the Visual Studio Installer Projects Extension
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.
I have an example web solution that I downloaded and when I try Add New Item (e.g. page, web control, etc.), only C# is present as a language option. In other solutions I use, I see C# and VB. How can I add a new VB item?
If the current project is a C# project, you will only be able to add C# items to an existing project.
You should be able to add a new project to the solution, set it to a VB.Net project, then add VB items to it.
If you're trying to do this in a web project, you might be able to achieve this like DotNetNuke does it. Check out this post as to what files have to go in what folder (specifically App_Code) as well as changes to your web.config file. I do have to admit that other than DNN, I've never tried to do this in a regular web project.
We've been using Visual Studio 2005 Team Suite for a fairly large web project. Now, we're adding another web app into our current project...it is essentially complete, and we're just adding the entire thing as a folder into our current project. The project builds, runs...everything is fine...but this new sub-project doesn't have any kind of Intellisense that recognizes the classes we've created for this sub-project.
I think that this is probably because the code for the project isn't in the App_Code folder, and so Visual Studio doesn't know where to find it. Does that make sense? If so, what can I do about it?
As fas as I know, that's just the way it is. For some reason, the default template for web apps in 2005 does it like this. If you just need small stuff, making the classes not in App_Code implement an interface, and then just use this when you interact with your code that reside somewhere outside of App_Code (for whatever reasons).
Otherwise, you can choose to use a different project model (doesn't ship with 2005, so need to be installed seperatly, and conversion could be non-trivial):
http://webproject.scottgu.com/CSharp/Migration2/Migration2.aspx