Bryant Likes's Blog

It's all about WebData

Recent Posts

Tags

News


  • Windows Live Alerts
    View Bryant Likes's profile on LinkedIn

    Me

    The posts on this weblog are provided "as is" with no warranties and confer no rights. The opinions expressed herin are the personal opinions of the individual authors and do not represent the views of Avanade in any way.

Community

Email Notifications

Archives

Automating WebPart Library Builds

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.

Comments

bryantlikes said:

Hi Brian,

Sounds like a neat tool. Sounds a bit simmilar to this one though http://www.waka.dk/Blog/PermaLink,guid,f9377888-85ac-4a23-b0a6-8391e97c495c.aspx

But with command line options.

Will you be making the tool available? I am sure we all we appreciate it.
I will even be able to refine my build process (http://www.geekswithblogs.net/tariq/archive/2004/01/08/1170.aspx) with it ;)

- Tariq
# February 22, 2005 2:37 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)