Friday, April 29, 2011

Sitefinity bindingRedirect with RadControls

I recently began developing with the latest version of the RadControls (Q1 2011), however, my existing website was still running on Sitefinity v. 3.7 SP4 on .Net 4.0.  Of course, the latest version of the RadControls are not compatible with this released version of Sitefinity, and given that all of the Sitefinity assemblies are strong named, this would be a problem while compiling my custom web application.

Fortunately, I found this article which seemed to indicate that a bindingRedirect could be performed on the Telerik.Web.UI DLL.  http://www.sitefinity.com/devnet/forums/sitefinity-4-x/deployment/problem-with-versions-of-radcontrols.aspx

After applying these changes to my Web.config file, sure enough, Sitefinity worked in conjunction with my custom ASP.Net Web Application.

Unfortunately, that is not the end of the story.  After working with my updated Sitefinity web site, I began noticing that the performance of my Sitefinity web site had degraded severely.  In many instances, I could not even get my pages to ever render.  My browser would simply time out attempting to retrieve the pages.

After doing a significant amount of testing and research, I determined that the most likely culprit was the bindingRedirect I had put in place.

Therefore, I worked through my existing Visual Studio project to re-bind my References to the version of Telerik.Web.UI that shipped with Sitefinity v. 3.7 SP4.  After completing my changes, my uploaded the newly compiled assembly to my website and attempted to access my Sitefinity web site once again.

Voila!  My site was suddenly was able to render almost instantaneously!  Most pages were back to their normal speedy self.

So what is the moral of the story??  Stick with the versions of the RadControls that ship with Sitefinity!  If you don't, you could render your site completely unusable.

Thursday, April 28, 2011

Managing Exec Commands with Arguments in MSBuild

I recently had to write an MSBuild Exec task to run the Visual Studio 2013 Code Metrics tool from the Command Line: http://www.microsoft.com/en-us/download/details.aspx?id=41647

Unfortunately, the tool is solely managed via the Command Line and there does not appear to be any specialized  MSBuild Task for it.  Once I started digging into the syntax, I encountered a problem with passing multiple files to the command since each file needs to be passed as a separate /file: parameter as outlined in this article: http://blogs.msdn.com/b/camerons/archive/2011/01/28/code-metrics-from-the-command-line.aspx

When working with NAnt, this operation would have been relatively easy since the exec task in NAnt provides an arg parameter: http://nant.sourceforge.net/release/latest/help/tasks/exec.html

However, the MSBuild Exec task has no such arg parameter to accomplish this in just the same manner.

Fortunately, I found this blog posting which saved me a lot of grief and helped me to come with a suitable solution to run my Code Metrics via the command line so I thought I would share it with anyone else who might need it as well: http://weblogs.asp.net/lorenh/archive/2008/12/11/msbuild-trick-for-making-lt-exec-gt-calls-more-maintainable.aspx

The MSBuild trick that it utilizes leverages an ItemGroup and delimits the elements in the ItemGroup with a single blank space character ' '.  I found it extremely handy and hopefully you will too!

Sunday, April 24, 2011

My thoughts on Firefox 4

Firefox 4 was released not too long ago and I was initially hesitant to try out a new version of Firefox since that has usually broken my installed extensions in the past.

However, with the recent release of Firefox 4, nearly all of my extensions had already released updates to support Firefox 4, therefore, I decided to take the plunge and upgrade my current version.

The browser was extremely fast while loading web pages compared to the earlier version, however, over time, I started to notice the performance of my system rapidly degraded.

After taking a quick look at my memory consumption in Task Manager, I noticed that after several hours of leaving Firefox open, Firefox had consumed nearly 1.5 GB of my memory!!

A quick search on Google for "memory leak in Firefox 4" demonstrated that thousands of other users were experiencing the same exact problem:

http://support.mozilla.com/en-US/questions/669659

http://support.mozilla.com/en-US/questions/799397

So I guess I will be going back to using Google Chrome, Safari or Opera for the time being...

Assembly Binding Redirection

I recently started working with the latest version of the Telerik RadControls for ASP.Net AJAX (Q1 2011).  However, my current Sitefinity site (which is running on Sitefinity v. 3.7 SP4) still utilized a much older version of the Telerik RadControls.  Therefore, I was worried that my development would cause my Sitefinity instance to break.

Fortunately, Assembly Binding Redirection came to my rescue.  Since the Telerik.Web.UI DLL does not have any other dependencies, I could easily redirect the old version to the newer version in my Sitefinity website.

This is the code that I placed into my Sitefinity web.config file:


  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Telerik.Web.UI" publicKeyToken="121fae78165ba3d4" />
        <bindingRedirect oldVersion="2010.2.826.40" newVersion="2011.1.315.40" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Registering User Controls and Assembies in Web.config

If you have ever found yourself re-creating the same register tag in ASP.Net Web Forms over and over again, you can easily migrate this content over to the Web.config file and thereby re-use the assemblies or User Controls throughout the Web Site or Web Application.

I recently found myself utilizing the Telerik RadControls for ASP.Net AJAX and therefore had this register directive scattered across several of my ASP.Net Web Forms:

<%@ register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

In order to centralize this code, I migrate it over to Web.config in the following manner:


    <pages>
      <controls>
        <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI"/>
      </controls>
    </pages>



That is all there is to it!

Friday, April 22, 2011

Don't leave Visual Studio running too long....

If you are like most developers nowadays, you probably do a considerable amount of development inside of a virtual machine.  Odds are, you probably also suspend the virtual machine so that you can resume the virtual machine at a later point in time and begin working right where you left off.

Well, I frequently do this and therefore leave Visual Studio running for several days at a time within my virtual machine.  Over time, I noticed that the performance inside of my VM was deteriorating drastically and my memory consumption was very close to the overall memory allocated to the VM.

After a quick look at Task Manager, I noticed that the biggest memory culprit was Visual Studio.  It was consuming nearly 500 MB of my memory using just a single instance of the IDE and a single solution!

So what was the quick fix??

Simply shut down Visual Studio and start it up back again.  After starting Visual Studio back up, memory consumption went down to a mere 150 MB!  Whew....

Monday, April 18, 2011

Sitefinity 4.1 released!

Sitefinity 4.1 was just released today.  This release brings back features that were previously in Sitefinity 3.7 but missing in earlier releases of Sitefinity 4.0 such as the Lists Module and Shared Content.

You can read the release notes for all of the features and changes in Sitefinity 4.1 here: http://www.sitefinity.com/versionnotes.aspx?id=2437

Friday, April 8, 2011

Developing Sandboxed solutions

If you are familiar with the new feature available in SharePoint 2010 for Sandboxed solutions, you probably already know that one of the restrictions/limitations with using Sandboxed solutions is that they do not support Visual Web Parts.  Given that Visual Web Parts were introduced with the release of Visual Studio 2010 for SharePoint 2010, this is definitely a HUGE disappointment.

Fortunately, though, Microsoft has released a Power Tool to address this issue.  http://visualstudiogallery.msdn.microsoft.com/8e602a8c-6714-4549-9e95-f3700344b0d9/

With the release of the Visual Studio 2010 SharePoint Power Tools, you can now create a Sandboxed-compatible Visual Web Part as well as improved support for Sandboxed compilation.



Wednesday, April 6, 2011

Using Web.config transforms in ASP.Net Web Application projects

One of the interesting things about using Web.config transformations with ASP.Net Web Application projects is that the Build and Rebuild operations in Visual Studio do not automatically perform the necessary processing of the Web.config transformations. 

Instead, one actually has to use the Publish capabilities available through the ASP.Net Web Application project. 

  1. Right click on the ASP.Net Web Application project and select the menu option for Publish
  2. A Publish Web dialog should now display
  3. From the drop down list of Publish methods, select File System
  4. Specify a target location on the file system for publication
  5. Click on the Publish button to build the project and publish it to its desired target location

Monday, April 4, 2011

MSBuild IDEs and Editors

If you frequently create MSBuild Scripts, you may be interested in available IDEs and Editors for creating these MSBuild Scripts.  Amongst some of the most common editors are the following:


  1. Visual Studio with or without add-ins such as Jetbrains Resharper
  2. MSBuild Sidekick--http://attrice.info/msbuild/
  3. SharpDevelop--http://www.icsharpcode.net/OpenSource/SD/Download/
  4. MSBuild Explorer-http://www.msbuildexplorer.com/v2/Install.htm
  5. Enhanced text editors such as EditPlus, EditPad Pro, TextPad, Notepad++ etc.
Let's go through each of the options one by one:

  1. While Visual Studio offers Intellisense for MSBuild, the overall Intellisense is very poor when the schema of the file changes due to extensions such as the MSBuild Extension Pack.  In addition, there is no Intellisense for the use of properties.  This can be remedied through the use of Jetbrains Resharper, however, these is one major flaw which continues to exist in Visual Studio (which has not been resolved yet to my knowledge).  If you use MSBuild as an external tool in Visual Studio, you will encounter unexpected behaviors when passing arguments to the MSBuild file.  This is especially true if you pass several arguments to your MSBuild file.  Given this extremely problematic issue, Visual Studio is probably not a REAL viable option for working with MSBuild files.
  2. While MSBuild Sidekick offers great Intellisense support, it continues to be plagued by numerous problems while refactoring and modifying the build file.  In addition, support for MSBuild Sidekick is practically non-existent and updates to MSBuild Sidekick are few and far between.  The most recent release of MSBuild Sidekick has not been updated in nearly a year.  If you wish to have a reliable development environment for creating MSBuild scripts, MSBuild Sidekick is also not likely to be an option.
  3. SharpDevelop offers Intellisense similar to Visual Studio.  However, it is plagued by issues with passing arguments as well that cause unexpected output behaviors to result.
  4. MSBuild Explorer is a great tool for viewing your MSBuild files, but it is not meant to Edit them as you would expect from most IDEs/Editors.
  5. Finally, an enhanced text editor such as EditPlus for editing and running your build scripts.  While these enhanced text editors offer no Intellisense and little or no syntax highlighting for build script elements, it is actually one of the most reliable means of executing build scripts and happens to be my preferred choice for executing MSBuild Scripts.  Setting up and configuring the MSBuild scripts to run in the editor is extremely easy and painless and passing arguments to the MSBuild script is surprisingly reliable and robust.  In conjunction with the ability to easily capture the output of a build script, debugging and executing build scripts could not be any easier.
Therefore, if you are creating MSBuild Scripts, you are probably best off using an enhanced text editor such as EditPlus (my personally preferred text editor).  However, if you are also like me, you cannot live without Intellisense.  

So what do I do for editing and running my MSBuild scripts?  I use an external editor such as Visual Studio with Resharper, MSBuild Sidekick or SharpDevelop to perform most of the editing of the MSBuild file.  However, once I am satisfied with the changes that I have made, I will open the MSBuild file in EditPlus and then use it to actually execute and run the build script.  If your editor or IDE supports having the file open in more than one editor such as Visual Studio and SharpDevelop, you can bounce back and forth between editing and running the build script.

For those of you who are interested in also using EditPlus as your preferred MSBuild editor of choice, here are the steps to configure EditPlus to run MSBuild:

  1. From the Tools menu, select Configure User Tools
  2. Click on the Add Tool button
  3. For the Menu text, enter something such as "MSBuild"
  4. For the command, browse to the executable path of MSBuild (ex: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe)
  5. For the Argument, select File Path and Prompt.  You may need to surround the File Path with double quotes in order to ensure that spaces are appropriately escaped in the file path (e.g. "$(FilePath)" $(Prompt))
  6. Select the checkbox for "Capture output"
  7. Click OK to save your changes
  8. You will now have an option in your Tools menu for MSBuild
  9. You can now open the MSBuild file of your choice.
  10. Once the file has been opened, simply select MSBuild from your Tools menu and the MSBuild script should execute!

Where can I find the Microsoft.IdentityModel DLL?

If you use any code analysis tools such as FxCop for any of your Windows Identity Foundation assemblies, you may encounter an error message such as the following:

Project : error : CA0001 : The following error was encountered while reading module 'UserClaims': Assembly reference not resolved: Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
Project : error : CA0058 : The referenced assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be found. This assembly is required for analysis and was referenced by: '.dll'.

Since it is not readily obvious as to where this assembly is located, you must look for it in the location where you have installed the Windows Identity Foundation SDK. This will usually be in one of the following locations:

1. C:\Program Files\Reference Assemblies\Microsoft\Windows Identity Foundation\v3.5\Microsoft.IdentityModel.dll
2. C:\Program Files (x86)\Reference Assemblies\Microsoft\Windows Identity Foundation\v3.5\Microsoft.IdentityModel.dll

Once you create the appropriate directory/assembly reference for FxCop, this should resolve the error message and you should be able to continue performing your code analysis!