Index: System.Web.UI/TemplateParser.cs =================================================================== --- System.Web.UI/TemplateParser.cs (revision 68532) +++ System.Web.UI/TemplateParser.cs (working copy) @@ -30,6 +30,7 @@ using System.CodeDom.Compiler; using System.Collections; +using System.Globalization; using System.IO; using System.Reflection; using System.Security.Permissions; @@ -67,6 +68,7 @@ string oc_header, oc_custom, oc_param, oc_controls; bool oc_shared; OutputCacheLocation oc_location; + CultureInfo invariantCulture = CultureInfo.InvariantCulture; #if NET_2_0 string src; string partialClassName; @@ -77,6 +79,9 @@ internal TemplateParser () { imports = new ArrayList (); +#if NET_2_0 + AddNamespaces (imports); +#else imports.Add ("System"); imports.Add ("System.Collections"); imports.Add ("System.Collections.Specialized"); @@ -85,12 +90,12 @@ imports.Add ("System.Text.RegularExpressions"); imports.Add ("System.Web"); imports.Add ("System.Web.Caching"); - imports.Add ("System.Resources"); // should perhaps be conditional on App_Global/LocalResources existence? imports.Add ("System.Web.Security"); imports.Add ("System.Web.SessionState"); imports.Add ("System.Web.UI"); imports.Add ("System.Web.UI.WebControls"); imports.Add ("System.Web.UI.HtmlControls"); +#endif assemblies = new ArrayList (); #if NET_2_0 @@ -116,7 +121,7 @@ language = CompilationConfig.DefaultLanguage; } - + internal void AddApplicationAssembly () { string location = Context.ApplicationInstance.AssemblyLocation; @@ -127,6 +132,78 @@ protected abstract Type CompileIntoType (); +#if NET_2_0 + void AddNamespaces (ArrayList imports) + { + if (BuildManager.HaveResources) + imports.Add ("System.Resources"); + + PagesSection pages = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection; + if (pages == null) + return; + + NamespaceCollection namespaces = pages.Namespaces; + if (namespaces == null || namespaces.Count == 0) + return; + + foreach (NamespaceInfo nsi in namespaces) + imports.Add (nsi.Namespace); + } + + internal void RegisterConfigControls () + { + PagesSection pages = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection; + if (pages == null) + return; + + TagPrefixCollection controls = pages.Controls; + if (controls == null || controls.Count == 0) + return; + + foreach (TagPrefixInfo tpi in controls) { + if (!String.IsNullOrEmpty (tpi.TagName)) + RegisterCustomControl (tpi.TagPrefix, tpi.TagName, tpi.Source); + else if (!String.IsNullOrEmpty (tpi.Namespace)) + RegisterNamespace (tpi.TagPrefix, tpi.Namespace, tpi.Assembly); + } + } +#endif + + internal void RegisterCustomControl (string tagPrefix, string tagName, string src) + { + string realpath = MapPath (src); + if (String.Compare (realpath, inputFile, false, invariantCulture) == 0) + return; + + if (!File.Exists (realpath)) + throw new ParseException (Location, "Could not find file \"" + realpath + "\"."); + string vpath = UrlUtils.Combine (BaseVirtualDir, src); + Type type = null; + AddDependency (realpath); + try { + ArrayList other_deps = new ArrayList (); + type = UserControlParser.GetCompiledType (vpath, realpath, other_deps, Context); + foreach (string s in other_deps) { + AddDependency (s); + } + } catch (ParseException pe) { + if (this is UserControlParser) + throw new ParseException (Location, pe.Message, pe); + throw; + } + + AddAssembly (type.Assembly, true); + RootBuilder.Foundry.RegisterFoundry (tagPrefix, tagName, type); + } + + internal void RegisterNamespace (string tagPrefix, string ns, string assembly) + { + AddImport (ns); + Assembly ass = AddAssemblyByName (assembly); + AddDependency (ass.Location); + RootBuilder.Foundry.RegisterFoundry (tagPrefix, ass, ns); + } + internal virtual void HandleOptions (object obj) { } Index: System.Web.UI/TemplateControlParser.cs =================================================================== --- System.Web.UI/TemplateControlParser.cs (revision 68532) +++ System.Web.UI/TemplateControlParser.cs (working copy) @@ -56,7 +56,7 @@ protected TemplateControlParser () { } - + internal override void ProcessMainAttributes (Hashtable atts) { autoEventWireup = GetBool (atts, "AutoEventWireup", PagesConfig.AutoEventWireup); @@ -102,10 +102,7 @@ if (atts.Count != 0) ThrowParseException ("Unknown attribute: " + GetOneKey (atts)); - AddImport (ns); - Assembly ass = AddAssemblyByName (assembly); - AddDependency (ass.Location); - RootBuilder.Foundry.RegisterFoundry (tagprefix, ass, ns); + RegisterNamespace (tagprefix, ns, assembly); return; } @@ -121,28 +118,7 @@ if (!src.EndsWith (".ascx")) ThrowParseException ("Source file extension for controls must be .ascx"); - string realpath = MapPath (src); - if (!File.Exists (realpath)) - throw new ParseException (Location, "Could not find file \"" - + realpath + "\"."); - - string vpath = UrlUtils.Combine (BaseVirtualDir, src); - Type type = null; - AddDependency (realpath); - try { - ArrayList other_deps = new ArrayList (); - type = UserControlParser.GetCompiledType (vpath, realpath, other_deps, Context); - foreach (string s in other_deps) { - AddDependency (s); - } - } catch (ParseException pe) { - if (this is UserControlParser) - throw new ParseException (Location, pe.Message, pe); - throw; - } - - AddAssembly (type.Assembly, true); - RootBuilder.Foundry.RegisterFoundry (tagprefix, tagname, type); + RegisterCustomControl (tagprefix, tagname, src); return; } Index: System.Web.Compilation/AppResourcesCompiler.cs =================================================================== --- System.Web.Compilation/AppResourcesCompiler.cs (revision 68529) +++ System.Web.Compilation/AppResourcesCompiler.cs (working copy) @@ -123,6 +123,7 @@ } else { WebConfigurationManager.ExtraAssemblies.Add(ret.PathToAssembly); BuildManager.TopLevelAssemblies.Add (ret.CompiledAssembly); + BuildManager.HaveResources = true; } return ret; Index: System.Web.Compilation/AspGenerator.cs =================================================================== --- System.Web.Compilation/AspGenerator.cs (revision 68529) +++ System.Web.Compilation/AspGenerator.cs (working copy) @@ -277,7 +277,9 @@ } isApplication = tparser.DefaultDirectiveName == "application"; - +#if NET_2_0 + tparser.RegisterConfigControls (); +#endif Parse (); BaseCompiler compiler = GetCompilerFromType (); Index: System.Web.Compilation/BuildManager.cs =================================================================== --- System.Web.Compilation/BuildManager.cs (revision 68529) +++ System.Web.Compilation/BuildManager.cs (working copy) @@ -46,6 +46,7 @@ public sealed class BuildManager { private static List AppCode_Assemblies = new List(); private static List TopLevel_Assemblies = new List(); + private static bool haveResources; internal BuildManager () { @@ -201,18 +202,17 @@ // Assemblies built from the App_Code directory public static IList CodeAssemblies { - get { - return AppCode_Assemblies; - } + get { return AppCode_Assemblies; } } - internal static IList TopLevelAssemblies - { - get { - return TopLevel_Assemblies; - } + internal static IList TopLevelAssemblies { + get { return TopLevel_Assemblies; } } - + + internal static bool HaveResources { + get { return haveResources; } + set { haveResources = value; } + } } }