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);
     }
 }
Exemple #2
0
        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*/);
                }
            }
        }