Tag Archives: Visual Studio 2010

Debugging CRM web resources without ever deploying them

UPDATE: The steps explained below don’t work with CRM 2013.  However, Scott has a blog post which shows you how to get it working again:

http://develop1.net/public/post/Fiddler2-The-tool-that-gives-you-Superpowers-Part-2.aspx

One of my last posts was sharing how I use Visual Studio to debug CRM web resources:

http://blogs.msdn.com/b/devkeydet/archive/2013/06/19/eureka-f5-debugging-of-crm-javascript-web-resources.aspx

This approach was one of those discoveries that makes us developer types get a little excited because it allows us to do something we do repeatedly in a much more efficient fashion.  I just came across another one of those EUREKA moments thanks to Scott Durow (@scottdurow) and some his promising new http://www.sparklexrm.com project. 

BTW, Scott’s the man behind Ribbon Workbench for Dynamics CRM.  It’s the best Ribbon editor out there in my opinion.  I digress…

I was reading through http://www.sparklexrm.com/s/Tutorials/SetUpNewProject.html and discovered a little gift from Scott at the end of the walkthrough.  Steps 9-14 explain how to use www.fiddler2.com to let you debug changes to web resources without ever having to deploy them to Dynamics CRM.  How?  Steps 9-14 explain it.

Combine this with my post on F5 debugging from Visual Studio and you nearly have web resource developer productivity nirvana.  I just tried combining the two approaches.  It works beautifully!  I was able to make changes to JavaScript, hit F5, debug right in Visual Studio, and repeat over and over again.  I did this all without ever having to deploy the JavaScript file to the server.  Because of it, I was able to iterate on my changes in a fraction of the time CRM developer typically spend.  Try it yourself!

@devkeydet

WEBCAST FOLLOW UP: Unit Testing Dynamics CRM Plugin and JavaScript code

Thanks to everyone who attended my presentation on Unit Testing Dynamics CRM Plugin and JavaScript code hosted by http://www.xrmvirtual.com/.  I’ll update this post when the recording is available.  However, the webcast was basically a shortened walkthrough of these two posts:

http://blogs.msdn.com/b/devkeydet/archive/2012/10/31/how-i-develop-and-unit-test-crm-2011-plugins.aspx

http://blogs.msdn.com/b/devkeydet/archive/2012/11/27/unit-testing-crm-2011-javascript-web-resources.aspx

…with some additional “what is and why unit testing” commentary.

Here’s the presentation:

@devkeydet

CRM, Accessibility, and 508

I’ve spent many a time having accessibility and 508 compliance discussions with customers and partners over the years working at Microsoft and focusing on various web based technologies.  In fact, it’s hard to believe I recorded this video over seven years ago:

https://channel9.msdn.com/Blogs/keydet/Creating-an-Accessible-Web-Page

As it relates to Dynamics CRM 2011, whether your overall implementation is accessible is a combination of:

  1. Whether the HTML the CRM product produces is accessible
  2. Whether your web resources are accessible
  3. Whether any custom ASP.NET, etc. pages integrated into the CRM UI (say through iFrames) are accessible

For #1, the CRM product team produces a document called a Voluntary Product Accessibility Template (VPAT).  Ben does a good job explaining the relationship to 508 compliance and VPATs here so I won’t go into it.  As Ben mentions, all of Microsoft’s VPATs are available at:

http://www.microsoft.com/government/en-us/products/section508/Pages/default.aspx

The most recent VPAT for Dynamics CRM 2011 (as of writing this) is: Microsoft Dynamics CRM December 2012 Service Update VPAT.  For #2, the CRM 2011 SDK has a section called Create Accessible Web Resources to help you.  This section is chock full of resources and links to external resources on accessibility.  What surprised me is that it doesn’t talk about Visual Studio’s built in accessibility checker which is covered in Visual Studio’s Accessibility in Visual Studio and ASP.NET documentation.  For #3, you need to similarly understand how to make sure those pages are accessible.  Visual Studio’s ASP.NET Controls and Accessibility should prove helpful.  In fact, the 7+ year old video I recorded that I link to earlier shows both the accessibility checker and general ASP.NET accessibility techniques in action.  Hopefully this post is helpful to those of you who are going to be in the business of ensuring your CRM implementation is accessible.  Here are a few other resources you will want to review which are not linked from the other resources in this post as far as I can tell:

http://webaim.org/

http://www.section508.gov/

Now that the latest CRM Online update is complete and UR12 is out, Dynamics CRM 2011 is now cross browser capable.  Therefore, you can now use the popular WAVE Toolbar Firefox addon to check accessibility of your customizations.  Yea, I know, a Microsoft guy recommending Firefox.  I don’t know of a better free tool that allows you to check accessibility of web pages without uploading html or point the tools servers at your web site.  The latter kind of validator won’t work for CRM deployments because of authentication.  Plus, you should be testing all your customizations in Firefox and Chrome anyway.

@devkeydet

Visual Studio, ALM & Dynamics CRM

UPDATE (17MAY2013): There’s now a whitepaper on the topic as well: ALM for Microsoft Dynamics CRM 2011: CRM Solution Lifecycle Management

NOTE: I’ve included related links to both Visual Studio 2010 & 2012 content.  Even thought the Developer Toolkit for Microsoft Dynamics CRM now supports Visual Studio 2012, I recognized not everyone has upgraded.  I do my best to differentiate VS2010 & VS2012 where necessary.  You can always switch to the right version of the documentation if you click the wrong link:

image

I’ve had a recurring discussion lately about using Visual Studio’s Application Lifecycle Management (ALM) tools:

http://msdn.microsoft.com/en-us/library/fda2bad5(v=vs.100).aspx (Visual Studio 2010)

http://msdn.microsoft.com/en-us/library/fda2bad5(v=vs.110).aspx (Visual Studio 2012)

…including Team Foundation Server (TFS), when developing Dynamics CRM 2011 solutions.  CRM Development is a little different than traditional software development because you write much less code than building something from scratch (in some cases no code).  However, I am a firm believer that CRM projects should be RUN just like a custom dev project.  Especially enterprise projects.  Enter Visual Studio ALM…

Many think of Visual Studio and Team Foundation Server as just for developers, but if you read through the links above, you will learn there’s much more than what you might think.  However, leveraging all of these capabilities in the context of a Dynamics CRM project isn’t really spelled out anywhere.  This post is an attempt to be a contextualized table of contents of public information to help people understand how the two worlds collide.  The 2010 version of the ALM starter page breaks Visual Studio ALM down to:

  • Plan and track your project. Enact processes and monitor their quality to help your team turn customer requirements into working software.

  • Design functionality, either on top of existing assets or from scratch, by using architectural diagrams to communicate critical information about your team’s software.

  • Write, unit test, debug, analyze, and profile your application by using tools that are integrated with the rest of the application lifecycle so that your team can understand how your progress contributes to the project. Use version control to manage your source code and other files.

  • Build your application by using an integrated build system so that your team can ensure that quality gates have been met and verify that requirements have been fulfilled in each build.

  • Test your application by running manual or automated tests, including performance and stress tests. Manage testing systematically so that your team knows the software quality on any given day.

  • Deploy into virtual environments to enable more sophisticated development and testing.

I’m going to use this as the structure of my mapping to CRM.  There’s nothing really specific to Plan and track with CRM.  However, I find it surprising how few people are using the Visual Studio planning and tracking tools (work item / bug tracking, reports, etc.) on CRM projects.  Definitely review the material to learn about how TFS can help you run your projects.  The next area where Visual Studio can really help is Write, unit test, debug, analyze, and profile.  With CRM, you “develop” with two primary tools: The CRM Web UI and Visual Studio (usually with the Developer Toolkit for Microsoft Dynamics CRM):

CRM UI to edit Visual Studio / Other to edit
Entities, Attributes, Relationships
Forms & Views
Charts, Dashboards, Basic Reports
Workflows & Dialogs
Templates
Security Roles & Field Security
HTML, JavaScript, CSS
XML / XSL
Images
Sitemap & Ribbon
Plugin & Workflow code
Companion ASP.NET code

 

In may cases, you also use community tools to do things like site map and ribbon customizations.  However, in the end, those tools ultimately modify the CRM system (usually by modifying XML files).  So the writing code part should be pretty self explanatory through the CRM SDK (online / download) and developer toolkit.  The first place where you need to sprinkle in additional CRM context/nuance is unit testing.  My posts here should help you:

How I develop and unit test CRM 2011 plugins (make sure to use Fakes instead of Moles if you are using Visual Studio 2012)

Unit testing CRM 2011 JavaScript web resources

Debugging is another place where people get a little tripped up.  There are multiple approaches to debugging both plugins and web resources.  Debug a Plug-In explains how to attach Visual Studio to the right process to debug plug-in and workflow code.  Of course this requires you to attach to the CRM Server.  In cases where you can’t, you can profile code execution on the server, save it locally and debug by replaying captured state.  See Analyze Plug-in Performance for more details.  The CRM SDK has a section on Debugging JavaScript in Microsoft Dynamics CRM.  If you are developing your CRM code using a Test Driven Development (TDD) approach with unit testing, then you might come to the same conclusion I came to in my Developing CRM 2011 customizations without a local server post.  My personal opinion is that unit testing makes the debugging process much better and improves overall developer productivity.  So what about using version control to manage your source code and other files?  Remember that most of your non-code customizations can be exported as part of CRM solution export as XML files.  I blogged about how to integrate the SolutionPackager tool from the CRM SDK into Visual Studio to source control non-code customizations to help you get started.

The SolutionPackager tool lays the foundation to enable you to build your application on a build server.  However, most people who go to the extent of using a build server also want more advanced build automation such as deploying to a test server or virtual environment.  While there’s a whitepaper called Deploying Microsoft Dynamics CRM 2011 and CRM Online Solutions from Development through Test and Production Environments which covers some of the nuances of such automation, it leaves much of the work to you to implement.  Thankfully, ADXStudio has built the Adxstudio ALM Toolkit which greatly decreases the time it will take a team to reach this level of automation.  Shan McCarthur delivered a fairly comprehensive webcast on team development that brings all the core topics together.  While the webcast is relatively ALM tool agnostic, it’s not a far leap to understand how use Visual Studio ALM tools after watching and having gone through the material in this post.

What about functional testing?  Unit testing is great and all, but not everyone is bought into TDD and unit testing.  I always tell people that unit testing doesn’t replace functional testing.  However, it usually DOES result in less bugs found during functional testing.  The Creating and Managing Tests section of the Visual Studio ALM documentation does a good job of navigating you through the different kind of functional testing it supports.  The little gem that I don’t think enough CRM projects are utilizing is Testing the User Interface with Automated UI Tests (aka Coded UI).  Dynamics CRM 2011 is one of the many Supported Configurations and Platforms for Coded UI Tests and Action Recordings.

And performance testing?  Performance testing is absolutely critical for any large scale software solution.  Not enough people do it.  The end result is usually finding issues in production when you go live.  UGH!  Performance testing can prevent lots of heartache.  The Visual Studio has tools to help you in your Testing Application Performance and Stress.  A compliment to Visual Studio is the Performance Toolkit for Microsoft Dynamics CRM 2011 which is just a set of guidance + additional tools which show you how to Visual Studio Stress Testing Tools with CRM.  Stress testing with CRM is a pretty specialized skill.  While I’ve given you pointers to the tools to do it yourself, you might want to consider the Microsoft Dynamics Benchmark offered by the Dynamics Premier Field Engineering (PFE) team at Microsoft.

@devkeydet

CRM Solution Manager keeps getting better

Full disclosure, I received a free license from the authors of the tool.  However, I do believe it’s definitely worth the license fee.

I’ve blogged previously about reasons for my fondness of the www.crmsolutionmanager.com addin to Visual Studio for Dynamics CRM 2011 development.  Well they’ve recently introduced some new features that I think make it an even more compelling alternative to the Developer Toolkit for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online.

@devkeydet

Improving the performance of multiple Inserts, Updates, and Deletes via the CRM 2011 Organization Service

UPDATE: Now that Polaris/UR12 are out, the new bulk API is available.  Check out Sonoma Partners blog post on a simple benchmark of the improvements.  Now you can Combine the ne bulk API with client side parallelism to achieve even better performance.  I’ll put that on my ever growing “to blog” list.  However, if you followed this post, then you should be able to figure it out yourself. 

UPDATE: Removed explicitly creating a ConnectionStringSettings object by calling CrmConnection.Parse().

If you are writing any .NET code that interacts with the Organization Service, any insert/update/delete performed happens one at a time, even if you call OrganizationServiceContext.SaveChanges().  This is a perfect candidate to improve performance using the Task Parallel Library.  Here’s a little code snippet to get you started:

var conn = CrmConnection.Parse("Url=https://YOURORG.crm.dynamics.com;Username=YOURUSERNAME;Password=YOURPASSWORD");
var ctx = new MyDataContext(new OrganizationService(conn));
 
var query = from a in ctx.AccountSet
            select new Account
            {                
                Id = a.Id,
                Name = a.Name,
                Address1_City = a.Address1_City
            };
 
var tasks = new List<System.Threading.Tasks.Task>();
var accounts = query.ToList();
 
foreach (var account in accounts)
{    
    // Parallelize each update until BulkAPI is released in UR12
    var task = System.Threading.Tasks.Task.Factory.StartNew(()=>{        
        ctx.Detach(account);
 
        account.Name += " - UPDATED";                
        account.Address1_City += " - UPDATED";    
 
        var newctx = new MyDataContext(new OrganizationService(conn));        
        newctx.Attach(account);
        newctx.UpdateObject(account);        
        newctx.SaveChanges();
    });
}
 
//Wait for all the updates executing in parallel to complete.
System.Threading.Tasks.Task.WaitAll(tasks.ToArray());

On my quad core laptop.  The serial version of this code takes a little over 5 seconds.   In comparison, the code above executes in less than a second.

@devkeydet

Getting started with the CRM 2011 Windows Store app sample

UPDATE (18APR2013): Updated AuthenticateAsync() extension method to handle both IFD and CRM Online authentication.  Now, the code in HelloCRM will work regardless of whether you point it to an IFD or CRM Online Organization Service.  All you have to do is pass in the appropriate username/password combo to AuthenticateAsync().  Quick link to updated code: http://sdrv.ms/Qy0Wcv.

UPDATE (12MAR2013): Found another issue with my helper extension methods around when I was detaching the event handler.  Uploaded a zip file with the improved helper methods.

UPDATE: There was a bug in my extension methods.  I wasn’t detaching the event handlers after the event had been handled.  This caused issues with subsequent calls to the Async extensions methods.  I’ve fixed the code to detach the event handlers appropriately.

I’ve blogged about a hackish, but workable approach to building an Windows Store app here and here.  However, as I mentioned in the post, if you like it use it.  If not wait until there’s an official SDK sample.  Well, in early November, the CRM time published the official SDK sample:

http://blogs.msdn.com/b/crm/archive/2012/11/02/building-clients-for-windows-phone-and-windows-8-rt.aspx

The feedback I’ve gotten from a few folks who’ve looked at the official sample is:

  • “It’s not exactly the easiest sample to follow.  Can you give me a hello world example?”
  • “I can’t use crmsvcutil.exe generated code with the sample.”
  • “I have to use Event-based Asynchronous Pattern (EAP)?  It’s Windows 8!  Everyone expects async / await capable APIs.”

The goal of this post is to address these common responses with:

  • A simplified hello world example to get you started
  • How to use crmsvcutil.exe generated entities so you have early bound / strongly typed / data binding friendly classes
  • Starter extension method examples which wrap the EAP nature of the sample API and give you async / await friendly methods

 

 

You can grab the hello world example from the video here:

http://sdrv.ms/Qy0Wcv

In the video, I make reference to Erik Pool’s wonderful tool to control what gets generated from crmsvcutil.exe:

http://erikpool.blogspot.com/2011/03/filtering-generated-entities-with.html

The inspiration for the Extension methods comes from this Stack Overflow post:

http://stackoverflow.com/questions/12853445/convert-event-based-pattern-to-async-ctp-pattern

I blogged about using LINQPad to create FetchXml here:

http://blogs.msdn.com/b/devkeydet/archive/2012/04/22/getting-fetchxml-from-linqpad.aspx

@devkeydet

Developing CRM 2011 customizations without a local server

I’ve spent a lot of time over the last year applying my general application development experience to the world of Dynamics CRM customizations (aka XRM).  Often, I take part in conversations that go something like “Why is X harder to do when customizing Dynamics CRM compared to general .NET web development?”  I usually respond with “Well how exactly are you doing X?”  After finding out, my next response is usually along the lines of “Well have you thought about doing it like Y instead?  That’s a much more productive way.”  The next response is usually “Well, why isn’t that documented somewhere?”  My answer is usually “Well, it’s really just applying proven development practices to CRM.”  These conversations are usually the catalyst for many of my blog posts.  Sorry for the contextual tangent.  Back to the point of this post.

When I first started focusing on Dynamics CRM about a year ago, I was adamant about developing in an isolated VM which included the CRM Server installed (if at all possible).  The main reasons were:

  • Developing in isolation from others
  • Ability to attach to the necessary processes to debug plugins and workflow activities
  • Speed of deploying web resources / plugins to the server through the developer toolkit (no network latency slowing the process down)
  • Ability to create/delete CRM organizations on the fly for prototyping, starting from a clean environment, etc.

I still believe this is the best setup for CRM developers.  However, I also recognize that many folks don’t have the hardware resources to give each of their developers a machine that can handle such an environment. 

I’ve been asked quite a few times “Why isn’t there a lightweight dev server for CRM like there is for ASP.NET?”  That’s a much longer discussion.  It’s the same basic answer as why SharePoint and other server products with APIs don’t have one.  However, what I think people really want is to be productive developing without having to install the full fledged server locally.  As I was building out the walkthroughs for my posts on unit testing:

… I had a bit of “DUH” or “AHA” moment.  If you practice Test Driven Development (TDD) using these approaches, go with the one org per developer approach on a remote server, and sprinkle in effective team development approaches enabled through Solution Packager, then you can become quite productive developing without a local server.  Your remote server becomes your integration testing environment. 

I still prefer doing all of the above in a local, isolated VM environment.  There’s nobody else playing in my sandboxSmile.  However, when you don’t have the luxury of installing CRM locally, I’ve learned that the combination of these approaches against a remote server can be a surprisingly productive setup.  I’ve been forcing myself to use this approach lately, even in a local VM.  It does take some getting used to.  I call this the “up front setup/config tax.”  Once you’ve paid the tax and get into a rhythm doing things this way, I think you will appreciate the efficiencies gained.  Try it out.  Let me know your thoughts.

@devkeydet

Unit testing CRM 2011 JavaScript web resources

UPDATE: Fixed the video resolution issue.  Higher resolution (720p) version is available.

After writing my post on unit testing plugins, I’ve been asked a few times about how to do the same for Dynamics CRM 2011 JavaScript web resources.  While I knew it could be done, truth be told, I had never done any significant JavaScript unit test using Visual Studio other than unit testing Script# code using MSTest (the default unit testing framework in Visual Studio).  Sure, I had played around with QUnit.  However, QUnit is one of those JavaScript testing frameworks which requires tests to run within a browser.  What I wanted was an approach which met the following criteria:

  • Integrate with MSTest so:
    • I have one test dashboard for both my plugin & JavaScript unit tests
    • I get as much of the TFS integration goodness I can get
      • Gated check-ins
      • Running tests on a build server
      • Etc.
  • Write and debug my code without having to constantly deploy to a CRM server to test and iterate on my code
  • Mock things like Xrm.Page, web service calls, interaction with the HTML DOM, etc.
  • Integrate with the Developer Toolkit
  • Run tests OUTSIDE of the context of a browser

So I scoured the internet, tried a bunch of things I came across, and finally landed on approach which combines lessons learned from the following resources:

While the catalyst for this video was to demonstrate JavaScript unit testing in the context of Dynamics CRM 2011, the approach can be applied to any scenario where you are using JavaScript and some additional API (SharePoint, standard web app, etc.).

Just like with my post on unit testing plugins, it is not my goal here to convince you that you should embrace unit testing.  It’s for those of you who have already bought into the value of unit testing, want to apply it to JavaScript web resource development, and do it in a way that meets my stated criteria above.  In the video, I assume you understand concepts like mocks, fakes, etc. 

You can grab the finished example I show in the walkthrough here:

http://sdrv.ms/StxcgU

Hope this helps those of you who have been as eager as I have to unit test JavaScript web resources.

@devkeydet