Skip to main content

Wouter

Go Search
Home
Contact Me
  

 ‭(Hidden)‬ Admin Links

Code and walkthrough for my Visual Studio Extensibility session

A few days ago I presented a session on Visual Studio Extensibility. In this post you will find a short walkthrough for this session.

During the course of the following walkthrough you will learn to setup a basic project extension, explorer node type and deployment step.

Get the download for this walkthrough here.

Solution Setup

You begin with creating a new VSIX project. VSIX is a new packaging model for Visual Studio extensions. Note that you need to target the .NET 4.0 Framework.

I named my project VirtualConferencePackage

Delete the code file since you'll not be coding in this project.

Next, add a new project to the solution. Target the .NET 4.0 Framework. I named this project VirtualConferenceExtensions since it will contain the main extension code.

For the VirtualConferenceExtension project, add references to the following items. You can find them all on the .NET tab. All these assemblies are part of the public APIs of the SharePoint project model.

  • Microsoft.VisualStudio.SharePoint
  • Microsoft.VisualStudio.SharePoint.Explorer.Extensions
  • Microsoft.VisualStudio.SharePoint.Utilities

Next, add a reference to yet another DLL on the .NET tab. This time you are including the Managed Extensibility Framework, or MEF. This is basically a new .NET plugin system which allows easy application composition.

  • System.ComponentModel.Composition.

There is one more project to add to the solution. This project will contain the code that integrates with SharePoint. You need a separate assembly because SharePoint is .NET 3.5 / 64 bit, and Visual Studio hosts .NET 4.0 / 32 bit.

Be sure to set the .NET Framework to version 3.5. I named this project VirtualConferenceCommands since the integration with SharePoint is command-based.

Add references to the following assembly belonging to the project model.

  • Microsoft.VisualStudio.SharePoint.Commands

Also add a reference to the Microsoft.SharePoint DLL. Currently you'll still need to use the Browse tab to locate it in the SharePoint installation folder, but that'll probably be resolved before RTM! (I hope)

Next, I removed the code files, and the references I don't need, like System.Data. This leaves the following shell. At this point in time you may want to right-click the VSIX project you added first and set it as the startup project.

Configuring packaging

Open the source.extension.vsixmanifest file and behold the manifest editor. Change some of the metadata to your liking.

You will need to include both the extension and the command assembly. Hit Add Content to add the extension DLL. The extension DLL needs to be packaged as a MEF component since it will use MEF for extending the SharePoint project system.

Next do the same for the command assembly. This assembly is unknown to Visual Studio, and hence is a Custom Extension Type. Use the identifier SharePoint.Commands.v4 so that the SharePoint project model can find it.

A simple project extension

The first demo for the day is a project extension. Add a new code file 'ProjectExtension' to the extensions project. Make this class implement the ISharePointProjectExtension interface. Export the class using the MEF Export attribute. This allows the SharePoint project model to load it.

[Export(typeof(ISharePointProjectExtension))]
class ProjectExtension
    : ISharePointProjectExtension
{
    public void Initialize(ISharePointProjectService projectService)
    {
    }
}
The ISharePointProjectService you receive can be seen as a reference to the entire Visual Studio solution. Meaning you get events such as ProjectAdded, and you can enumerate over all projects. You can also hook into events that have a particular project as the context such as ProjectMenuItemsRequested and ProjectPropertiesRequested. The first is called to show menu items on the project context menu in the Solution Explorer. The second is called to get objects to show in the Properties window. First hook into the event.

projectService.ProjectMenuItemsRequested += projectService_ProjectMenuItemsRequested;

Then you implement this method. You get to add menu items to the 'Action' area and the 'Add' area of the context menu. Super easy to do. Add the menu item using only text, and hook the click event. As a demo, here's one that calls IIS Reset.

void projectService_ProjectMenuItemsRequested(
    object sender, SharePointProjectMenuItemsRequestedEventArgs e)
{
    IMenuItem item = e.ActionMenuItems.Add("Reset IIS");
    item.Click +=
        delegate
        {
            string path = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.System),
                "iisreset.exe");
            Process.Start(
                new ProcessStartInfo
                {
                    FileName = path
                });
        };
}
Now say that you want to provide the option to either do an IIS Reset or an application pool recycle. You could expose a custom setting on the Properties window. To do this, hook into the ProjectPropertiesRequested event and go for it!

projectService.ProjectPropertiesRequested += projectService_ProjectPropertiesRequested;

You will first need to have a custom 'Properties' class to define the project properties you want to expose. This can be an internal class. Here's a simple one that contains a custom ResetMode property. This is an two-value enumeration with the values Recylce or Reset. As you can see you will need to use a backing store that survives quiting VIsual Studio. In this case I will use the user properties file.

class ProjectProperties
{
    public IDictionary<stringstring> Properties { getinternal set; }

    [Category("Virtual Conference")]
    public ResetMode ResetMode 
    {
        get
        {
            return Properties.ContainsKey("ResetMode") ?
                (ResetMode)Enum.Parse(typeof(ResetMode), Properties["ResetMode"]) :
                ResetMode.Recycle;
        }
        set { Properties["ResetMode"] = value.ToString(); }
    }
}
And now in the method hooked to the event, you add an instance of this object to the collection of items to show in the Properties window.

void projectService_ProjectPropertiesRequested(
    object sender, SharePointProjectPropertiesRequestedEventArgs e)
{
    e.PropertySources.Add(new ProjectProperties 
    { 
        Properties = e.Project.ProjectUserFileData 
    });
}
You should now be able to press F5 and see the results of your efforts. Create a new SharePoint project and check out the menu item and custom property.

That's it for now. Have fun building more extensions.

Again: get the download for this walkthrough here.

Hope it helps!

 

 

 

 

 

Yet another tool to build SharePoint solutions?

So,

Here goes….

Usually I develop SharePoint 2007 solutions using Visual Studio 2008 and a set of MSBuild targets. In the train yesterday I thought I'd automate it a bit more. I call my tool YEAST (Yet Another SharePoint Tool)…. Yes. YEAST.

Here's my logo. You may recognize it as Word Art, but really, it is not. I have spent many hours designing this.


What is YEAST?

The goal for YEAST is to take away my manual steps with MS Build, and to be integrated into Visual Studio. I also want it to be non-intrusive so that the YEAST based project will still compile on machines that don't have it installed, basically, because there is nothing to install.

YEAST consists of three parts.

The first component is a simple DDF generator. This generator takes in a SharePoint solution manifest and generates a nicely formatted DDF file. The solution manifest itself is maintained by you as part of the solution. Personally I like the control over the manifest. It's a vital artifact. Your project must follow the SharePoint installation folder hierarchy. It expects the RootFiles folder to be the root of the hierarchy within your project. The generator itself is about 200 lines of code, for which you can add the source to your solution. And since it does nothing more than you could do manually, you are not locking into my vendorism.

The second part is a project template which is just a normal class library but with a bunch of preconfigured MS Build targets that can deploy / retract / upgrade / xcopy. This allows you to perform all the common actions on a project. The project does not override the default Build target so that you can still compile on any machine with Visual Studio and SharePoint installed. All tasks are performed using normal calls to STSADM, meaning no extra install for this. You can even package and deploy language packs using a single command. Nice!

To allow you to easily call an MS Build target you can register an external tool in Visual Studio (using Tools à External Tools), to call into MS Build. The fun detail of this is that you can actually add the external tool to the project context menu, so you do get an integrated experience.

What so different about YEAST?

The difference with WSP Builder is that the manifest is not generated. The manifest is a real artifact which I'd rather maintain myself. It only takes a few seconds anyway. The DDF is the big issue in terms of developer productivity and YEAST generates that during each build. I also notice that WSP Builder puts some unwanted content into the manifest, like Feature Resources and Printing Permissions.

The difference with STSDEV is that this approach does not use Build Configurations (Debug, Release, etc) as a way to provide buttons. Instead you get real buttons on the project context menu for deploy, retract, upgrade and XCopy.

Why are you polluting the packaging tools space with more packaging tools?

I always use MSBuild, but that is painfully non-integrated. I've built YEAST (all 200 lines of code) to better integrate the approach I commonly follow in enterprise development. Just thought I'd share my new approach.

Where do I get it?

CodePlex obviously! I chose http://yeast.codeplex.com to be the home of this tool.

How do I set up my environment to be YEAST ready?

I'll dedicate another blog post on that! It's not difficult at all!

Hope it helps!

SharePoint 2010 - The local-only collaboration tool?
Here's a funny SharePoint 2010 observation.
 
Install SharePoint 2010. You know, the business collaboration platform for the Enterprise and the Web.
 
Create your team site, and examine the picture that is on that site.
 
For your comfort, here it is.
 
 
 
People, collaborating... Cool! Looking all enabled and such.
 
Around a single laptop.... !
 
WTF? haha.
 
Now I am wondering. Is that the Enterprise part? Because it sure ain't web!
 
:)

Happy SharePointing!  
Announcement: CKS: Development Tools Edition is born
Recently my little pet project SharePoint Dev Tools saw the light of day when I hit the rounded Publish button on CodePlex. Born out of interest in the Visual Studio extensibiltiy model for SharePoint projects and a hefty addiction to writing tools, especially for the platform that I invest so much of my time in.
 
Well, it was awesome to learn that there are more likeminded people out there also creating amazing tools on top of Visual Studio 2010. Check out Waldek with his Imtech extensions, and be sure to visit the  SPVSX project with Matt, Wesley and Todd.
 
So, in order not to polute the community with a large amount of small tools, we decided that it would be for the good of us developers if we create a small amount of tools with large amounts of features. #CKSDEV is the result! The merger of all the existing tools into one neat package.
 
The Community Kit for SharePoint - Development Tools Edition is building on the popular set of CKS tools. This time focusing on the development experience and not on the solutions themselves (e.g. we don't deploy anything in production). We hope to provide the one toolkit that we'll all use and benefit from. Thus ensuring a streamlined development experience wherever there is SharePoint (and there is lots of SharePoint right? :) We are planning an alpha release early February. Be sure to check it out as soon as it is there!
 
Update: Some new topics for the SPC 2010 Post Conf

It seems there is some overlap between some of the talks on the SPC 2010 event next week and the post conference I'll be delivering there. So, in order to allow you to learn about as many facets of SharePoint 2010 as possible I thought I'd swap out two of the topics I was going to cover.

So, instead of Office Service Apps and BCS, I'll cover two topics that everyone needs. The first new topic might just revolve around a big announcement to be made tomorrow. The next one is a personal favorite: building Ribbon components. Got some amazing demos lines up! Hope to see you there! Note that you'll be able to go to the original topics during the regular event, so you will definitely not miss out (I hear there is going to be some recording done…!)

Upcoming Conferences

The next few months will be filled with many great conferences to look forward to. Some SharePoint specific and others more general, but I think for all of them SharePoint 2010 will take the main stage!

First is the SharePoint Connections event in Amsterdam on the 18th and 19th of January. For more information visit the conference website at http://www.devconnections.com/SPEurope/. I'll be giving a few SharePoint development sessions and also a full day post conference! Exciting stuff, mash-ups with Excel and Visio, advanced Silverlight integration and more! Got an awesome demo going with Bing Map integration into List Forms. F5-baby!

Next up in February is a SharePoint 2010 Virtual Conference. Dates are still to be decided, so I'll keep you up to date! No VR Goggles required, but who knows, it might provide you with an unprecedented experience to use them anyway!

After the virtual conference is another physical one, namely the SharePoint and Office Conference in Italy. This conference is held the 9th of March through the 11th in Milan. Find more information on the conference website at http://www.sharepointconference.it. I will be giving three development sessions on a variety of topics. Workflow for one!

 

 

March is month for the DevDays in the Netherlands, which this year is joined with the Belgian tech days. Lots of fun topics at this event, of course broader in scope than SharePoint 2010, but hey, any developer should be a SharePoint developer right? For more information visit either http://www.devdays.nl/ or http://www.microsoft.com/belux/techdays/2010/, or perhaps…both! J

Next is April with a non-European event. I'll be visiting Montreal for the SharePoint Summit 2010. Visit the following website for more information: http://sharepointsummit2010.com/overview.htm.

Hope to meet you at any, if not all, of these events!

Happy coding!

SharePoint Dev Tools Beta 1 Released!

I was one of the lucky few that had a very early opportunity to meet with the product team that builds the SharePoint project system in Visual Studio 2010. One can only be impressed with the work that was done to enable SharePoint developers more than any other tool currently in use. I was happy to learn that the SharePoint development environment was built around the core concept of extensibility. Meaning you are able to bridge any gaps and tune the environment to your needs. Great stuff!

Since then I have been spending my evenings building the toolset that will further enable SharePoint developers world-wide. With added features to discover SharePoint content using the new SharePoint Explorer, new and exciting templates that make it easy to author solutions and many enhancements to the deployment of your solution into your testing environment.

May I present the SharePoint Dev Tools. Version beta 1 is ready for your approval. And I believe it will exceed your expectation! Some of the exciting features that you find within this advanced toolset are summed up below. You can go over to the project site and download the beta.

One of the first areas that has been extended is deployment. Out of the box Visual Studio 2010 is capable of retracting / redeploying your solution packages. The DevTools provide X-Copy deployment and solution upgrades on top of that. Along with many other deployment steps you have the tools you need to lower the round-trip time for small changes in your codebase. Go to the site and check out the video!

Next are some of the very exciting templates that you can use. One that I am particularly happy with is the Sandboxed Visual Web Part. This template allows you full visual design of a Web Part, while allowing it to be deployed into the solution sandbox (which does not allow ASCX files to be deployed). With SharePoint Dev Tools you can, and in a totally supported way! Also don't forget the Linq To SharePoint integrated template. Just change one XML file and get your proxies regenerated immediately. No need to leave your comfort zone. Think of it as an Office Business Application for SharePoint Developers, and SDBA J.

Finally there are numerous enhancements to the Visual Studio environment. For instance, you can find the SharePoint tab on the Add Reference dialog. Prime Visual Studio real-estate! Here's a screenshot:

As you can understand there is way too much to talk about for this single blog post. So much more good stuff to build! For now, please download and let me know anything that you find should be added. Or even better, join up with the project and add features yourself. I intend for this project to be the only toolset that SharePoint developers install outside of Visual Studio 2010. You can help make it just that!

Hope it helps!

 

 

 

Managing your SharePoint Solution store

Typically after doing a training class my solution store is a true disaster area. It's best to board it up, cover it with a pile of dirt and restart from scratch by paving over my machine. Ok, I reinstall a backup. I do not really bury my laptop under tons of dirt (perhaps that would be fun when the laptop goes out of date).

Typically my solution store resembles this nightmare, but then counting up to SharePointProject6.1223

In SharePoint 2007 I would typically do X-Copy based installation, meaning it's hard to clean up after yourself. In Visual Studio 2010 you only install solution packages, which can be retracted, returning your SharePoint dev install into a state of tranquility. It is however a big pain to manually retract / remove solutions. There is this thing called PowerShell which seemingly allows you to do this in a more easy way. I present version 0.1 of my "clean up after yourself" script. Perhaps not quite perfect yet since I only spent five minutes on debugging it J

$spAdminServiceName = "SPAdminV4"
Stop-Service -Name $spAdminServiceName
$deployedSolutions = Get-SPSolution | Where-Object {$_.Deployed -eq $true}
if($deployedSolutions)
{
    foreach($solution in $deployedSolutions)
    {
        if($solution.ContainsWebApplicationResource)
        {
            $solution | Uninstall-SPSolution -AllWebApplications -Confirm:$false
        }
        else
        {
            $solution | Uninstall-SPSolution -Confirm:$false
        }
    }
}
Start-SPAdminJob
Get-SPSolution | Remove-SPSolution -Confirm:$false
Start-Service -Name $spAdminServiceName

 

Save this out to a .ps1 file and run it. Afterwards your solution store is nice and empty again, ready for another day's training.


Hope it helps to bring some tranquility to your SharePoint dev box!

Feature: Developer Dashboard Manager

Sample Code: http://blogs.code-counsel.net/Wouter/Downloads/Dashboard Manager - Source.zip
Installable Feature: http://blogs.code-counsel.net/Wouter/Downloads/Dashboard Manager - WSP.zip

One feature every developer loves, or will love, is the Developer Dashboard. It's obvious right? Earlier SharePoint developers were in the dark as to what is causing slow pages and now you can gain valuable insights out of the tracing information provided in the dash.

To enable the Developer Dashboard you can write a bit of code:

SPDeveloperDashboardSettings settings = SPWebService.ContentService.DeveloperDashboardSettings;

settings.DisplayLevel = SPDeveloperDashboardLevel.On;

settings.Update();

 

You do this either in a console app (hella-lame), in PowerShell (semi-lame and a bit ITPro-ish), or….

You create a feature of course!

Find the Developer Dashboard Manager feature attached. First it adds some navigation items to Central Admin under both the landing page and the System Settings page.

The navigation leads to a page where you can manage the enabled state of the Developer Dashboard.

Hope it helps! Personally I use this feature as a quick overview of the new Visual Studio 2010 tools.

SharePoint Dev Tools - Sandboxed Visual Web Part Teaser
More developer goodies. Release time is near! This time I'd like to show the Sandboxed Visual Web Part. This template allows you to create web parts using visual designers while still retaining your ability to deploy your solution into the site collection solution gallery. Good stuff!
 
View the video on the following page
 
 
Don't forget to check out the first video on the SP Metal Item Template!
 
1 - 10 Next

 Projects

Databinding toolkit for Word 2007Use SHIFT+ENTER to open the menu (new window).
Open XML Activities for Windows Workflow FoundationUse SHIFT+ENTER to open the menu (new window).
Package ExplorerUse SHIFT+ENTER to open the menu (new window).
Windows SharePoint Services 3 Workflow DesignersUse SHIFT+ENTER to open the menu (new window).
Word 2007 Source ViewUse SHIFT+ENTER to open the menu (new window).