Visual Studio extensions for code generation...what's the best way - visual-studio

So we have this tool, it's a web page, we drop a large piece of text in textBox a (say sql) run the tool
and it generates the guts of a code file in TextBoxb (say a custom view class model).
it's written in C#.
I know there are several ways to create visual studio extensions.
What I'd like to know is, what's the best/easiest/fastest way to take a c# dll that has a method that takes text in and returns text out, and turn it into a VisualStudio extenson, that takes text in and creates a files, adds it to the project and puts the text into it.
We're using Vs2008 and VS2010, and I'm okay the best soloution only work on 2010.
The closest I've found by googling so far is this:
http://visualstudiomagazine.com/articles/2009/03/01/generate-code-from-custom-file-formats.aspx
but they are for custom file formats only, i want to generate*.cs and *.rdlc and similar files.
I'd also like to be able to add methods to an existing class.
tutorial walkthroughs or better approaches woud be greatly appreicated.

VS package Builder is the answer. Lots easier.

Related

Create solution programmatically

We are automatically creating solution files (sln) and solution filters (slnf) during our CI.
Since we are not working inside Visual Studio we cannot use the DTE to work with Therefore we are using the Microsoft.Build nuget packages.
Everathing works fine, except that there is not possibility to create a solution file programmatically. It seems that I have to create it fully manually by stiching blocks of text.
Is there a better way to do this?
Since my comment helped, posting it as answer
There's MvsSln which is very powerful in editing. Also there's mine little project that has very simple API - bunch of immutable types and saveToFile function

I need a wrapper (or alternative) for Open Office XML Presentations / Powerpoints

I recently automated the creation of Powerpoint Presentations in a site I'm making. I found the Office Interop libraries extremely simple to use.
Office isn't built for this kind of thing in a webserver environment, so I'm looking at creating the Powerpoints using Open Office XML, only it's so extremely complex. For example I downloaded some code to create a blank presentation with some text. This code was around 300 lines! Using the Office Interop libraries I could do the same thing in just a couple of lines of code.
I don't have time, nor do I want to attempt to learn how to interact with the Open Office XML libraries, so I'm hoping someone has made a wrapper for the Open Office XML libraries. So far all my searching has only given me one result, Aspose Slides for .NET. This looks really hopeful, but it also looks rather expensive
Has anyone ever used a decent wrapper or alternative before?
If you are looking at automating the creation of Powerpoint presentation files, I'd say you continue with OpenXML, there's nothing better than it. Everything else is either paid or don't offer entire gamut of functionality that Open XML can provide.
If you find creating a blank file tedious, you could save an empty file somewhere and use that as a template for performing further operations on it.
The only thing close to a wrapper for PowerPoint I've found is the Open XML PowerTools. It includes a PresentationBuilder class which can be used for some specific tasks like combining slides from multiple PowerPoint documents into a new document. Although its pretty limited in its functionality you could extend the class.
However, I've come to the conclusion that there just is not a good wrapper out there so I've had to do what everybody pretty much recommends and that is using the Open XML SDK Productivity Tool and the Reflect code button.
I put together a basic presentation then Reflect Code and put that into a class. Yes its a lot of lines of code and its not the most elegant solution but it does work. Then from there I can extend or modify that class to do the specific things I need to do with each slide. The Productivity Tool is a big help for figuring out the code need to do specific things. I try to keep it simple and just do one or two things at a time, Reflect Code, then look at the code to see what it does.
You could try SoftArtisans PowerPointWriter, it has a template mode that allows you to start with an existing PowerPoint file with a few place holders, and merge your data with your presentation with as little as 5 lines of code.
Disclaimer: I work for SoftArtisans

Combing CoffeeScript output files and minimizing them in Visual Studio 2010

I am using WorkBench to create CoffeScript files in VS2010. IS there a way I can combine the compiled js files into 1 file and minimize that file to include in my view?
I had a quick look at WorkBench and found it to be much less appealing and functional than "Chirpy" which simply does the job. See http://chirpy.codeplex.com/
You might want to check this article http://mkramar.blogspot.com/2011/08/css-and-javascript-minify-and-combine.html
It is a hand-crafted solution but somehow I liked it. Could be improved more, as it uses a custom compressor but it simply concats and compresses the static files into a single one using an Html helper.

Manage often used code in Visual Studio

When programming a big project, you often need the same pieces of code in different pages. calling methods, returning references, ...
Now, I always need to open a page, and copy paste parts from that. but I'm getting tired of that. There should be a better way to list very often used code. I've read about snippets but they seem a lot of work. How do you manage that?
Snippets are not a lot of work if you use one of the handy snippet-easing extensions to Visual Studio. I happen to like this one http://visualstudiogallery.msdn.microsoft.com/B08B0375-139E-41D7-AF9B-FAEE50F68392 by Matt Manela. Once it's installed, you can right-click a block of code and make it into a snippet. You can also set up replacements just like when you do an if or for block with the built-in snippets.

How to store reusable code in Visual Studio 2010?

Is there any way I could save my block of code in Visual Studio 2010 and reuse it in my future web applications without having to "Add existing files"? Is there a feature in VS2010 that lets you globally store these blocks of code?
Thanks!
Oded pretty much covered it but I'll just reiterate here. There are three main ways you can do this depending on how much code you want to store.
For a little code just copy the code to your Toolbox:
Link
For a little code to very large blocks of code (with some intelligence for putting in values) you can use code snippets:
http://blogs.msdn.com/b/zainnab/archive/tags/tips+and+tricks/snippet/
And for lots of custom files, resources, etc... that essentially make up a new project you should use project templates:
Link
Visual Studio has a feature called code snippets, which will allow you to do exactly that.
If you want a more advanced use - for whole files, sets of files and even whole projects, use templates.

Resources