/*
         * Returns an array of the assemblies defined in the bin and assembly reference config section
         */
        internal String[] GetTopLevelAssemblyReferences(VirtualPath virtualPath)
        {
            // Add a pending call to make sure our thread doesn't get killed
            AddPendingCall();

            List <Assembly> assemblyList = new List <Assembly>();

            try {
                // Treat it as relative to the app root
                virtualPath.CombineWithAppRoot();

                CompilationSection compConfig = MTConfigUtil.GetCompilationConfig(virtualPath);

                // Add all the config assemblies to the list
                foreach (AssemblyInfo assemblyInfo in compConfig.Assemblies)
                {
                    Assembly[] assemblies = assemblyInfo.AssemblyInternal;
                    for (int i = 0; i < assemblies.Length; i++)
                    {
                        if (assemblies[i] != null)
                        {
                            assemblyList.Add(assemblies[i]);
                        }
                    }
                }
            } finally {
                RemovePendingCall();
            }
            StringCollection paths = new StringCollection();

            Util.AddAssembliesToStringCollection(assemblyList, paths);
            string[] references = new string[paths.Count];
            paths.CopyTo(references, 0);
            return(references);
        }
        public void AddCodeCompileUnit(System.Web.Compilation.BuildProvider buildProvider, CodeCompileUnit compileUnit)
        {
            string str;

            this.AddChecksumPragma(buildProvider, compileUnit);
            Util.AddAssembliesToStringCollection(this._initialReferencedAssemblies, compileUnit.ReferencedAssemblies);
            Util.AddAssembliesToStringCollection(this._additionalReferencedAssemblies, compileUnit.ReferencedAssemblies);
            using (new ProcessImpersonationContext())
            {
                TextWriter writer = this.CreateCodeFile(buildProvider, out str);
                try
                {
                    this._codeProvider.GenerateCodeFromCompileUnit(compileUnit, writer, null);
                }
                finally
                {
                    writer.Flush();
                    writer.Close();
                }
            }
            if (str != null)
            {
                this._totalFileLength += this.GetFileLengthWithAssert(str);
            }
        }
Beispiel #3
0
        // Add the referenced assemblies into the compileParameters. Notice that buildProviders do not have
        // the correct referenced assemblies and we don't cache them since the assemblies could change
        // between appdomains. (removing assemblies from bin, etc)
        private void FixupReferencedAssemblies(VirtualPath virtualPath, CompilerParameters compilerParameters)
        {
            CompilationSection compConfig = MTConfigUtil.GetCompilationConfig(virtualPath);

            ICollection referencedAssemblies = BuildManager.GetReferencedAssemblies(compConfig);
            Util.AddAssembliesToStringCollection(referencedAssemblies, compilerParameters.ReferencedAssemblies);
        }
        internal string[] GetTopLevelAssemblyReferences(VirtualPath virtualPath)
        {
            this.AddPendingCall();
            List <Assembly> fromList = new List <Assembly>();

            try
            {
                virtualPath.CombineWithAppRoot();
                foreach (AssemblyInfo info in MTConfigUtil.GetCompilationConfig(virtualPath).Assemblies)
                {
                    Assembly[] assemblyInternal = info.AssemblyInternal;
                    for (int i = 0; i < assemblyInternal.Length; i++)
                    {
                        if (assemblyInternal[i] != null)
                        {
                            fromList.Add(assemblyInternal[i]);
                        }
                    }
                }
            }
            finally
            {
                this.RemovePendingCall();
            }
            StringCollection toList = new StringCollection();

            Util.AddAssembliesToStringCollection(fromList, toList);
            string[] array = new string[toList.Count];
            toList.CopyTo(array, 0);
            return(array);
        }
        internal CompilerParameters GetCompilerParameters()
        {
            CompilerParameters compilerParameters = this._compilerType.CompilerParameters;
            string             tempDir            = this._tempFiles.TempDir;

            if (this.CultureName != null)
            {
                tempDir = Path.Combine(tempDir, this.CultureName);
                Directory.CreateDirectory(tempDir);
                compilerParameters.OutputAssembly = Path.Combine(tempDir, this.OutputAssemblyName + ".resources.dll");
            }
            else
            {
                compilerParameters.OutputAssembly = Path.Combine(tempDir, this.OutputAssemblyName + ".dll");
            }
            if (File.Exists(compilerParameters.OutputAssembly))
            {
                Util.RemoveOrRenameFile(compilerParameters.OutputAssembly);
            }
            compilerParameters.TempFiles = this._tempFiles;
            if ((this._stringResourceBuilder != null) && this._stringResourceBuilder.HasStrings)
            {
                string resFileName = this._tempFiles.AddExtension("res");
                this._stringResourceBuilder.CreateResourceFile(resFileName);
                compilerParameters.Win32Resource = resFileName;
            }
            if (this._embeddedResourceFiles != null)
            {
                foreach (string str3 in (IEnumerable)this._embeddedResourceFiles)
                {
                    compilerParameters.EmbeddedResources.Add(str3);
                }
            }
            if (this._additionalReferencedAssemblies != null)
            {
                foreach (Assembly assembly in (IEnumerable)this._additionalReferencedAssemblies)
                {
                    this._initialReferencedAssemblies.Add(assembly);
                }
            }
            Util.AddAssembliesToStringCollection(this._initialReferencedAssemblies, compilerParameters.ReferencedAssemblies);
            FixUpCompilerParameters(this._compilerType.CodeDomProviderType, compilerParameters);
            return(compilerParameters);
        }
        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 FixupReferencedAssemblies(VirtualPath virtualPath, CompilerParameters compilerParameters)
 {
     Util.AddAssembliesToStringCollection(BuildManager.GetReferencedAssemblies(MTConfigUtil.GetCompilationConfig(virtualPath)), compilerParameters.ReferencedAssemblies);
 }