Building LightSwitch Extensions Part 1

Microsoft shipped version 1.0 of Visual Studio
in July as both a stand-alone product and an add-on to the
full version of Visual
. While the product is targeted at quickly creating useful
line-of-business applications, it’s quite capable of doing much more. The key
to rapid development centers around accessing data and presenting it to the
user on template-driven screens.

Extending the functionality of Visual Studio, LightSwitch is not as
difficult as it sounds. Out of the box the product comes with a minimal number
of supported extensions including money and phone number data types and a
picture and text custom layout control. Extensions fall into four basic
categories consisting of business type, data source, theme and shell. While you
only need the Visual Studio LightSwitch product to build applications, you’ll
need a full copy of Visual Studio 2010 with SP1 to build extensions.


You must be running Visual Studio
2010 with Service Pack 1
(SP1) installed before you can install any of
the additions needed for developing LightSwitch extensions. Next, you must
install the Visual
Studio 2010 SP1 SDK
. Then you’ll need to install Visual Studio
LightSwitch 2011
followed by the Visual Studio
LightSwitch 2011 Extensibility Toolkit

The final requirement will be to install Silverlight 4.0 for developers if
you haven’t already done so. Visual Studio will let you know if this isn’t
installed the first time you try to create a LightSwitch extension project.
It’s important to point out at this point that Silverlight plays a key role in
the development of custom controls. That means you’ll need to get familiar with
if you plan on building any Silverlight controls.

The Basics

Once you have everything installed you should see several new options on the
Visual Studio New Project menu as shown in Figure 1. Language choices include C#
After you have created a new extension project you should see a number of
entries in the Solution explorer as shown in Figure 2. This is essentially the
same list of projects you’ll see with a new LightSwitch solution with the
addition of Lspkg and Vsix. We’ll take a look at these two new items next.

Visual Studio New Project menu
Figure 1: Visual Studio New Project menu

Visual Studio Solution Explorer
Figure 2: Visual Studio Solution Explorer

LsPkg is short for LightSwitch Packaging project and contains information
about all the moving parts contained in your application. This is the project
you will add new items to from the list of available extension types (Figure 3
shows the list). To do this, simply right-click on this project and then select
Add New Item. Choosing to add a new data source will create a template file
with the code as shown in Figure 4. Choosing to add a new control will add a
number of new things to your project as shown in Figure 5. Now all you have to
do is add the code to make your new extension do what you need. We’ll cover
that in a future article.

Add New Item - LightSwitchExtension2.LsPkg
Figure 3: Add New Item – LightSwitchExtension2.LsPkg

Add a new data source
Figure 4: Add a new data source

Add a new control
Figure 5: Add a new control

The VSIX project is where the actual Visual Studio Extension will be built.
Once you have your new extension created you must distribute it as a VSIX file
for others to install. It’s essentially the same format used for any Visual
Studio extension.


Microsoft has done a decent job of providing tutorial information to get you
started developing your own extensions. You’ll find them in the MSDN LightSwitch Developer
under the Extending LightSwitch heading. A quick Google search will
turn up lots of additional resources as well. Many commercial vendors such as
DevExpress, Infragistics, Rssbus, and Telerik are starting to release
LightSwitch-specific versions of their custom controls.

There’s also a collection of user-contributed extensions and links to
commercial offerings on the Visual Studio Gallery
site. Use the search box to look for LightSwitch-specific extensions. You can
take the LightSwitch product out for a spin with the free trial version
available on the main LightSwitch
site. You’ll need a full-blown version of Visual Studio if you’re itching to
get started developing your own extensions. You might as well go ahead and get
an MSDN subscription so you can have access to both along with a whole host of
other Microsoft products.

Next time we’ll take a deep dive on actually developing a few extensions.

More by Author

Must Read