Project description
Post-build tool transforming any WebApplication into a library containing .ascx controls. It is easy to use resulting library like a set of Custom Controls.

Project aims
  • Make it possible to create libraries containing *.ascx user controls
  • Preserve designers, code generators, etc working within the library project
  • It should be easy to use controls of the library in any other web application
  • It should be easy to use controls of the library in other such libraries
  • It should be easy to reuse controls of the library within itself
  • It should be possible to reference the library as projects
  • It should be possible to reference the library as DLL
  • It should be possible to create new library in 30 seconds
  • The library should consist of one file.
  • The solution should work for .NET v2.0, v3.0, v3.5
Now the project succeeds all points.

How to create new library
  1. Extract WebLibraryMaker to somewhere on your PC
  2. Create new WebApplication project
  3. Select project root, press F4 and select Always Start When Debugging = false
  4. Edit post-build step on property pages: Input something like "$(MSBuildProjectDirectory)\..\WebLibraryMaker\WebLibraryMaker.exe" /net " $(Framework20Dir) " /name " $(MSBuildProjectName) " /prj " $(MSBuildProjectDirectory) " /obj " $(IntermediateOutputPath) " /out " $(OutDir) " /debug $(DebugSymbols) /key " $(AssemblyOriginatorKeyFile) " where $(MSBuildProjectDirectory)\..\WebLibraryMaker\WebLibraryMaker.exe is path to your WebLibraryMaker directory
  5. Make sure you have directory mentioned in WebLibraryMaker.exe.config -> TemporaryPath setting (C:\temp\ASP.NET.Tmp by default)
  6. Build the project

How to use the library
  1. Link the library to your target project
    1. Add reference to the library project
    2. OR add reference to the library dll
  2. Use library controls like Custom Controls (control type names are equal to codebehind type names):
    1. Use <% register assembly="yourassembly" namespace="yournamespace" tagPrefix="your_prefix" %> within .ascx/.aspx files
    2. Use new yourassembly.yourcontrol within *.vb files.
Read the source example in case of any doubts

How to reuse controls within the same library
  1. Use library controls like User Controls within .ascx/.aspx files
    1. Use <% register src="~/yourpath/yourcontrol.ascx" tagPrefix="yourprefix" tagName="yourcontrol"%>
  2. Use Activator.CreateInstance() within *.vb files. It is not possible to use Control.LoadControl function. You can also use something like ControlLoader class from the source example to speed-up this operation.
    1. Use (Control)Activator.CreateInstance(Type.GetType("your_control"))
    2. OR Use ControlLoader.LoadControl<your_control>
Read the source example in case of any doubts

How to sign my library (v 0.6 only)
  1. Make sure that your post-build command contains following argument: /key " $(AssemblyOriginatorKeyFile) "
  2. Sign your library with the regular way
  3. Note: it is not possible to make project reference to signed library. Make reference to DLL file if you need.

How to make delayed sign library (v 0.6 only)
  1. Create public key, include it into the project
  2. Don't sign your library with the regular way
  3. Change "/key" argument of the post-build command to use real key name like /key " publickey.snk "
  4. Add following additional argument into the post-build command: /ds true

Principle of operation
  1. Depending of hash of the Dll: backup unchanged Dll OR restore it before processing (in order to prevent double processing of the same file)
  2. Call aspnet_compiler of .NET 2.0
  3. Gather names of newly created Dlls
  4. Create "interface" Dll containing classes inherited from ASP.XX. These classes have names similiar to grandparents' ones.
  5. Load special unmanaged resources from Dlls created by aspnet_compiler
  6. Merge all these Dlls into one file (interface Dll Dlls created by aspnet_compiler initial Dll) using ILMerge tool
  7. Write special unmanaged resource into resulting Dll
  8. Overwrite Dll files within output and intermediate folders
  9. Calculate hash code of the Dll

Known problems
  • You can see "Could not load type strange type name from assembly assemble name" error in runtime. It occures if you try to use members of an user control outside of the control. I.e. you can't create public properties/methods within your user controls. It is problem of the IlMerge tool. I can't fix it. But you can use following workaround: Create a base class for your user control and place all public members into the base class. See LibraryB.ControlC of the example.
  • It is impossible to create project references to signed libraries. DLL references are available only. It occures because the tool replaces output library and new library has different public key.

Last edited Feb 13, 2009 at 10:30 PM by Zuber, version 10