DeployWebLib
Build and merge ASP.NET user controls into DLL library which can be later used to dynamically load these user controls from code into other web application projects. You'll no longer need to distribute aspx/ascx files within this library, it is already merged to single DLL.

Project benefits
  • Builds and mergs all user controls (including ascx, aspx, master) into one library DLL file
  • Merges also web resources attached to project as Embedded Resource
  • You no longer need to manually write <% register assembly="..." namespace="..." tagPrefix="..." stuff at the top of each web page where you want to use user control(s) from library
  • Your current code like var control = Page.LoadControl(typeOfControl, null); still works with little change (described later)
  • Strong name signed libraries also supported
  • No Post Builds events are used, just simple msbuild target injected into csproj/vbproj file
  • There is also "utils" class called DeployWebLibUtils which has extension methods to get Type of embedd user control which can be later used to load control into place holder

For installation and other documentation read Documentation page.

Do you have questions? - read FAQ page.


Creating new library (from wizard)
  • Project template is installed with project setup
  • Visual Studio >> File >> New >> Project... >> Visual C# >> Templates (My Templates) >> WebControlsLibrary
    • This will create new ASP.NET Application with modified csproj file to execute custom target ModuleDeploy on AfterBuild msbuild event automatically

Creating new library manually (without wizard)
  • Create new project with type ASP.NET Application
  • In solution explorer, gets context menu on library project node and execute Unload Project
  • Again in solution explorer, gets context menu on library project node and execute Edit ...csproj
  • Navigate to line
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
  • Add these new lines under above:
<Import Project="$(MSBuildExtensionsPath)\DeployWebLib\DeployWebLib.targets" />
<Target Name="AfterBuild" DependsOnTargets="ModuleDeploy" />
  • and results will be as this:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
<Import Project="$(MSBuildExtensionsPath)\DeployWebLib\DeployWebLib.targets" />
<Target Name="AfterBuild" DependsOnTargets="ModuleDeploy" />

Building library
  • When the library is builded within Visual Studio, after compiler builds library then our custom target ModuleDeploy is executed
  • MSBuild target ModuleDeploy makes "merginig magic" on library and makes new one (with the same name) and copies it to folder $(SOLUTIONDIR)\Modules\Debug|Release
  • In target projects, you must reference this library which contains all metadata informations about inner user controls

Signing library
  • When you want to sign library then you must use assembly attribute AssemblyKeyFile (in AssemblyInfo.cs or AssemblyInfo.vb file) to point to existing snk file
  • Edit csproj file (like described above, Unload Project and Edit, ...)
  • Navigate to this line:
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  • you can see value Microsoft.VisualBasic.targets instead when you have VB.NET project
  • and add following lines before above node:
<PropertyGroup>
  <DeployWebLibSnkFile>test.snk</DeployWebLibSnkFile>
</PropertyGroup>
  • where value of test.snk will be the name of your snk file (the file must be located within solution directory root)
  • and the results will be as this:
<PropertyGroup>
  <DeployWebLibSnkFile>test.snk</DeployWebLibSnkFile>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

Demo Example documentation
See more info about this in Demo Example documentation.

Inspiration was taken from project WebLibraryMaker http://weblibrarymaker.codeplex.com. This project has good starting point, but it does not meet my condition - simple solution!

Last edited Nov 19, 2009 at 3:26 PM by terrorix, version 25