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.
- 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
How to use the library
- Extract WebLibraryMaker to somewhere on your PC
- Create new WebApplication project
- Select project root, press F4 and select Always Start When Debugging = false
- 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
- Make sure you have directory mentioned in WebLibraryMaker.exe.config -> TemporaryPath setting (C:\temp\ASP.NET.Tmp by default)
- Build the project
- Link the library to your target project
- Add reference to the library project
- OR add reference to the library dll
- Use library controls like Custom Controls (control type names are equal to codebehind type names):
- Use <% register assembly="yourassembly" namespace="yournamespace" tagPrefix="your_prefix" %> within
- Use new yourassembly.yourcontrol within *.vb files.
Read the source example in case of any doubts
How to reuse controls within the same library
- Use library controls like User Controls within .ascx/.aspx files
- Use <% register src="~/yourpath/yourcontrol.ascx" tagPrefix="yourprefix" tagName="yourcontrol"%>
- 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.
- Use (Control)Activator.CreateInstance(Type.GetType("your_control"))
- OR Use ControlLoader.LoadControl<your_control>
Read the source example in case of any doubts
How to sign my library (v 0.6 only)
How to make delayed sign library (v 0.6 only)
- Make sure that your post-build command contains following argument: /key " $(AssemblyOriginatorKeyFile) "
- Sign your library with the regular way
- Note: it is not possible to make project reference to signed library. Make reference to DLL file if you need.
Principle of operation
- Create public key, include it into the project
- Don't sign your library with the regular way
- Change "/key" argument of the post-build command to use real key name like /key " publickey.snk "
- Add following additional argument into the post-build command: /ds true
- Depending of hash of the Dll: backup unchanged Dll OR restore it before processing (in order to prevent double processing of the same file)
- Call aspnet_compiler of .NET 2.0
- Gather names of newly created Dlls
- Create "interface" Dll containing classes inherited from ASP.XX. These classes have names similiar to grandparents' ones.
- Load special unmanaged resources from Dlls created by aspnet_compiler
- Merge all these Dlls into one file (interface Dll Dlls created by aspnet_compiler
initial Dll) using
- Write special unmanaged resource into resulting Dll
- Overwrite Dll files within output and intermediate folders
- Calculate hash code of the Dll
- 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.