justnbusiness

Thursday, April 12, 2007

Visual Studio Plugin Breakthrough

Well I've been working on a visual studio plugin for NBusiness here since v1 was released. I've encountered a few small bugs and have a host of changes I hope to make to the compiler for v2 but I've mainly just been focused on getting this plugin "working". There is a seemingly infinte list of things I need to fix still but I had a major breakthrough today in my progress!
I'll try to lay out what I'm hoping the plugin will do and give a few nice little screen shots of my current development environment then I'll spend a bit of time ranting about the process of creating VS plugins and I'll even try to drop a few gems of advice for anyone trying to do something similar.
First I'll give the most basic requirements I had for this plugin:
  1. I want to be able to click File->Project->Visual E#->Entity Library
  2. I want to be able to add and edit es/cs files directly to my entity library. (Also add embedded files).
  3. I want to be able to add references to my entity library project from other projects.
  4. When I click build the end result yields a .dll that other projects get by reference.
  5. I want intellisense and syntax hilighting.

Here is a snapshot of me adding an Entity Library via the File->Add New->Project menu!

Here is a snapshot of my dev environment with everything else hooked up (except intellisense and syntax hilighting):


So to get this far I basically just opened up the IronPython example that comes with the visual studio SDK and looked over every square inch of code. There were a couple minor areas of confusion that ended up turning into extreme time delays that I'll warn you about here.

For one thing beware the confusion of naming your language! I had "Visual E#" and "ESharp" and "NBusiness" here and there and nothing seemed to work right. In certain areas it expects the names to match up and if they don't then good luck figuring out what is wrong... Basically I would reccomend simply picking one name (like "ESharp") and using that everywhere. Then after things are working right start tentatively renaming things so they look pretty. That will save you enormous amounts of time.

Another extreme area of confusion was how the heck you get the .zip templates into the right location! Well I was a little lucky because I know a thing or two about MSBuild but in case you weren't aware, it turns out that it is possible to put custom MSBuild tasks manually into your project file (via notepad for example). This is what they did in IronPython and unless you're really paying attention it almost seems like magic how things end up where they do. This is also how they get the .targets file in the right location during build time.

Also, I know it seems ridiculous how Microsoft developed the bulk of their (useful) managed API for VS as plain C# files rather than compiling it for us into an Assembly but trust me, it's worth just adding the damn files to your project and building them. The sheer amount of code you would have to write is staggering, so much seemingly useless cookie cutter code... I have no idea why it isn't just an assembly you reference. But also beware that some of those project files litterally have python specific strings in them! Watch out for embedded resources being loaded by invalid paths due to namespace differences and do a vigorous "Find All" for "py". Get it all out of there!

I'm trying to look over the carnage that is my Visual Studio plugin to see if I can relay anything else useful but all I can think of to say is that if you're planning on creating a custom language for Visual Studio be sure to either have someone who already knows how to make them help you or plan about a month of hard core hacking to get the basics working. This has probably been the hardest (managed, I've seen nastier C++) code I've ever had to work with... I'm going to lose sleep just thinking about what I'll need to do to get intellisense and syntax hilighting to work!

Oh yeah I'll probably be cooking up a beta installer for this pretty soon if anyone wants to try it out. Stay tuned for new blogs or just IM me.

All bitching aside I would just like to say that having this power integrated directly into VS is pretty exciting. When I first got it to build my entity I was litterally shaking slightly afterwards. This really opens up a whole new world for this project and will hopefully bring some legitimacy to the idea of it really being viable. I definitely look forward getting this plugin out the door!

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home