This project is read-only.

Installation steps

  • run setup which will install files to directory $(MSBuildExtensionsPath)\DeployWebLib\
    • for x86 enviroment, path will be c:\Program Files\MSBuild\DeployWebLib\
    • for x64 enviroment, path will be c:\Program Files (x86)\MSBuild\DeployWebLib\
  • in this folder, you can find file DeployWebLib.targets
    • subfolder called Ext contains 3rd party tools used by msbuild file
  • setup also copy project template to path {MyDocuments}\Visual Studio 2008\Templates\ProjectTemplates\Visual C#
    • now you can use project template called "WebControlsLibrary" within Visual Studio Add New Project Wizard (in tree Visual C#, listbox 'My Templates')

Usage notes

Using new project type called WebControlsLibrary will change content of .csproj file and add following lines to execute custom msbuild target file:
<Import Project="$(MSBuildExtensionsPath)\DeployWebLib\DeployWebLib.targets" />
<Target Name="AfterBuild" DependsOnTargets="ModuleDeploy" />
  • after the project library is builded, then module deploy task is executed which does the "merging magic" and builds out new library with the same name as current libary but to different folder called Modules within solution directory
  • this new library contains all classes which you have in library, but also adds merged data under namepsace _ASP and ASP which contains metadata for web user controls and/or pages
  • now you can free to create and design your user controls within library, which you can later use in other web projects
  • important thing is that you must reference DLL builded out using DeployWebLib msbuild target, and which you can locate it in folder Modules within solution direcotry, because only this file contains all metadata informations about yours user controls

Important Note

When you unloads project and than gets back with Reload project command you get this "security warning...":
DeployWebLib.png
  • Just select *Load project normally" and uncheck option "Ask me for every project in this solution"

Loading user control at runtime:
Old way of loading user control at runtime into place holder:
Control control = Page.LoadControl("~/Controls/UserControl1.ascx");
ph.Controls.Add(control);
But when you try to build web library the old way (without DeployWebLib target) and use other way to load user control from DLL:
Type typeOfControl = typeof(UserControl1);
Control control = Page.LoadControl(typeOfControl, null);
ph.Controls.Add(control);
Which will be executed without error, but no user control is added to placeholder.
This is because library does NOT contains ANY metadata about user controls within library.
But also when you use code above up to library builded new way with DeployWebLib you got same issue - NO user control is loaded.
This is because merging user control using DeployWebLib puts users controls metadata under special namespace folder called ASP (internal data are also under _ASP - but we dont care about this).
  • Reason:
    • User control class still exist in library, but contains only code part, not ascx/aspx part
    • You must call special extension method (created for this scenario on .net clr type Type - GetWebEmbeddControlType) to load the correct Type of user control from ASP namespace:
var registerUserType = typeof(RegisterUser).GetWebEmbeddControlType();
// and now load page control and add it to controls collection of place holder
Control control = Page.LoadControl(registerUserType, null);
ph.Controls.Add(control);
  • Now when you run this code, user control is loaded into place holder and it works like an normal "ascx" file loaded from disk.

Demo Example documentation

See more info about this in Demo Example documentation.

Last edited Nov 16, 2009 at 7:25 PM by terrorix, version 6

Comments

No comments yet.