internal virtual void RemoveAssemblyAndRelatedFiles(string assemblyName) { if (assemblyName.StartsWith("App_Web_", StringComparison.Ordinal)) { string str = assemblyName.Substring("App_Web_".Length); bool gotLock = false; try { CompilationLock.GetLock(ref gotLock); DirectoryInfo info = new DirectoryInfo(this._cacheDir); foreach (FileInfo info2 in info.GetFiles("*" + str + ".*")) { if (info2.Extension == ".dll") { string assemblyCacheKey = BuildResultCache.GetAssemblyCacheKey(info2.FullName); HttpRuntime.CacheInternal.Remove(assemblyCacheKey); RemoveAssembly(info2); StandardDiskBuildResultCache.RemoveSatelliteAssemblies(assemblyName); } else if (info2.Extension == ".delete") { CheckAndRemoveDotDeleteFile(info2); } else { TryDeleteFile(info2); } } } finally { if (gotLock) { CompilationLock.ReleaseLock(); } ShutDownAppDomainIfRequired(); } } }
/* * Delete an assembly and all its related files. The assembly is typically named * something like ASPNET.jnw_y10n.dll, while related files are simply jnw_y10n.*. */ internal virtual void RemoveAssemblyAndRelatedFiles(string assemblyName) { Debug.Trace("DiskBuildResultCache", "RemoveAssemblyAndRelatedFiles(" + assemblyName + ")"); // If the name doesn't start with the prefix, the cleanup code doesn't apply if (!assemblyName.StartsWith(BuildManager.WebAssemblyNamePrefix, StringComparison.Ordinal)) { return; } // Get rid of the prefix, since related files don't have it string baseName = assemblyName.Substring(BuildManager.WebAssemblyNamePrefix.Length); bool gotLock = false; try { // Grab the compilation mutex, since we will remove generated assembly CompilationLock.GetLock(ref gotLock); DirectoryInfo directory = new DirectoryInfo(_cacheDir); // Find all the files that contain the base name FileInfo[] files = directory.GetFiles("*" + baseName + ".*"); foreach (FileInfo f in files) { if (f.Extension == ".dll") { // Notify existing buildresults that result assembly will be removed. // This is required otherwise new components can be compiled // with obsolete build results whose assembly has been removed. string assemblyKey = GetAssemblyCacheKey(f.FullName); HttpRuntime.CacheInternal.Remove(assemblyKey); // Remove the assembly RemoveAssembly(f); // Also, remove satellite assemblies that may be associated with it StandardDiskBuildResultCache.RemoveSatelliteAssemblies(assemblyName); } else if (f.Extension == dotDelete) { CheckAndRemoveDotDeleteFile(f); } else { // Remove the file, or if not possible, rename it, so it'll get // cleaned up next time by RemoveOldTempFiles() TryDeleteFile(f); } } } finally { // Always release the mutex if we had taken it if (gotLock) { CompilationLock.ReleaseLock(); } DiskBuildResultCache.ShutDownAppDomainIfRequired(); } }
private void ProcessBuildProviders() { CompilerType compilerType = null; BuildProvider firstLanguageBuildProvider = null; // First, delete all the existing satellite assemblies of the assembly // we're about to build (VSWhidbey 87022) (only if it has a fixed name) if (OutputAssemblyName != null) { Debug.Assert(!CbmGenerateOnlyMode); StandardDiskBuildResultCache.RemoveSatelliteAssemblies(OutputAssemblyName); } // List of BuildProvider's that don't ask for a specific language ArrayList languageFreeBuildProviders = null; foreach (BuildProvider buildProvider in _buildProviders) { // If it's an InternalBuildProvider, give it the assembly references early on buildProvider.SetReferencedAssemblies(_referencedAssemblies); // Instruct the internal build providers to continue processing for more parse errors. if (!BuildManager.ThrowOnFirstParseError) { InternalBuildProvider provider = buildProvider as InternalBuildProvider; if (provider != null) { provider.ThrowOnFirstParseError = false; } } // Get the language and culture CompilerType ctwp = BuildProvider.GetCompilerTypeFromBuildProvider(buildProvider); // Only look for a culture if we're supposed to (basically, in the resources directories) string cultureName = null; if (_supportLocalization) { cultureName = buildProvider.GetCultureName(); } // Is it asking for a specific language? if (ctwp != null) { // If it specifies a language, it can't also have a culture if (cultureName != null) { throw new HttpException(SR.GetString(SR.Both_culture_and_language, BuildProvider.GetDisplayName(buildProvider))); } // Do we already know the language we'll be using if (compilerType != null) { // If it's different from the current one, fail if (!ctwp.Equals(compilerType)) { throw new HttpException(SR.GetString(SR.Inconsistent_language, BuildProvider.GetDisplayName(buildProvider), BuildProvider.GetDisplayName(firstLanguageBuildProvider))); } } else { // Keep track of the build provider of error handling purpose firstLanguageBuildProvider = buildProvider; // Keep track of the language compilerType = ctwp; _assemblyBuilder = compilerType.CreateAssemblyBuilder( CompConfig, _referencedAssemblies, _generatedFilesDir, OutputAssemblyName); } } else { if (cultureName != null) { // Ignore the culture files in generate-only mode if (CbmGenerateOnlyMode) { continue; } if (_satelliteAssemblyBuilders == null) { _satelliteAssemblyBuilders = new Hashtable( StringComparer.OrdinalIgnoreCase); } // Check if we already have an assembly builder for this culture AssemblyBuilder satelliteAssemblyBuilder = (AssemblyBuilder)_satelliteAssemblyBuilders[cultureName]; // If not, create one and store it in the hashtable if (satelliteAssemblyBuilder == null) { satelliteAssemblyBuilder = CompilerType.GetDefaultAssemblyBuilder( CompConfig, _referencedAssemblies, _configPath, OutputAssemblyName); satelliteAssemblyBuilder.CultureName = cultureName; _satelliteAssemblyBuilders[cultureName] = satelliteAssemblyBuilder; } satelliteAssemblyBuilder.AddBuildProvider(buildProvider); continue; } if (_assemblyBuilder == null) { // If this provider doesn't need a specific language, and we don't know // the language yet, just keep track of it if (languageFreeBuildProviders == null) { languageFreeBuildProviders = new ArrayList(); } languageFreeBuildProviders.Add(buildProvider); continue; } } _assemblyBuilder.AddBuildProvider(buildProvider); } // If we didn't get an AssemblyBuilder, use a default if (_assemblyBuilder == null && languageFreeBuildProviders != null) { _assemblyBuilder = CompilerType.GetDefaultAssemblyBuilder( CompConfig, _referencedAssemblies, _configPath, _generatedFilesDir, OutputAssemblyName); } // Add all the language free providers (if any) to the AssemblyBuilder if (_assemblyBuilder != null && languageFreeBuildProviders != null) { foreach (BuildProvider languageFreeBuildProvider in languageFreeBuildProviders) { _assemblyBuilder.AddBuildProvider(languageFreeBuildProvider); } } }
private void ProcessBuildProviders() { CompilerType type = null; System.Web.Compilation.BuildProvider buildProvider = null; if (this.OutputAssemblyName != null) { StandardDiskBuildResultCache.RemoveSatelliteAssemblies(this.OutputAssemblyName); } ArrayList list = null; foreach (System.Web.Compilation.BuildProvider provider2 in this._buildProviders) { provider2.SetReferencedAssemblies(this._referencedAssemblies); if (!BuildManager.ThrowOnFirstParseError) { InternalBuildProvider provider3 = provider2 as InternalBuildProvider; if (provider3 != null) { provider3.ThrowOnFirstParseError = false; } } CompilerType compilerTypeFromBuildProvider = System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(provider2); string cultureName = null; if (this._supportLocalization) { cultureName = provider2.GetCultureName(); } if (compilerTypeFromBuildProvider != null) { if (cultureName != null) { throw new HttpException(System.Web.SR.GetString("Both_culture_and_language", new object[] { System.Web.Compilation.BuildProvider.GetDisplayName(provider2) })); } if (type != null) { if (!compilerTypeFromBuildProvider.Equals(type)) { throw new HttpException(System.Web.SR.GetString("Inconsistent_language", new object[] { System.Web.Compilation.BuildProvider.GetDisplayName(provider2), System.Web.Compilation.BuildProvider.GetDisplayName(buildProvider) })); } } else { buildProvider = provider2; this._assemblyBuilder = compilerTypeFromBuildProvider.CreateAssemblyBuilder(this.CompConfig, this._referencedAssemblies, this._generatedFilesDir, this.OutputAssemblyName); } } else { if (cultureName != null) { if (!this.CbmGenerateOnlyMode) { if (this._satelliteAssemblyBuilders == null) { this._satelliteAssemblyBuilders = new Hashtable(StringComparer.OrdinalIgnoreCase); } AssemblyBuilder builder = (AssemblyBuilder)this._satelliteAssemblyBuilders[cultureName]; if (builder == null) { builder = CompilerType.GetDefaultAssemblyBuilder(this.CompConfig, this._referencedAssemblies, this._configPath, this.OutputAssemblyName); builder.CultureName = cultureName; this._satelliteAssemblyBuilders[cultureName] = builder; } builder.AddBuildProvider(provider2); } continue; } if (this._assemblyBuilder == null) { if (list == null) { list = new ArrayList(); } list.Add(provider2); continue; } } this._assemblyBuilder.AddBuildProvider(provider2); } if ((this._assemblyBuilder == null) && (list != null)) { this._assemblyBuilder = CompilerType.GetDefaultAssemblyBuilder(this.CompConfig, this._referencedAssemblies, this._configPath, this._generatedFilesDir, this.OutputAssemblyName); } if ((this._assemblyBuilder != null) && (list != null)) { foreach (System.Web.Compilation.BuildProvider provider4 in list) { this._assemblyBuilder.AddBuildProvider(provider4); } } }