Expert Texture Home Contact me About Subscribe Digipede Connect on LinkedIn rwandering on Twitter rwandering on FriendFeed

rwandering.net

The blogged wandering of Robert W. Anderson

Merging ASP.NET 2.0 without aspnet_merge

Apparently Microsoft will be releasing a tool called aspnet_merge that will help resolve some of the shortcomings in the deployment options when precompiling ASP.NET 2.0 projects. This is supposed to be available on November 7th, but I don’t feel like I want to wait. Thanks to the DotNetNuke guys for working with Microsoft on this. I’m really surprised that it got to be so late in Microsoft’s development cycle before they figured out this was a problem.

I thought I’d try ILMerge to do it. Searching to see if someone else had, I came across this post by K. Scott Allen: Using MSBuild and ILMerge to Package User Controls For Reuse. Similar problem, different goal.

I went ahead and did this with nant as that was the quickest way for me to get this into my release process. I admit this is all a kind of a hack. First, I search for all App_Web*.dll files. Then I replace all references in the aspx and ascx files with a reference to my new merged dll. Finally, I use ILMerge to merge to the new dll. Note that I’m not merging everything, just the assemblies that have seemingly random names.

The nant code follows. It is a bit clumsy, but it works.

  <property name="ProjectPath" value="${BuildRoot}\PrecompiledWeb\${ProjectName}" />
  <property name="ilmergePath" value="c:\Program Files\Microsoft\ILMerge\ILMerge.exe" />
  <property name="mergedAssemblyName" value="ControlMerged.dll" />
  <target name="deploy">
    <property name="assemblyFiles" value="" />
    <foreach item="File" property="assembly">
      <in>
        <items basedir="${ProjectPath}\bin">
          <include name="App_Web*.dll" />
        </items>
      </in>
      <do>
        <property name="assemblyFiles" value="${assemblyFiles} ${assembly}" />
        <copy todir="${ProjectPath}/tmpBak" overwrite="true">
          <fileset basedir="${ProjectPath}">
            <include name="**\*.as?x" />
            <exclude name="tmpBak\**" />
          </fileset>
          <filterchain>
            <replacestring from="${path::get-file-name-without-extension(assembly)}" 
                           to="${path::get-file-name-without-extension(mergedAssemblyName)}" />
          </filterchain>
        </copy>
        <copy todir="${ProjectPath}" overwrite="true">
          <fileset basedir="${ProjectPath}/tmpBak">
            <include name="**\*.as?x" />
          </fileset>
        </copy>
      </do>
    </foreach>
    <exec program="${ilmergePath}" commandline="/out:${mergedAssemblyName} ${assemblyFiles}" workingdir="${ProjectPath}/bin"/>

Tags: , ,

    Trackback

No comments yet

Sorry, the comment form is closed at this time.