Pogo69's Blog

April 15, 2011

CRM 2011 – Visual Studio Plugin Templates

Filed under: C#, CRM — Tags: , , , , — pogo69 [Pat Janes] @ 15:27

I really liked the Visual Studio templates that shipped with the CRM 4.0 SDK.  They provide a handy blank workspace in which to create a new plugin or custom workflow activity without having to remember each time how to code them from scratch.

I was rather dismayed to find no trace of similar templates in the CRM 2011 SDK.  So I created my own.  I’m offering them here so that other developers can benefit from the same.  Let me know if you discover any issues; I’ll update the source and refresh the links.

The Templates

Custom Workflow Activity

http://www.mediafire.com/?5ai40s51qjqv24o

Plugin

http://www.mediafire.com/?ip9avvd5wnc87f0

How to Install

Simply copy the zip files (do not extract them – just copy the archives directly) into the folder:

<My Documents>\Visual Studio 2010\Templates\ProjectTemplates\Visual C#\CRM 2011\

I called my new folder ‘CRM 2011’ – you can call it what you wish.  The name you choose will appear as a new category when you create a new Visual Studio project:

Automatically Referencing the SDK Libraries

I had an interesting query (see below) from Gonzalo Ruiz about whether we could have the template include references to the SDK libraries.  If you’ve used these templates, you will have noticed that there are comments at the top of each about which libraries require referencing before your SDK object references will resolve and compile.

The answer is yes… and no.

Why I Can’t Put the References in the Generic Template

The CRM SDK libraries are not installed in the GAC on a developer’s workstation.  Nor are they installed to a well known location.  The template cannot therefore know to what path the library references should point.  I’ll include the plugin template’s project file so that you can see what the existing assembly references look like:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.50727</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{BCC9080F-3C19-4D40-B487-1E874F6D2BD1}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>$safeprojectname$</RootNamespace>
    <AssemblyName>$safeprojectname$</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>PluginKey.snk</AssemblyOriginatorKeyFile>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core">
      <RequiredTargetFramework>4.0</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Data.Services" />
    <Reference Include="System.Data.Services.Client" />
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.ServiceModel" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="plugin.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="PluginKey.snk" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

For example, the LINQ library is referenced using:

    <Reference Include="System.Xml.Linq" />

because it is installed in the GAC and therefore requires no path information.

What You Can Do to Make Hard-Coded References Work for You and Your Team

  1. Install the latest version of the SDK in a well-known location – preferably a network location so that the entire development team can reliably load the same projects
  2. Update the template to include “hint” information in a reference to each required CRM SDK assembly

Plugin Template

I’ll step through it for the Plugin template – you can figure out from there what to do to the Custom Workflow Assembly template.

Expand Plugin.zip

In the resultant folder, you will find a file named ‘CRM 2011 Plug-in Test Template.csproj’ – edit this file in notepad (or similar).  The contents are exactly as I have posted above – an XML file that tells Visual Studio which resources to load for your project.

Edit ‘CRM 2011 Plug-in Test Template.csproj’ to Add SDK Assembly References

Add two references in the <ItemGroup> node that contains the existing assembly references.  It should look like the following when you’re done:

  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core">
      <RequiredTargetFramework>4.0</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Data.Services" />
    <Reference Include="System.Data.Services.Client" />
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.ServiceModel" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
    <Reference Include="microsoft.xrm.client">
      <HintPath>\\<server>\<share>\<path to sdk>\bin\microsoft.xrm.client.dll</HintPath>
    </Reference>
    <Reference Include="microsoft.xrm.sdk">
      <HintPath>\\<server>\<share>\<path to sdk>\bin\microsoft.xrm.sdk.dll</HintPath>
    </Reference>
  </ItemGroup>

Much the same as the other references, but with “hints” to the location(s).

Package and Deploy

  1. Save the project file.
  2. Zip up the contents of the entire folder structure you extracted into an archive named Plugin.zip.
  3. Overwrite the existing Plugin.zip

Your new Plugin projects should now contain resolved references to CRM SDK libraries.

 

 

 

 

 

 

 

 

 

 

 

 

 

Advertisements

17 Comments »

  1. Brilliant stuff. I had made a template myself but I had included class library for linq queries until I found today that you can’t use them with CRM 2011 online.
    could you please publish an RSS feed to this blog, I want to subscribe but cant find it.
    Cheers
    Hosk
    http://crmbusiness.wordpress.com/

    Comment by Hosk — April 16, 2011 @ 00:26

    • Glad you like it, Ben.

      And there’s now an RSS feed icon in the upper right of the blog. Maybe that’ll inspire me to post more!?

      Comment by pogo69 — April 16, 2011 @ 07:21

  2. great artwork dear. earlier i thoughtof creating one for myself but you saved a lot of time.
    thanks.

    Comment by vishal — April 16, 2011 @ 20:26

  3. […] he has published some Visual Studio templates for CRM 2011 and you can read about it here […]

    Pingback by CRM 2011 – Visual Studio Plugin Templates « Hosk's Dynamic CRM 2011 Blog — April 28, 2011 @ 07:43

  4. I like this, thanks for sharing! Is there a way to have the template automatically add the Microsoft.Xrm.Sdk.dll to the project?

    Comment by Gonzalo — June 3, 2011 @ 01:02

    • You’re most welcome, Gonzalo.

      With respect to the Xrm library references; I’d love to be able to do so, but given that they aren’t installed into the GAC, but referenced from the SDK (which will be in a different location on every developer’s machine), I doubt it.

      You could do it for your organisation and/or development team, by hosting the SDK in a well known network location. Then edit the template .csproj file to reference the fully qualified network path. Actually, I might give that a go, then post results; it would be really handy – despite the comment hints I added to the top of the source files, it is a bit tedious to have to perform the same additional steps each time.

      Comment by pogo69 — June 3, 2011 @ 05:23

  5. […] now it’s time to create our Microsoft CRM plugin using Visual Studio 2010; I’m using Pogo69’s CRM 2011 – Visual Studio Plugin Templates to easy my plugin developments so you might as well use it, it’s […]

    Pingback by How-to series: Send SMS messages from CRM 2011 (part 3) - BugsOli's xRM blog - CRM Technical Blogs - Microsoft Dynamics Community — June 7, 2011 @ 19:52

  6. […] Visual Studio Plugin Templates […]

    Pingback by Excellent Microsoft Dynamics CRM 2011 Development Resources « Hosk's Dynamic CRM 2011 Blog — August 15, 2011 @ 10:46

  7. […] Visual Studio Plugin Templates […]

    Pingback by Microsoft Dynamics CRM 2011 Development Resources | Dynamic Blog — November 21, 2011 @ 18:29

  8. very nice stuff…Thanks

    Comment by snehadeore — November 25, 2011 @ 20:23

  9. Hello ,

    How Do I Use the Filestream Data Type to Store BLOB Data in CRM 2011

    Thanks
    Sneha

    Comment by snehadeore — December 6, 2011 @ 20:43

  10. […] Visual Studio Plugin Templates […]

    Pingback by Microsoft Dynamics CRM 2011 Development Resources « Srikanth Reddy's Blog — February 1, 2012 @ 19:11

  11. The CRM 2011 SDK now ships with the CRM Developer Toolkit that has a Solution and Project Templates:

    http://msdn.microsoft.com/en-us/library/hh372957.aspx

    Comment by T Jason Mayo — March 10, 2012 @ 03:42

    • Thanks Jason. I was aware, but it is a good idea to let others who come to my abhorrently neglected blog, know.

      Comment by pogo69 — March 12, 2012 @ 12:08

  12. […] 4 to CRM 2011 JavaScript Converter Tool OData Query Designer JavaScript SOAP Request Formatter Visual Studio Plugin Templates NuGet plugin package CRM 2011 Metadata Browser Entity Metadata Browser Ribbon Browser CRM […]

    Pingback by Microsoft Dynamics CRM — September 7, 2012 @ 08:23

  13. […] it’s time to create our Microsoft CRM plugin using Visual Studio 2010; I’m using Pogo69’s CRM 2011 – Visual Studio Plugin Templates to easy my plugin developments so you might as well use it, it’s […]

    Pingback by MS CRM 2011 : Sending SMS (How to Send SMS using MS CRM 2011) | Nikhil Kumar Das — September 11, 2012 @ 22:01


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: