public void Defaults () { CompilationSection c = new CompilationSection (); Assert.IsNotNull (c.Assemblies, "A1"); Assert.AreEqual ("", c.AssemblyPostProcessorType, "A2"); Assert.IsTrue (c.Batch, "A3"); Assert.AreEqual (TimeSpan.FromMinutes (15), c.BatchTimeout, "A4"); Assert.IsNotNull (c.BuildProviders, "A5"); Assert.IsNotNull (c.CodeSubDirectories, "A6"); Assert.IsNotNull (c.Compilers, "A7"); Assert.IsFalse (c.Debug, "A8"); Assert.AreEqual ("vb", c.DefaultLanguage, "A9"); Assert.IsTrue (c.Explicit, "A10"); Assert.IsNotNull (c.ExpressionBuilders, "A11"); Assert.AreEqual (1000, c.MaxBatchSize, "A12"); Assert.AreEqual (15, c.NumRecompilesBeforeAppRestart, "A13"); Assert.IsFalse (c.Strict, "A14"); Assert.AreEqual ("", c.TempDirectory, "A15"); Assert.IsFalse (c.UrlLinePragmas, "A16"); }
internal bool AllowVirtualReference(CompilationSection compConfig, System.Web.VirtualPath referenceVirtualPath) { VirtualReferenceType page; string extension = referenceVirtualPath.Extension; Type type = CompilationUtil.GetBuildProviderTypeFromExtension(compConfig, extension, BuildProviderAppliesTo.Web, false); if (type == null) { return false; } if (type == typeof(PageBuildProvider)) { page = VirtualReferenceType.Page; } else if (type == typeof(UserControlBuildProvider)) { page = VirtualReferenceType.UserControl; } else if (type == typeof(MasterPageBuildProvider)) { page = VirtualReferenceType.Master; } else if (type == typeof(SourceFileBuildProvider)) { page = VirtualReferenceType.SourceFile; } else { page = VirtualReferenceType.Other; } return this.AllowVirtualReference(referenceVirtualPath.VirtualPathString, page); }
internal AssemblyBuilder(CompilationSection compConfig, ICollection referencedAssemblies, CompilerType compilerType, string outputAssemblyName) { this._compConfig = compConfig; this._outputAssemblyName = outputAssemblyName; this._initialReferencedAssemblies = AssemblySet.Create(referencedAssemblies); this._compilerType = compilerType.Clone(); if (BuildManager.PrecompilingWithDebugInfo) { this._compilerType.CompilerParameters.IncludeDebugInformation = true; } else if (BuildManager.PrecompilingForDeployment) { this._compilerType.CompilerParameters.IncludeDebugInformation = false; } else if (DeploymentSection.RetailInternal) { this._compilerType.CompilerParameters.IncludeDebugInformation = false; } else if (this._compConfig.AssemblyPostProcessorTypeInternal != null) { this._compilerType.CompilerParameters.IncludeDebugInformation = true; } this._tempFiles.KeepFiles = this._compilerType.CompilerParameters.IncludeDebugInformation; this._codeProvider = CompilationUtil.CreateCodeDomProviderNonPublic(this._compilerType.CodeDomProviderType); this._maxBatchSize = this._compConfig.MaxBatchSize; this._maxBatchGeneratedFileSize = this._compConfig.MaxBatchGeneratedFileSize * 0x400; }
internal WebDirectoryBatchCompiler(VirtualDirectory vdir) { this._vdir = vdir; this._utcStart = DateTime.UtcNow; this._compConfig = MTConfigUtil.GetCompilationConfig(this._vdir.VirtualPath); this._referencedAssemblies = BuildManager.GetReferencedAssemblies(this._compConfig); }
void RemoveAssembly(CompilationSection section, SettingsMappingWhatContents how) { Dictionary <string, string> attrs = how.Attributes; if (attrs == null || attrs.Count == 0) return; string assemblyName; if (!attrs.TryGetValue ("assembly", out assemblyName)) return; section.Assemblies.Remove (assemblyName); }
public AppResourcesAssemblyBuilder (string canonicAssemblyName, string baseAssemblyPath, AppResourcesCompiler appres) { this.appResourcesCompiler = appres; this.baseAssemblyPath = baseAssemblyPath; this.baseAssemblyDirectory = Path.GetDirectoryName (baseAssemblyPath); this.canonicAssemblyName = canonicAssemblyName; config = WebConfigurationManager.GetWebApplicationSection ("system.web/compilation") as CompilationSection; if (config == null || !CodeDomProvider.IsDefinedLanguage (config.DefaultLanguage)) throw new ApplicationException ("Could not get the default compiler."); ci = CodeDomProvider.GetCompilerInfo (config.DefaultLanguage); if (ci == null || !ci.IsCodeDomProviderTypeValid) throw new ApplicationException ("Failed to obtain the default compiler information."); }
internal static CompilerType GetDefaultLanguageCompilerInfo(CompilationSection compConfig, VirtualPath configPath) { if (compConfig == null) { // Get the <compilation> config object compConfig = MTConfigUtil.GetCompilationConfig(configPath); } // If no default language was specified in config, use VB if (compConfig.DefaultLanguage == null) { return GetCodeDefaultLanguageCompilerInfo(); } else { return compConfig.GetCompilerInfoFromLanguage(compConfig.DefaultLanguage); } }
internal CbmCodeGeneratorBuildProviderHost(CompilationSection compConfig, ICollection referencedAssemblies, CompilerType compilerType, string generatedFilesDir, string outputAssemblyName) : base(compConfig, referencedAssemblies, compilerType, outputAssemblyName) { if (Directory.Exists(generatedFilesDir)) { foreach (FileData data in (IEnumerable) FileEnumerator.Create(generatedFilesDir)) { if (!data.IsDirectory) { File.Delete(data.FullName); } } } Directory.CreateDirectory(generatedFilesDir); this._generatedFilesDir = generatedFilesDir; }
internal static void AddFolderLevelBuildProviders(BuildProviderSet buildProviders, VirtualPath virtualPath, FolderLevelBuildProviderAppliesTo appliesTo, CompilationSection compConfig, ICollection referencedAssemblies) { if (buildProviders == null) { return; } List<Type> buildProviderTypes = CompilationUtil.GetFolderLevelBuildProviderTypes(compConfig, appliesTo); if (buildProviderTypes != null) { foreach (Type buildProviderType in buildProviderTypes) { object o = HttpRuntime.CreatePublicInstance(buildProviderType); BuildProvider buildProvider = (BuildProvider)o; buildProvider.SetVirtualPath(virtualPath); buildProvider.SetReferencedAssemblies(referencedAssemblies); buildProviders.Add(buildProvider); } } }
internal static BuildProvider CreateBuildProvider(VirtualPath virtualPath, BuildProviderAppliesTo neededFor, CompilationSection compConfig, ICollection referencedAssemblies, bool failIfUnknown) { string extension = virtualPath.Extension; Type buildProviderType = CompilationUtil.GetBuildProviderTypeFromExtension(compConfig, extension, neededFor, failIfUnknown); if (buildProviderType == null) return null; object o = HttpRuntime.CreatePublicInstance(buildProviderType); BuildProvider buildProvider = (BuildProvider)o; buildProvider.SetVirtualPath(virtualPath); buildProvider.SetReferencedAssemblies(referencedAssemblies); return buildProvider; }
internal static BuildProvider CreateBuildProvider(VirtualPath virtualPath, CompilationSection compConfig, ICollection referencedAssemblies, bool failIfUnknown) { return CreateBuildProvider(virtualPath, BuildProviderAppliesTo.Web, compConfig, referencedAssemblies, failIfUnknown); }
internal static Type GetBuildProviderTypeFromExtension(CompilationSection config, string extension, BuildProviderAppliesTo neededFor, bool failIfUnknown) { BuildProviderInfo providerInfo = BuildProvider.GetBuildProviderInfo(config, extension); Type buildProviderType = null; // Never return an IgnoreFileBuildProvider/ForceCopyBuildProvider, since it's just a marker if (providerInfo != null && providerInfo.Type != typeof(IgnoreFileBuildProvider) && providerInfo.Type != typeof(ForceCopyBuildProvider)) { buildProviderType = providerInfo.Type; } // In updatable precomp mode, only aspx/ascx/master web files need processing. Ignore the rest. if (neededFor == BuildProviderAppliesTo.Web && BuildManager.PrecompilingForUpdatableDeployment && !typeof(BaseTemplateBuildProvider).IsAssignableFrom(buildProviderType)) { buildProviderType = null; } if (buildProviderType != null) { // Only return it if it applies to what it's needed for if ((neededFor & providerInfo.AppliesTo) != 0) return buildProviderType; } // If the extension is registered as a compiler extension, use // a SourceFileBuildProvider to handle it (not supported in Resources directory) else if (neededFor != BuildProviderAppliesTo.Resources && config.GetCompilerInfoFromExtension(extension, false /*throwOnFail*/) != null) { return typeof(SourceFileBuildProvider); } if (failIfUnknown) { throw new HttpException( SR.GetString(SR.Unknown_buildprovider_extension, extension, neededFor.ToString())); } return null; }
internal CbmCodeGeneratorBuildProviderHost(CompilationSection compConfig, ICollection referencedAssemblies, CompilerType compilerType, string generatedFilesDir, string outputAssemblyName) : base(compConfig, referencedAssemblies, compilerType, outputAssemblyName) { // Wipe out any existing directory, and recreate it // This is where we will put generated source files if (Directory.Exists(generatedFilesDir)) { // Delete all the files in the directory foreach (FileData fileData in FileEnumerator.Create(generatedFilesDir)) { // It should only contain files Debug.Assert(!fileData.IsDirectory); if (fileData.IsDirectory) continue; Debug.Trace("CbmCodeGeneratorBuildProviderHost", "Deleting " + fileData.FullName); File.Delete(fileData.FullName); } } // Create it to make sure it exists Directory.CreateDirectory(generatedFilesDir); _generatedFilesDir = generatedFilesDir; }
internal static List<Type> GetFolderLevelBuildProviderTypes(CompilationSection config, FolderLevelBuildProviderAppliesTo appliesTo) { return config.FolderLevelBuildProviders.GetBuildProviderTypes(appliesTo); }
internal bool AllowVirtualReference(CompilationSection compConfig, VirtualPath referenceVirtualPath) { // Get the extension, and from it the type of the BuildProvider string extension = referenceVirtualPath.Extension; Type buildProviderType = CompilationUtil.GetBuildProviderTypeFromExtension( compConfig, extension, BuildProviderAppliesTo.Web, false /*failIfUnknown*/); // If it's an unknown type, block it if (buildProviderType == null) return false; // Figure out the VirtualReferenceType based on the BuildProvider type VirtualReferenceType referenceType; if (buildProviderType == typeof(PageBuildProvider)) referenceType = VirtualReferenceType.Page; else if (buildProviderType == typeof(UserControlBuildProvider)) referenceType = VirtualReferenceType.UserControl; else if (buildProviderType == typeof(MasterPageBuildProvider)) referenceType = VirtualReferenceType.Master; else if (buildProviderType == typeof(SourceFileBuildProvider)) referenceType = VirtualReferenceType.SourceFile; else referenceType = VirtualReferenceType.Other; return AllowVirtualReference(referenceVirtualPath.VirtualPathString, referenceType); }
internal static ICollection GetReferencedAssemblies(CompilationSection compConfig) { // Start by cloning the top level referenced assemblies (code + global.asax + etc...) AssemblySet referencedAssemblies = AssemblySet.Create( TheBuildManager.TopLevelReferencedAssemblies); // Add all the config assemblies to the list foreach (AssemblyInfo a in compConfig.Assemblies) { Assembly[] assemblies = a.AssemblyInternal; if (assemblies == null) { lock (compConfig) { assemblies = a.AssemblyInternal; if (assemblies == null) // assemblies = a.AssemblyInternal = compConfig.LoadAssembly(a); } } for (int i = 0; i < assemblies.Length; i++) { if (assemblies[i] != null) { referencedAssemblies.Add(assemblies[i]); } } } // foreach (Assembly assembly in s_dynamicallyAddedReferencedAssembly) { referencedAssemblies.Add(assembly); } return referencedAssemblies; }
internal static CompilerType GetCSharpCompilerInfo(CompilationSection compConfig, VirtualPath configPath) { if (compConfig == null) { compConfig = MTConfigUtil.GetCompilationConfig(configPath); } if (compConfig.DefaultLanguage == null) { return new CompilerType(typeof(CSharpCodeProvider), null); } return compConfig.GetCompilerInfoFromLanguage("c#"); }
private static PolicyLevel GetPartialTrustPolicyLevel(TrustSection trustSection, SecurityPolicySection securityPolicySection, CompilationSection compilationSection, string physicalPath, VirtualPath virtualPath) { if ((securityPolicySection == null) || (securityPolicySection.TrustLevels[trustSection.Level] == null)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Unable_to_get_policy_file", new object[] { trustSection.Level }), string.Empty, 0); } string policyFileExpanded = securityPolicySection.TrustLevels[trustSection.Level].PolicyFileExpanded; if ((policyFileExpanded == null) || !System.Web.Util.FileUtil.FileExists(policyFileExpanded)) { throw new HttpException(System.Web.SR.GetString("Unable_to_get_policy_file", new object[] { trustSection.Level })); } PolicyLevel level = null; string path = System.Web.Util.FileUtil.RemoveTrailingDirectoryBackSlash(physicalPath); string newValue = HttpRuntime.MakeFileUrl(path); string tempDirectory = null; string tempDirAttribName = null; string configFileName = null; int configLineNumber = 0; if ((compilationSection != null) && !string.IsNullOrEmpty(compilationSection.TempDirectory)) { tempDirectory = compilationSection.TempDirectory; compilationSection.GetTempDirectoryErrorInfo(out tempDirAttribName, out configFileName, out configLineNumber); } if (tempDirectory != null) { tempDirectory = tempDirectory.Trim(); if (!Path.IsPathRooted(tempDirectory)) { tempDirectory = null; } else { try { tempDirectory = new DirectoryInfo(tempDirectory).FullName; } catch { tempDirectory = null; } } if (tempDirectory == null) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_temp_directory", new object[] { tempDirAttribName }), configFileName, configLineNumber); } try { Directory.CreateDirectory(tempDirectory); goto Label_0165; } catch (Exception exception) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_temp_directory", new object[] { tempDirAttribName }), exception, configFileName, configLineNumber); } } tempDirectory = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "Temporary ASP.NET Files"); Label_0165: if (!Util.HasWriteAccessToDirectory(tempDirectory)) { if (!Environment.UserInteractive) { throw new HttpException(System.Web.SR.GetString("No_codegen_access", new object[] { Util.GetCurrentAccountName(), tempDirectory })); } tempDirectory = Path.Combine(Path.GetTempPath(), "Temporary ASP.NET Files"); } string str7 = AppManagerAppDomainFactory.ConstructSimpleAppName(VirtualPath.GetVirtualPathStringNoTrailingSlash(virtualPath)); string str9 = HttpRuntime.MakeFileUrl(System.Web.Util.FileUtil.RemoveTrailingDirectoryBackSlash(Path.Combine(tempDirectory, str7))); string originUrl = trustSection.OriginUrl; FileStream stream = new FileStream(policyFileExpanded, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream, Encoding.UTF8); string str = reader.ReadToEnd(); reader.Close(); str = str.Replace("$AppDir$", path).Replace("$AppDirUrl$", newValue).Replace("$CodeGen$", str9); if (originUrl == null) { originUrl = string.Empty; } str = str.Replace("$OriginHost$", originUrl); string gacLocation = null; if (str.IndexOf("$Gac$", StringComparison.Ordinal) != -1) { gacLocation = HttpRuntime.GetGacLocation(); if (gacLocation != null) { gacLocation = HttpRuntime.MakeFileUrl(gacLocation); } if (gacLocation == null) { gacLocation = string.Empty; } str = str.Replace("$Gac$", gacLocation); } level = SecurityManager.LoadPolicyLevelFromString(str, PolicyLevelType.AppDomain); if (level == null) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Unable_to_get_policy_file", new object[] { trustSection.Level })); } if (gacLocation != null) { CodeGroup rootCodeGroup = level.RootCodeGroup; bool flag = false; foreach (CodeGroup group2 in rootCodeGroup.Children) { if (group2.MembershipCondition is GacMembershipCondition) { flag = true; break; } } if (!flag && (rootCodeGroup is FirstMatchCodeGroup)) { FirstMatchCodeGroup group3 = (FirstMatchCodeGroup) rootCodeGroup; if (!(group3.MembershipCondition is AllMembershipCondition) || !(group3.PermissionSetName == "Nothing")) { return level; } PermissionSet permSet = new PermissionSet(PermissionState.Unrestricted); CodeGroup group = new UnionCodeGroup(new GacMembershipCondition(), new PolicyStatement(permSet)); CodeGroup group5 = new FirstMatchCodeGroup(rootCodeGroup.MembershipCondition, rootCodeGroup.PolicyStatement); foreach (CodeGroup group6 in rootCodeGroup.Children) { if (((group6 is UnionCodeGroup) && (group6.MembershipCondition is UrlMembershipCondition)) && (group6.PolicyStatement.PermissionSet.IsUnrestricted() && (group != null))) { group5.AddChild(group); group = null; } group5.AddChild(group6); } level.RootCodeGroup = group5; } } return level; }
internal NonBatchDirectoryCompiler(VirtualDirectory vdir) { _vdir = vdir; _compConfig = MTConfigUtil.GetCompilationConfig(_vdir.VirtualPath); }
internal void SetCompilationReference(CompilationSection compSection) { _compilationSection = compSection; }
internal static void FixUpCompilerParameters(CompilationSection compilationSection, Type codeDomProviderType, CompilerParameters compilParams) { // The mscorlib reference is special cased, and needs to be passed via the CoreAssemblyFileName property. if (BuildManagerHost.InClientBuildManager && !MultiTargetingUtil.IsTargetFramework20 && !MultiTargetingUtil.IsTargetFramework35) { string coreAssemblyFile; AssemblyResolver.GetPathToReferenceAssembly(typeof(string).Assembly, out coreAssemblyFile); compilParams.CoreAssemblyFileName = coreAssemblyFile; } // DevDiv 404267: If the developer enabled 'warnings as errors', we should disable [Obsolete] warnings. This helps // prevent in-place framework updates from breaking runtime compilation of pages. We only respect this attribute // when not in the CBM, as CBM is a design-time feature instead of a runtime feature, and the developer probably // wants to be notified of all errors at design time. bool disableObsoleteWarnings = !BuildManagerHost.InClientBuildManager && compilationSection.DisableObsoleteWarnings; // If C#, remove the warning that complains about variables that start with "__" // Also ignore warning that complains about assemblyKeyName and delaysign // Also ignore warning about assuming assembly versions matching (CS1701, DevDiv 137847, warning about System.Web.Extensions v1.0 matching v3.5) if (codeDomProviderType == typeof(Microsoft.CSharp.CSharpCodeProvider)) { List<string> noWarnStrings = new List<string>(5); noWarnStrings.AddRange(new string[] { "1659", "1699", "1701" }); if (disableObsoleteWarnings) { noWarnStrings.Add("612"); // [Obsolete] without message noWarnStrings.Add("618"); // [Obsolete("with message")] } CodeDomUtility.PrependCompilerOption(compilParams, "/nowarn:" + String.Join(";", noWarnStrings)); } else if (codeDomProviderType == typeof(Microsoft.VisualBasic.VBCodeProvider)) { List<string> noWarnStrings = new List<string>(3); // If VB, add all the imported namespaces on the command line (DevDiv 21499). // This is VB only because other languages don't support global command line // namespace imports. AddVBGlobalNamespaceImports(compilParams); // Add any command line flags needed to support the My.* feature AddVBMyFlags(compilParams); // Ignore vb warning that complains about assemblyKeyName (Dev10 662544) // but only for target 3.5 and above (715329) if (MultiTargetingUtil.TargetFrameworkVersion >= MultiTargetingUtil.Version35) { noWarnStrings.Add("41008"); } if (disableObsoleteWarnings) { noWarnStrings.Add("40000"); // [Obsolete("with message")] noWarnStrings.Add("40008"); // [Obsolete] without message } if (noWarnStrings.Count > 0) { CodeDomUtility.PrependCompilerOption(compilParams, "/nowarn:" + String.Join(",", noWarnStrings)); } } ProcessProviderOptions(codeDomProviderType, compilParams); FixTreatWarningsAsErrors(codeDomProviderType, compilParams); // Add CodeAnalysis symbol if required by client. if (BuildManager.PrecompilingWithCodeAnalysisSymbol) { CodeDomUtility.PrependCompilerOption(compilParams, "/define:CODE_ANALYSIS"); } }
internal AssemblyBuilder(CompilationSection compConfig, ICollection referencedAssemblies, CompilerType compilerType, string outputAssemblyName) { _compConfig = compConfig; _outputAssemblyName = outputAssemblyName; // Clone the referenced assemblies _initialReferencedAssemblies = AssemblySet.Create(referencedAssemblies); // We need to clone it to avoid modifying the original (VSWhidbey 338935) _compilerType = compilerType.Clone(); if (BuildManager.PrecompilingWithDebugInfo) { // If the precompile flag indicates force debug, always compile as debug _compilerType.CompilerParameters.IncludeDebugInformation = true; } else if (BuildManager.PrecompilingForDeployment) { // If we're precompiling the app, never compile in debug mode (VSWhidbey 178377) _compilerType.CompilerParameters.IncludeDebugInformation = false; } else if (DeploymentSection.RetailInternal) { // If we're in retail deployment mode, always turn off debug (DevDiv 36396) _compilerType.CompilerParameters.IncludeDebugInformation = false; } else if (_compConfig.AssemblyPostProcessorTypeInternal != null) { // If an IAssemblyPostProcessor is registered always compile as debug _compilerType.CompilerParameters.IncludeDebugInformation = true; } // _tempFiles.KeepFiles = _compilerType.CompilerParameters.IncludeDebugInformation; _codeProvider = CompilationUtil.CreateCodeDomProviderNonPublic( _compilerType.CodeDomProviderType); _maxBatchSize = _compConfig.MaxBatchSize; _maxBatchGeneratedFileSize = _compConfig.MaxBatchGeneratedFileSize * 1024; }
internal static Type GetBuildProviderTypeFromExtension(CompilationSection config, string extension, BuildProviderAppliesTo neededFor, bool failIfUnknown) { BuildProviderInfo buildProviderInfo = System.Web.Compilation.BuildProvider.GetBuildProviderInfo(config, extension); Type c = null; if (((buildProviderInfo != null) && (buildProviderInfo.Type != typeof(IgnoreFileBuildProvider))) && (buildProviderInfo.Type != typeof(ForceCopyBuildProvider))) { c = buildProviderInfo.Type; } if (((neededFor == BuildProviderAppliesTo.Web) && BuildManager.PrecompilingForUpdatableDeployment) && !typeof(BaseTemplateBuildProvider).IsAssignableFrom(c)) { c = null; } if (c != null) { if ((neededFor & buildProviderInfo.AppliesTo) != 0) { return c; } } else if ((neededFor != BuildProviderAppliesTo.Resources) && (config.GetCompilerInfoFromExtension(extension, false) != null)) { return typeof(SourceFileBuildProvider); } if (failIfUnknown) { throw new HttpException(System.Web.SR.GetString("Unknown_buildprovider_extension", new object[] { extension, neededFor.ToString() })); } return null; }
internal static CompilerType GetDefaultCompilerTypeForLanguage (string language, CompilationSection configSection) { return GetDefaultCompilerTypeForLanguage (language, configSection, true); }
internal static CompilerType GetDefaultLanguageCompilerInfo(CompilationSection compConfig, VirtualPath configPath) { if (compConfig == null) { compConfig = MTConfigUtil.GetCompilationConfig(configPath); } if (compConfig.DefaultLanguage == null) { return GetCodeDefaultLanguageCompilerInfo(); } return compConfig.GetCompilerInfoFromLanguage(compConfig.DefaultLanguage); }
internal static CompilerType GetDefaultCompilerTypeForLanguage (string language, CompilationSection configSection, bool throwOnMissing) { // MS throws when accesing a Hashtable, we do here. if (language == null || language.Length == 0) throw new ArgumentNullException ("language"); CompilationSection config; if (configSection == null) config = WebConfigurationManager.GetWebApplicationSection ("system.web/compilation") as CompilationSection; else config = configSection; Compiler compiler = config.Compilers.Get (language); CompilerParameters p; Type type; if (compiler != null) { type = HttpApplication.LoadType (compiler.Type, true); p = new CompilerParameters (); p.CompilerOptions = compiler.CompilerOptions; p.WarningLevel = compiler.WarningLevel; SetCommonParameters (config, p, type, language); return new CompilerType (type, p); } if (CodeDomProvider.IsDefinedLanguage (language)) { CompilerInfo info = CodeDomProvider.GetCompilerInfo (language); p = info.CreateDefaultCompilerParameters (); type = info.CodeDomProviderType; SetCommonParameters (config, p, type, language); return new CompilerType (type, p); } if (throwOnMissing) throw new HttpException (String.Concat ("No compiler for language '", language, "'.")); return null; }
internal static long GetRecompilationHash(CompilationSection ps) { HashCodeCombiner combiner = new HashCodeCombiner(); combiner.AddObject(ps.Debug); combiner.AddObject(ps.TargetFramework); combiner.AddObject(ps.Strict); combiner.AddObject(ps.Explicit); combiner.AddObject(ps.Batch); combiner.AddObject(ps.OptimizeCompilations); combiner.AddObject(ps.BatchTimeout); combiner.AddObject(ps.MaxBatchGeneratedFileSize); combiner.AddObject(ps.MaxBatchSize); combiner.AddObject(ps.NumRecompilesBeforeAppRestart); combiner.AddObject(ps.DefaultLanguage); combiner.AddObject(ps.UrlLinePragmas); if (ps.AssemblyPostProcessorTypeInternal != null) { combiner.AddObject(ps.AssemblyPostProcessorTypeInternal.FullName); } foreach (Compiler compiler in ps.Compilers) { combiner.AddObject(compiler.Language); combiner.AddObject(compiler.Extension); combiner.AddObject(compiler.Type); combiner.AddObject(compiler.WarningLevel); combiner.AddObject(compiler.CompilerOptions); } foreach (System.Web.Configuration.ExpressionBuilder builder in ps.ExpressionBuilders) { combiner.AddObject(builder.ExpressionPrefix); combiner.AddObject(builder.Type); } AssemblyCollection assemblies = ps.Assemblies; if (assemblies.Count == 0) { combiner.AddObject("__clearassemblies"); } else { foreach (AssemblyInfo info in assemblies) { combiner.AddObject(info.Assembly); } } BuildProviderCollection buildProviders = ps.BuildProviders; if (buildProviders.Count == 0) { combiner.AddObject("__clearbuildproviders"); } else { foreach (System.Web.Configuration.BuildProvider provider in buildProviders) { combiner.AddObject(provider.Type); combiner.AddObject(provider.Extension); } } FolderLevelBuildProviderCollection folderLevelBuildProviders = ps.FolderLevelBuildProviders; if (folderLevelBuildProviders.Count == 0) { combiner.AddObject("__clearfolderlevelbuildproviders"); } else { foreach (FolderLevelBuildProvider provider2 in folderLevelBuildProviders) { combiner.AddObject(provider2.Type); combiner.AddObject(provider2.Name); } } CodeSubDirectoriesCollection codeSubDirectories = ps.CodeSubDirectories; if (codeSubDirectories.Count == 0) { combiner.AddObject("__clearcodesubdirs"); } else { foreach (CodeSubDirectory directory in codeSubDirectories) { combiner.AddObject(directory.DirectoryName); } } CompilerInfo[] allCompilerInfo = CodeDomProvider.GetAllCompilerInfo(); if (allCompilerInfo != null) { foreach (CompilerInfo info2 in allCompilerInfo) { if (info2.IsCodeDomProviderTypeValid) { string compilerOptions = info2.CreateDefaultCompilerParameters().CompilerOptions; if (!string.IsNullOrEmpty(compilerOptions)) { Type codeDomProviderType = info2.CodeDomProviderType; if (codeDomProviderType != null) { combiner.AddObject(codeDomProviderType.FullName); } combiner.AddObject(compilerOptions); } if (info2.CodeDomProviderType != null) { IDictionary<string, string> providerOptions = GetProviderOptions(info2); if ((providerOptions != null) && (providerOptions.Count > 0)) { string fullName = info2.CodeDomProviderType.FullName; foreach (string str3 in providerOptions.Keys) { string str4 = providerOptions[str3]; combiner.AddObject(fullName + ":" + str3 + "=" + str4); } } } } } } return combiner.CombinedHash; }
static void SetCommonParameters (CompilationSection config, CompilerParameters p, Type compilerType, string language) { p.IncludeDebugInformation = config.Debug; MonoSettingsSection mss = WebConfigurationManager.GetSection ("system.web/monoSettings") as MonoSettingsSection; if (mss == null || !mss.UseCompilersCompatibility) return; Compiler compiler = mss.CompilersCompatibility.Get (language); if (compiler == null) return; Type type = HttpApplication.LoadType (compiler.Type, false); if (type != compilerType) return; p.CompilerOptions = String.Concat (p.CompilerOptions, " ", compiler.CompilerOptions); }
static void Main(string[] args) { //<snippet1> // Obtains the machine configuration settings on the local machine. System.Configuration.Configuration machineConfig = System.Web.Configuration.WebConfigurationManager.OpenMachineConfiguration(); machineConfig.SaveAs("c:\\machineConfig.xml"); //</snippet1> //<snippet2> // Obtains the configuration settings for a Web application. System.Configuration.Configuration webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Temp"); webConfig.SaveAs("c:\\webConfig.xml"); //</snippet2> //<snippet3> // Obtains the configuration settings for the <anonymousIdentification> section. System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Temp"); System.Web.Configuration.SystemWebSectionGroup systemWeb = config.GetSectionGroup("system.web") as System.Web.Configuration.SystemWebSectionGroup; System.Web.Configuration.AnonymousIdentificationSection sectionConfig = systemWeb.AnonymousIdentification; if (sectionConfig != null) { StringBuilder sb = new StringBuilder(); sb.Append("<anonymousIdentification> attributes:\r\n"); System.Configuration.PropertyInformationCollection props = sectionConfig.ElementInformation.Properties; foreach (System.Configuration.PropertyInformation prop in props) { sb.AppendFormat("{0} = {1}\r\n", prop.Name.ToString(), prop.Value.ToString()); } Console.WriteLine(sb.ToString()); } //</snippet3> //<snippet4> IntPtr userToken = System.Security.Principal.WindowsIdentity.GetCurrent().Token; // Obtains the machine configuration settings on a remote machine. System.Configuration.Configuration remoteMachineConfig = System.Web.Configuration.WebConfigurationManager.OpenMachineConfiguration (null, "ServerName", userToken); remoteMachineConfig.SaveAs("c:\\remoteMachineConfig.xml"); // Obtains the root Web configuration settings on a remote machine. System.Configuration.Configuration remoteRootConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration (null, null, null, "ServerName", userToken); remoteRootConfig.SaveAs("c:\\remoteRootConfig.xml"); // Obtains the configuration settings for the // W3SVC/1/Root/Temp application on a remote machine. System.Configuration.Configuration remoteWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration ("/Temp", "1", null, "ServerName", userToken); remoteWebConfig.SaveAs("c:\\remoteWebConfig.xml"); //</snippet4> //<snippet5> // Updates the configuration settings for a Web application. System.Configuration.Configuration updateWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Temp"); System.Web.Configuration.CompilationSection compilation = updateWebConfig.GetSection("system.web/compilation") as System.Web.Configuration.CompilationSection; Console.WriteLine("Current <compilation> debug = {0}", compilation.Debug); compilation.Debug = true; if (!compilation.SectionInformation.IsLocked) { updateWebConfig.Save(); Console.WriteLine("New <compilation> debug = {0}", compilation.Debug); } else { Console.WriteLine("Could not save configuration."); } //</snippet5> //<snippet6> System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MyWebSiteRoot"); System.Configuration.ConnectionStringSettings connString; if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0) { connString = rootWebConfig.ConnectionStrings.ConnectionStrings["NorthwindConnectionString"]; if (connString != null) { Console.WriteLine("Northwind connection string = \"{0}\"", connString.ConnectionString); } else { Console.WriteLine("No Northwind connection string"); } } //</snippet6> //<snippet7> System.Configuration.Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null); if (rootWebConfig1.AppSettings.Settings.Count > 0) { System.Configuration.KeyValueConfigurationElement customSetting = rootWebConfig1.AppSettings.Settings["customsetting1"]; if (customSetting != null) { Console.WriteLine("customsetting1 application string = \"{0}\"", customSetting.Value); } else { Console.WriteLine("No customsetting1 application string"); } } //</snippet7> }
internal static CompilerType GetCSharpCompilerInfo( CompilationSection compConfig, VirtualPath configPath) { if (compConfig == null) { // Get the <compilation> config object compConfig = MTConfigUtil.GetCompilationConfig(configPath); } if (compConfig.DefaultLanguage == null) return new CompilerType(typeof(Microsoft.CSharp.CSharpCodeProvider), null); return compConfig.GetCompilerInfoFromLanguage("c#"); }
/* * Do some initialization before the parsing */ internal virtual void PrepareParse() { if (_circularReferenceChecker == null) _circularReferenceChecker = new CaseInsensitiveStringSet(); _baseType = DefaultBaseType; // Initialize the main directive _mainDirectiveConfigSettings = CreateEmptyAttributeBag(); // Get the config sections we care about if (!FInDesigner) { _compConfig = MTConfigUtil.GetCompilationConfig(CurrentVirtualPath); _pagesConfig = MTConfigUtil.GetPagesConfig(CurrentVirtualPath); } // Get default settings from config ProcessConfigSettings(); // Initialize the type mapper // This must follow processing of config, so it can use the results _typeMapper = new MainTagNameToTypeMapper(this as BaseTemplateParser); // Register the <object> tag _typeMapper.RegisterTag("object", typeof(System.Web.UI.ObjectTag)); _sourceDependencies = new CaseInsensitiveStringSet(); // Create and seed the stack of ID lists. _idListStack = new Stack(); _idList = new CaseInsensitiveStringSet(); _scriptList = new ArrayList(); // Optionally collect additional parse data for render tracing InitializeParseRecorders(); }
internal static long GetRecompilationHash(CompilationSection ps) { HashCodeCombiner recompilationHash = new HashCodeCombiner(); AssemblyCollection assemblies; BuildProviderCollection builders; FolderLevelBuildProviderCollection buildProviders; CodeSubDirectoriesCollection codeSubDirs; // Combine items from Compilation section recompilationHash.AddObject(ps.Debug); recompilationHash.AddObject(ps.TargetFramework); recompilationHash.AddObject(ps.Strict); recompilationHash.AddObject(ps.Explicit); recompilationHash.AddObject(ps.Batch); recompilationHash.AddObject(ps.OptimizeCompilations); recompilationHash.AddObject(ps.BatchTimeout); recompilationHash.AddObject(ps.MaxBatchGeneratedFileSize); recompilationHash.AddObject(ps.MaxBatchSize); recompilationHash.AddObject(ps.NumRecompilesBeforeAppRestart); recompilationHash.AddObject(ps.DefaultLanguage); recompilationHash.AddObject(ps.UrlLinePragmas); recompilationHash.AddObject(ps.DisableObsoleteWarnings); if (ps.AssemblyPostProcessorTypeInternal != null) { recompilationHash.AddObject(ps.AssemblyPostProcessorTypeInternal.FullName); } if (!String.IsNullOrWhiteSpace(ps.ControlBuilderInterceptorType)) { recompilationHash.AddObject(ps.ControlBuilderInterceptorType); } // Combine items from Compilers collection foreach (Compiler compiler in ps.Compilers) { recompilationHash.AddObject(compiler.Language); recompilationHash.AddObject(compiler.Extension); recompilationHash.AddObject(compiler.Type); recompilationHash.AddObject(compiler.WarningLevel); recompilationHash.AddObject(compiler.CompilerOptions); } // Combine items from <expressionBuilders> section foreach (System.Web.Configuration.ExpressionBuilder eb in ps.ExpressionBuilders) { recompilationHash.AddObject(eb.ExpressionPrefix); recompilationHash.AddObject(eb.Type); } // Combine items from the Assembly collection assemblies = ps.Assemblies; if (assemblies.Count == 0) { recompilationHash.AddObject("__clearassemblies"); } else { foreach (AssemblyInfo ai in assemblies) { recompilationHash.AddObject(ai.Assembly); } } // Combine items from the Builders Collection builders = ps.BuildProviders; if (builders.Count == 0) { recompilationHash.AddObject("__clearbuildproviders"); } else { foreach (System.Web.Configuration.BuildProvider bp in builders) { recompilationHash.AddObject(bp.Type); recompilationHash.AddObject(bp.Extension); } } // Combine items from the FolderLevelBuildProviderCollection buildProviders = ps.FolderLevelBuildProviders; if (buildProviders.Count == 0) { recompilationHash.AddObject("__clearfolderlevelbuildproviders"); } else { foreach (System.Web.Configuration.FolderLevelBuildProvider bp in buildProviders) { recompilationHash.AddObject(bp.Type); recompilationHash.AddObject(bp.Name); } } codeSubDirs = ps.CodeSubDirectories; if (codeSubDirs.Count == 0) { recompilationHash.AddObject("__clearcodesubdirs"); } else { foreach (CodeSubDirectory csd in codeSubDirs) { recompilationHash.AddObject(csd.DirectoryName); } } // Make sure the <system.CodeDom> section is hashed properly. CompilerInfo[] compilerInfoArray = CodeDomProvider.GetAllCompilerInfo(); if (compilerInfoArray != null) { CompilerInfo cppCodeProvider = CodeDomProvider.GetCompilerInfo("cpp"); foreach (CompilerInfo info in compilerInfoArray) { // Skip cpp code provider (Dev11 193323). if (info == cppCodeProvider) { continue; } // Ignore it if the type is not valid. if (!info.IsCodeDomProviderTypeValid) { continue; } CompilerParameters parameters = info.CreateDefaultCompilerParameters(); string option = parameters.CompilerOptions; if (!String.IsNullOrEmpty(option)) { Type type = info.CodeDomProviderType; if (type != null) { recompilationHash.AddObject(type.FullName); } // compilerOptions need to be hashed. recompilationHash.AddObject(option); } // DevDiv 62998 // The tag providerOption needs to be added to the hash, // as the user could switch between v2 and v3.5. if (info.CodeDomProviderType == null) continue; // Add a hash for each providerOption added, specific for each codeDomProvider, so that // if some codedom setting has changed, we know we have to recompile. IDictionary<string, string> providerOptions = GetProviderOptions(info); if (providerOptions != null && providerOptions.Count > 0) { string codeDomProviderType = info.CodeDomProviderType.FullName; foreach (string key in providerOptions.Keys) { string value = providerOptions[key]; recompilationHash.AddObject(codeDomProviderType + ":" + key + "=" + value); } } } } return recompilationHash.CombinedHash; }