Feed Icon  

Contact

  • Bryant Likes
  • Send mail to the author(s) E-mail
  • twitter
  • View Bryant Likes's profile on LinkedIn
  • del.icio.us
Get Microsoft Silverlight
by clicking "Install Microsoft Silverlight" you accept the
Silverlight license agreement

Hosting By

Hot Topics

Tags

Open Source Projects

Archives

Ads

Automating WebPart Library Builds

Posted in SharePoint | ASP.Net/Web Services at Friday, February 18, 2005 3:55 AM Pacific Standard Time

Back when I was working on version 1.1 of the RsWebParts I setup a build script for my project which I think is pretty useful. It automates the process of creating DWP files and packaging the project using the WP Packager tool.

The first step in automating this process was to create a console application that I called the DwpGenerator. I did this because I grew tired of forgetting to change version numbers or trying to look up the public key token of an assembly. The DwpGenerator is a simple application that takes a web part assembly and generates a dwp file for each web part it finds in the assembly. It uses .Net Attributes to gather other information such as title and description. These are set in the web part assembly. For example, here is the RsExplorer web part's class declaration:

[DefaultProperty("ServerUrl"),
 ToolboxData("<{0}:RsExplorer runat=server>"),
 XmlRoot(Namespace="Bml.RsWebParts"),
 Description("Explore a Reporting Services Server."),
 Title("RS Explorer"),
 PartImage("_WPR_/ReportExplorer.gif")]
public class RsExplorer : RsBasePart, IRowProvider, 
IPostBackEventHandler, IDesignTimeHtmlProvider 
{
    ....
}

The DwpGenerator picks up the title and description from these attributes. The generator doesn't look for any specific class of attributes, so you can create your own. It only looks at the name of the attribute to determine if it should use it. So for the above web part the dwp that gets generated looks like:


<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
  <Title>RS ExplorerTitle>
  <Description>Explore a Reporting Services Server.Description>
  <Assembly>Bml.RsWebParts, Version=1.2.0.0,Culture=neutral, 
PublicKeyToken=4fafef280eaa1b9cAssembly>
  <TypeName>Bml.RsWebParts.RsExplorerTypeName>
  <PartImageLarge>_WPR_/ReportExplorer.gifPartImageLarge>
WebPart>

The next part of the automation involves the wppackager tool. This tool is great for generating an installer program for web parts. The only drawback is that you need to copy every file into the same folder for the tool to work. However, it is pretty easy to automate copying files. So here is my post build event command line process for the Bml.RsWebParts:

c:\temp\DwpGenerator.exe "$(TargetPath)" "$(ProjectDir)"
copy "$(ProjectDir)\manifest.xml" "$(TargetDir)"
copy "$(ProjectDir)\*.dwp" "$(TargetDir)"
copy "$(ProjectDir)\images\*.gif" "$(TargetDir)"
copy "$(ProjectDir)\xsl\*.xsl" "$(TargetDir)"
copy "$(ProjectDir)\scripts\*.js" "$(TargetDir)"
"c:\program files\wppackager\wppackager.exe" "$(ProjectDir)\wppackager.xml"
del  "$(TargetDir)\*.xml"
del  "$(TargetDir)\*.gif"
del  "$(TargetDir)\*.dwp"
del  "$(TargetDir)\*.xsl"
del  "$(TargetDir)\*.js"

That is all there is to it. Now I can make changes to my project and when I build it everything is updated.

Monday, February 21, 2005 6:37:00 PM (Pacific Standard Time, UTC-08:00)
Hi Brian,
<br>
<br>Sounds like a neat tool. Sounds a bit simmilar to this one though <a target="_new" href="http://www.waka.dk/Blog/PermaLink,guid,f9377888-85ac-4a23-b0a6-8391e97c495c.aspx">http://www.waka.dk/Blog/PermaLink,guid,f9377888-85ac-4a23-b0a6-8391e97c495c.aspx</a>
<br>
<br>But with command line options.
<br>
<br>Will you be making the tool available? I am sure we all we appreciate it.
<br>I will even be able to refine my build process (<a target="_new" href="http://www.geekswithblogs.net/tariq/archive/2004/01/08/1170.aspx">http://www.geekswithblogs.net/tariq/archive/2004/01/08/1170.aspx</a>) with it ;)
<br>
<br>- Tariq
Tuesday, December 23, 2008 8:02:38 PM (Pacific Standard Time, UTC-08:00)
Excellent Article.

Thanks for the hard work and the valuable information for sharing with us.
Comments are closed.