private void AddBuildProviders(bool retryIfDeletionHappens) { DiskBuildResultCache.ResetAssemblyDeleted(); foreach (VirtualFile file in this._vdir.Files) { BuildResult vPathBuildResultFromCache = null; try { vPathBuildResultFromCache = BuildManager.GetVPathBuildResultFromCache(file.VirtualPathObject); } catch { if (!BuildManager.PerformingPrecompilation) { continue; } } if (vPathBuildResultFromCache == null) { System.Web.Compilation.BuildProvider provider = BuildManager.CreateBuildProvider(file.VirtualPathObject, this._compConfig, this._referencedAssemblies, false); if (provider != null) { this._buildProviders[file.VirtualPath] = provider; } } } if ((DiskBuildResultCache.InUseAssemblyWasDeleted && retryIfDeletionHappens) && BuildManager.PerformingPrecompilation) { this.AddBuildProviders(false); } }
private void AddCompileWithBuildProvider(VirtualPath virtualPath, System.Web.Compilation.BuildProvider owningBuildProvider) { System.Web.Compilation.BuildProvider buildProvider = BuildManager.CreateBuildProvider(virtualPath, this._compConfig, this._initialReferencedAssemblies, true); buildProvider.SetNoBuildResult(); SourceFileBuildProvider provider2 = buildProvider as SourceFileBuildProvider; if (provider2 != null) { provider2.OwningBuildProvider = owningBuildProvider; } this.AddBuildProvider(buildProvider); }
private void ProcessDirectoryRecursive(VirtualDirectory vdir, bool topLevel) { if (this._dirType == CodeDirectoryType.WebReferences) { BuildProvider o = new WebReferencesBuildProvider(vdir); o.SetVirtualPath(vdir.VirtualPathObject); this._buildProviders.Add(o); this.AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.WebReferences); } else if (this._dirType == CodeDirectoryType.AppResources) { this.AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.GlobalResources); } else if (this._dirType == CodeDirectoryType.LocalResources) { this.AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.LocalResources); } else if ((this._dirType == CodeDirectoryType.MainCode) || (this._dirType == CodeDirectoryType.SubCode)) { this.AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.Code); } foreach (VirtualFileBase base2 in vdir.Children) { if (base2.IsDirectory) { if (((!topLevel || (this._excludedSubdirectories == null)) || !this._excludedSubdirectories.Contains(base2.Name)) && !(base2.Name == "_vti_cnf")) { this.ProcessDirectoryRecursive(base2 as VirtualDirectory, false); } } else if ((this._dirType != CodeDirectoryType.WebReferences) && ((!IsResourceCodeDirectoryType(this._dirType) || !this._onlyBuildLocalizedResources) || (Util.GetCultureName(base2.VirtualPath) != null))) { BuildProvider provider2 = BuildManager.CreateBuildProvider(base2.VirtualPathObject, IsResourceCodeDirectoryType(this._dirType) ? BuildProviderAppliesTo.Resources : BuildProviderAppliesTo.Code, this._bpc.CompConfig, this._bpc.ReferencedAssemblies, false); if (provider2 != null) { if ((this._dirType == CodeDirectoryType.LocalResources) && (provider2 is BaseResourcesBuildProvider)) { ((BaseResourcesBuildProvider)provider2).DontGenerateStronglyTypedClass(); } this._buildProviders.Add(provider2); } } } }
private System.Web.Compilation.BuildProvider GetCompilerParamsAndBuildProvider(VirtualPath virtualPath, out Type codeDomProviderType, out CompilerParameters compilerParameters) { virtualPath.CombineWithAppRoot(); CompilationSection compilationConfig = MTConfigUtil.GetCompilationConfig(virtualPath); ICollection referencedAssemblies = BuildManager.GetReferencedAssemblies(compilationConfig); System.Web.Compilation.BuildProvider provider = null; if (StringUtil.EqualsIgnoreCase(virtualPath.VirtualPathString, BuildManager.GlobalAsaxVirtualPath.VirtualPathString)) { ApplicationBuildProvider provider2 = new ApplicationBuildProvider(); provider2.SetVirtualPath(virtualPath); provider2.SetReferencedAssemblies(referencedAssemblies); provider = provider2; } else { provider = BuildManager.CreateBuildProvider(virtualPath, compilationConfig, referencedAssemblies, true); } provider.IgnoreParseErrors = true; provider.IgnoreControlProperties = true; provider.ThrowOnFirstParseError = false; CompilerType codeCompilerType = provider.CodeCompilerType; if (codeCompilerType == null) { codeDomProviderType = null; compilerParameters = null; return(null); } codeDomProviderType = codeCompilerType.CodeDomProviderType; compilerParameters = codeCompilerType.CompilerParameters; IAssemblyDependencyParser assemblyDependencyParser = provider.AssemblyDependencyParser; if ((assemblyDependencyParser != null) && (assemblyDependencyParser.AssemblyDependencies != null)) { Util.AddAssembliesToStringCollection(assemblyDependencyParser.AssemblyDependencies, compilerParameters.ReferencedAssemblies); } AssemblyBuilder.FixUpCompilerParameters(codeDomProviderType, compilerParameters); return(provider); }
private BuildProvider GetCompilerParamsAndBuildProvider(VirtualPath virtualPath, out Type codeDomProviderType, out CompilerParameters compilerParameters) { virtualPath.CombineWithAppRoot(); CompilationSection compConfig = MTConfigUtil.GetCompilationConfig(virtualPath); ICollection referencedAssemblies = BuildManager.GetReferencedAssemblies(compConfig); // Create the buildprovider for the passed in virtualPath BuildProvider buildProvider = null; // Special case global asax build provider here since we do not want to compile every files with ".asax" extension. if (StringUtil.EqualsIgnoreCase(virtualPath.VirtualPathString, BuildManager.GlobalAsaxVirtualPath.VirtualPathString)) { ApplicationBuildProvider provider = new ApplicationBuildProvider(); provider.SetVirtualPath(virtualPath); provider.SetReferencedAssemblies(referencedAssemblies); buildProvider = provider; } else { buildProvider = BuildManager.CreateBuildProvider(virtualPath, compConfig, referencedAssemblies, true /*failIfUnknown*/); } // DevDiv 69017 // The methods restricted to internalBuildProvider have been moved up to BuildProvider // to allow WCFBuildProvider to support .svc syntax highlighting. // Ignore parse errors, since they should not break the designer buildProvider.IgnoreParseErrors = true; // Ignore all control properties, since we do not generate code for the properties buildProvider.IgnoreControlProperties = true; // Process as many errors as possible, do not rethrow on first error buildProvider.ThrowOnFirstParseError = false; // Get the language (causes the file to be parsed) CompilerType compilerType = buildProvider.CodeCompilerType; // compilerType could be null in the no-compile case (VSWhidbey 221749) if (compilerType == null) { codeDomProviderType = null; compilerParameters = null; return(null); } // Return the provider type and compiler params codeDomProviderType = compilerType.CodeDomProviderType; compilerParameters = compilerType.CompilerParameters; IAssemblyDependencyParser parser = buildProvider.AssemblyDependencyParser; // Add all the assemblies that the page depends on (e.g. user controls) if (parser != null && parser.AssemblyDependencies != null) { Util.AddAssembliesToStringCollection(parser.AssemblyDependencies, compilerParameters.ReferencedAssemblies); } // Make any fix up adjustments to the CompilerParameters to work around some issues AssemblyBuilder.FixUpCompilerParameters(compConfig, codeDomProviderType, compilerParameters); return(buildProvider); }
private void AddBuildProviders(bool retryIfDeletionHappens) { DiskBuildResultCache.ResetAssemblyDeleted(); foreach (VirtualFile vfile in _vdir.Files) { // If it's already built and up to date, skip it BuildResult result = null; try { result = BuildManager.GetVPathBuildResultFromCache(vfile.VirtualPathObject); } catch { // Ignore the cached error in batch compilation mode, since we want to compile // as many files as possible. // But don't ignore it in CBM or precompile cases, since we always want to try // to compile everything that had failed before. if (!BuildManager.PerformingPrecompilation) { // Skip it if an exception occurs (e.g. if a compile error was cached for it) continue; } } if (result != null) { continue; } BuildProvider buildProvider = BuildManager.CreateBuildProvider(vfile.VirtualPathObject, _compConfig, _referencedAssemblies, false /*failIfUnknown*/); // Non-supported file type if (buildProvider == null) { continue; } // IgnoreFileBuildProvider's should never be created Debug.Assert(!(buildProvider is IgnoreFileBuildProvider)); _buildProviders[vfile.VirtualPath] = buildProvider; } // If an assembly had to be deleted/renamed as a result of calling GetVPathBuildResultFromCache, // me way need to run the AddBuildProviders logic again. The reason is that as a result of // deleting the assembly, we may have invalidated other BuildResult that we had earlier found // to be up to date (VSWhidbey 269297) if (DiskBuildResultCache.InUseAssemblyWasDeleted) { Debug.Assert(retryIfDeletionHappens); // Only retry if we're doing precompilation. For standard batching, we can live // with the fact that not everything will be built after we're done (and we want to // be done as quickly as possible since the user is waiting). if (retryIfDeletionHappens && BuildManager.PerformingPrecompilation) { Debug.Trace("WebDirectoryBatchCompiler", "Rerunning AddBuildProviders for '" + _vdir.VirtualPath + "' because an assembly was out of date."); // Pass false for retryIfDeletionHappens to make sure we don't get in an // infinite recursion. AddBuildProviders(false /*retryIfDeletionHappens*/); } } }
private void ProcessDirectoryRecursive(VirtualDirectory vdir, bool topLevel) { // If it's a WebReferences directory, handle it using a single WebReferencesBuildProvider // instead of creating a different BuildProvider for each file. if (_dirType == CodeDirectoryType.WebReferences) { // Create a build provider for the current directory BuildProvider buildProvider = new WebReferencesBuildProvider(vdir); buildProvider.SetVirtualPath(vdir.VirtualPathObject); _buildProviders.Add(buildProvider); AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.WebReferences); } else if (_dirType == CodeDirectoryType.AppResources) { AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.GlobalResources); } else if (_dirType == CodeDirectoryType.LocalResources) { AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.LocalResources); } else if (_dirType == CodeDirectoryType.MainCode || _dirType == CodeDirectoryType.SubCode) { AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.Code); } // Go through all the files in the directory foreach (VirtualFileBase child in vdir.Children) { if (child.IsDirectory) { // If we are at the top level of this code directory, and the current // subdirectory is in the exclude list, skip it if (topLevel && _excludedSubdirectories != null && _excludedSubdirectories.Contains(child.Name)) { continue; } // Exclude the special FrontPage directory (VSWhidbey 116727) if (child.Name == "_vti_cnf") { continue; } ProcessDirectoryRecursive(child as VirtualDirectory, false /*topLevel*/); continue; } // Don't look at individual files for WebReferences directories if (_dirType == CodeDirectoryType.WebReferences) { continue; } // Skip neutral files if _onlyBuildLocalizedResources is true if (IsResourceCodeDirectoryType(_dirType)) { if (_onlyBuildLocalizedResources && System.Web.UI.Util.GetCultureName(child.VirtualPath) == null) { continue; } } BuildProvider buildProvider = BuildManager.CreateBuildProvider(child.VirtualPathObject, (IsResourceCodeDirectoryType(_dirType)) ? BuildProviderAppliesTo.Resources : BuildProviderAppliesTo.Code, _bpc.CompConfig, _bpc.ReferencedAssemblies, false /*failIfUnknown*/); // Non-supported file type if (buildProvider == null) { continue; } // For Page resources, don't generate a strongly typed class if (_dirType == CodeDirectoryType.LocalResources && buildProvider is BaseResourcesBuildProvider) { ((BaseResourcesBuildProvider)buildProvider).DontGenerateStronglyTypedClass(); } _buildProviders.Add(buildProvider); } }