Пример #1
0
        internal static BuildResultCompiledGlobalAsaxType GetGlobalAsaxBuildResult(bool isPrecompiledApp)
        {
            string cacheKey = "App_global.asax";
            BuildResultCompiledGlobalAsaxType buildResultFromCache = BuildManager.GetBuildResultFromCache(cacheKey) as BuildResultCompiledGlobalAsaxType;

            if (buildResultFromCache == null)
            {
                if (isPrecompiledApp)
                {
                    return(null);
                }
                VirtualPath globalAsaxVirtualPath = BuildManager.GlobalAsaxVirtualPath;
                if (!globalAsaxVirtualPath.FileExists())
                {
                    return(null);
                }
                ApplicationBuildProvider o = new ApplicationBuildProvider();
                o.SetVirtualPath(globalAsaxVirtualPath);
                DateTime utcNow = DateTime.UtcNow;
                BuildProvidersCompiler compiler = new BuildProvidersCompiler(globalAsaxVirtualPath, BuildManager.GenerateRandomAssemblyName("App_global.asax"));
                compiler.SetBuildProviders(new SingleObjectCollection(o));
                CompilerResults results = compiler.PerformBuild();
                buildResultFromCache = (BuildResultCompiledGlobalAsaxType)o.GetBuildResult(results);
                buildResultFromCache.CacheToMemory = false;
                BuildManager.CacheBuildResult(cacheKey, buildResultFromCache, utcNow);
            }
            return(buildResultFromCache);
        }
 internal static BuildResultCompiledGlobalAsaxType GetGlobalAsaxBuildResult(bool isPrecompiledApp)
 {
     string cacheKey = "App_global.asax";
     BuildResultCompiledGlobalAsaxType buildResultFromCache = BuildManager.GetBuildResultFromCache(cacheKey) as BuildResultCompiledGlobalAsaxType;
     if (buildResultFromCache == null)
     {
         if (isPrecompiledApp)
         {
             return null;
         }
         VirtualPath globalAsaxVirtualPath = BuildManager.GlobalAsaxVirtualPath;
         if (!globalAsaxVirtualPath.FileExists())
         {
             return null;
         }
         ApplicationBuildProvider o = new ApplicationBuildProvider();
         o.SetVirtualPath(globalAsaxVirtualPath);
         DateTime utcNow = DateTime.UtcNow;
         BuildProvidersCompiler compiler = new BuildProvidersCompiler(globalAsaxVirtualPath, BuildManager.GenerateRandomAssemblyName("App_global.asax"));
         compiler.SetBuildProviders(new SingleObjectCollection(o));
         CompilerResults results = compiler.PerformBuild();
         buildResultFromCache = (BuildResultCompiledGlobalAsaxType) o.GetBuildResult(results);
         buildResultFromCache.CacheToMemory = false;
         BuildManager.CacheBuildResult(cacheKey, buildResultFromCache, utcNow);
     }
     return buildResultFromCache;
 }
        internal static BuildResultCompiledGlobalAsaxType GetGlobalAsaxBuildResult(bool isPrecompiledApp)
        {
            string cacheKey = BuildManager.GlobalAsaxAssemblyName;

            // Try the cache first, and if it's not there, compile it
            BuildResultCompiledGlobalAsaxType result = BuildManager.GetBuildResultFromCache(cacheKey) as
                                                       BuildResultCompiledGlobalAsaxType;

            if (result != null)
            {
                return(result);
            }

            // If this is a precompiled app don't attempt to compile it
            if (isPrecompiledApp)
            {
                return(null);
            }

            VirtualPath virtualPath = BuildManager.GlobalAsaxVirtualPath;

            // If global.asax doesn't exist, just ignore it
            if (!virtualPath.FileExists())
            {
                return(null);
            }

            // Compile global.asax
            ApplicationBuildProvider buildProvider = new ApplicationBuildProvider();

            buildProvider.SetVirtualPath(virtualPath);

            DateTime utcStart = DateTime.UtcNow;

            BuildProvidersCompiler bpc = new BuildProvidersCompiler(virtualPath /*configPath*/,
                                                                    BuildManager.GenerateRandomAssemblyName(BuildManager.GlobalAsaxAssemblyName));

            // Set the BuildProvider using a single item collection
            bpc.SetBuildProviders(new SingleObjectCollection(buildProvider));

            CompilerResults results = bpc.PerformBuild();

            result = (BuildResultCompiledGlobalAsaxType)buildProvider.GetBuildResult(results);

            // Top level assembliy should not be cached to memory.
            result.CacheToMemory = false;

            // Cache it for next time
            BuildManager.CacheBuildResult(cacheKey, result, utcStart);

            // Return the compiled type
            return(result);
        }
    internal static BuildResultCompiledGlobalAsaxType GetGlobalAsaxBuildResult(bool isPrecompiledApp) {

        string cacheKey = BuildManager.GlobalAsaxAssemblyName;
        
        // Try the cache first, and if it's not there, compile it
        BuildResultCompiledGlobalAsaxType result = BuildManager.GetBuildResultFromCache(cacheKey) as
            BuildResultCompiledGlobalAsaxType;
        if (result != null)
            return result;

        // If this is a precompiled app don't attempt to compile it
        if (isPrecompiledApp)
            return null;

        VirtualPath virtualPath = BuildManager.GlobalAsaxVirtualPath;

        // If global.asax doesn't exist, just ignore it
        if (!virtualPath.FileExists())
            return null;

        // Compile global.asax
        ApplicationBuildProvider buildProvider = new ApplicationBuildProvider();
        buildProvider.SetVirtualPath(virtualPath);

        DateTime utcStart = DateTime.UtcNow;

        BuildProvidersCompiler bpc = new BuildProvidersCompiler(virtualPath /*configPath*/, 
            BuildManager.GenerateRandomAssemblyName(BuildManager.GlobalAsaxAssemblyName));

        // Set the BuildProvider using a single item collection
        bpc.SetBuildProviders(new SingleObjectCollection(buildProvider));

        CompilerResults results = bpc.PerformBuild();

        result = (BuildResultCompiledGlobalAsaxType) buildProvider.GetBuildResult(results);

        // Top level assembliy should not be cached to memory.
        result.CacheToMemory = false;

        // Cache it for next time
        BuildManager.CacheBuildResult(cacheKey, result, utcStart);

        // Return the compiled type
        return result;
    }
        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 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;
    }
Пример #8
0
        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);
        }