public BuildManagerCacheItem(Assembly assembly, BuildProvider bp, CompilerResults results) { this.BuiltAssembly = assembly; this.CompiledCustomString = bp.GetCustomString(results); this.VirtualPath = bp.VirtualPath; this.Type = bp.GetGeneratedType(results); }
private bool IsBuildProviderSkipable(BuildProvider buildProvider) { // If another build provider depends on it, we should not skip it if (buildProvider.IsDependedOn) { return(false); } // No one depends on it (at least in this directory) // If it's a source file, skip it. We need to do this for v1 compatibility, // since v1 VS projects contain many source files which have already been // precompiled into bin, and that should not be compiled dynamically if (buildProvider is SourceFileBuildProvider) { return(true); } // For the same reason, skip resources if (buildProvider is ResXBuildProvider) { return(true); } return(false); }
// // Helper methods // internal static CompilerType GetCompilerTypeFromBuildProvider( BuildProvider buildProvider) { HttpContext context = null; if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure) && (context = HttpContext.Current) != null) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_PARSE_ENTER, context.WorkerRequest); } try { CompilerType compilerType = buildProvider.CodeCompilerType; if (compilerType != null) { CompilationUtil.CheckCompilerOptionsAllowed(compilerType.CompilerParameters.CompilerOptions, false /*config*/, null, 0); } return(compilerType); } finally { if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure) && context != null) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_PARSE_LEAVE, context.WorkerRequest); } } }
Type GetBuildProviderCodeDomType(BuildProvider bp) { CompilerType ct = bp.CodeCompilerType; if (ct == null) { string language = bp.LanguageName; if (String.IsNullOrEmpty(language)) { language = CompilationSection.DefaultLanguage; } ct = BuildManager.GetDefaultCompilerTypeForLanguage(language, CompilationSection, false); } Type ret = ct != null ? ct.CodeDomProviderType : null; if (ret == null) { throw new HttpException("Unable to determine code compilation language provider for virtual path '" + bp.VirtualPath + "'."); } return(ret); }
bool IsDependency(BuildProvider bp1, BuildProvider bp2) { IDictionary <string, bool> deps = bp1.ExtractDependencies(); if (deps == null) { return(false); } if (deps.ContainsKey(bp2.VirtualPath)) { return(true); } BuildProvider bp; // It won't loop forever as by the time this method is called, we are sure there are no cycles foreach (var dep in deps) { if (!buildProviders.TryGetValue(dep.Key, out bp)) { continue; } if (IsDependency(bp, bp2)) { return(true); } } return(false); }
bool IsDependencyCycle(BuildProvider buildProvider) { var cache = new Dictionary <BuildProvider, bool> (); cache.Add(buildProvider, true); return(IsDependencyCycle(cache, buildProvider.ExtractDependencies())); }
public BuildManagerCacheItem (Assembly assembly, BuildProvider bp, CompilerResults results) { this.BuiltAssembly = assembly; this.CompiledCustomString = bp.GetCustomString (results); this.VirtualPath = bp.VirtualPath; this.Type = bp.GetGeneratedType (results); }
List <BuildProviderGroup> GetSingleBuildProviderGroup(BuildProvider bp) { var ret = new List <BuildProviderGroup> (); var group = new BuildProviderGroup(); group.AddProvider(bp); ret.Add(group); return(ret); }
public void GenerateCode(AssemblyBuilder assemblyBuilder, Stream xamlStream, BuildProvider buildProvider) { object serviceObject = WorkflowServiceHostFactory.LoadXaml(xamlStream); WorkflowService workflowService = serviceObject as WorkflowService; if (workflowService != null && workflowService.Body != null) { string activityName; if (this.TryGenerateSource(assemblyBuilder, buildProvider, workflowService, false, null, out activityName)) { this.generatedPrimaryTypeName = GeneratedNamespace + "." + activityName + ExpressionRootFactorySuffix; } // find all supported versions xamlx files, load and compile them IList<Tuple<string, Stream>> streams = null; string xamlVirtualFile = GetXamlVirtualPath(buildProvider); string xamlFileName = Path.GetFileNameWithoutExtension(VirtualPathUtility.GetFileName(xamlVirtualFile)); WorkflowServiceHostFactory.GetSupportedVersionStreams(xamlFileName, out streams); if (streams != null) { try { foreach (Tuple<string, Stream> stream in streams) { try { WorkflowService service = WorkflowServiceHostFactory.CreatetWorkflowService(stream.Item2, workflowService.Name); if (service != null && service.Body != null) { this.TryGenerateSource(assemblyBuilder, buildProvider, service, true, stream.Item1, out activityName); } } catch (Exception e) { Exception newException; if (Fx.IsFatal(e) || !WorkflowServiceHostFactory.TryWrapSupportedVersionException(stream.Item1, e, out newException)) { throw; } throw FxTrace.Exception.AsError(newException); } } } finally { foreach (Tuple<string, Stream> stream in streams) { stream.Item2.Dispose(); } } } } }
// // Return a 'friendly' string that identifies the build provider // internal static string GetDisplayName(BuildProvider buildProvider) { // If it has a VirtualPath, use it if (buildProvider.VirtualPath != null) { return(buildProvider.VirtualPath); } // Otherwise, the best we can do is the type name return(buildProvider.GetType().Name); }
internal void AddBuildProviderDependency(BuildProvider dependentBuildProvider) { if (_buildProviderDependencies == null) { _buildProviderDependencies = new BuildProviderSet(); } _buildProviderDependencies.Add(dependentBuildProvider); dependentBuildProvider.flags[isDependedOn] = true; }
public void AddCodeCompileUnit(BuildProvider buildProvider, CodeCompileUnit compileUnit) { if (buildProvider == null) { throw new ArgumentNullException("buildProvider"); } if (compileUnit == null) { throw new ArgumentNullException("compileUnit"); } units.Add(CheckForPartialTypes(new CodeUnit(buildProvider, compileUnit))); }
void AddPathToBuilderMap(string path, BuildProvider bp) { if (path_to_buildprovider == null) { path_to_buildprovider = new Dictionary <string, BuildProvider> (); } if (path_to_buildprovider.ContainsKey(path)) { return; } path_to_buildprovider.Add(path, bp); }
public TextWriter CreateCodeFile(BuildProvider buildProvider) { if (buildProvider == null) { throw new ArgumentNullException("buildProvider"); } // Generate a file name with the correct source language extension string filename = GetTempFilePhysicalPath(provider.FileExtension); SourceFiles.Add(filename); AddPathToBuilderMap(filename, buildProvider); return(new StreamWriter(File.OpenWrite(filename))); }
void AddVirtualFile(VirtualFile file, BuildProviderCollection bpcoll) { if (file == null || BuildManager.IgnoreVirtualPath(file.VirtualPath)) { return; } BuildProvider bp = GetBuildProvider(file.VirtualPath, bpcoll); if (bp == null) { return; } AddBuildProvider(bp); }
internal static Type GetBuildProviderTypeFromExtension(CompilationSection config, string extension, BuildProviderAppliesTo neededFor, bool failIfUnknown) { BuildProviderInfo providerInfo = BuildProvider.GetBuildProviderInfo(config, extension); Type buildProviderType = null; // Never return an IgnoreFileBuildProvider/ForceCopyBuildProvider, since it's just a marker if (providerInfo != null && providerInfo.Type != typeof(IgnoreFileBuildProvider) && providerInfo.Type != typeof(ForceCopyBuildProvider)) { buildProviderType = providerInfo.Type; } // In updatable precomp mode, only aspx/ascx/master web files need processing. Ignore the rest. if (neededFor == BuildProviderAppliesTo.Web && BuildManager.PrecompilingForUpdatableDeployment && !typeof(BaseTemplateBuildProvider).IsAssignableFrom(buildProviderType)) { buildProviderType = null; } if (buildProviderType != null) { // Only return it if it applies to what it's needed for if ((neededFor & providerInfo.AppliesTo) != 0) { return(buildProviderType); } } // If the extension is registered as a compiler extension, use // a SourceFileBuildProvider to handle it (not supported in Resources directory) else if (neededFor != BuildProviderAppliesTo.Resources && config.GetCompilerInfoFromExtension(extension, false /*throwOnFail*/) != null) { return(typeof(SourceFileBuildProvider)); } if (failIfUnknown) { throw new HttpException(SR.GetString(SR.Unknown_buildprovider_extension, extension, neededFor.ToString())); } return(null); }
bool AddBuildProvider(BuildProvider buildProvider) { if (buildProviders == null) { buildProviders = new Dictionary <string, BuildProvider> (dictionaryComparer); } string bpPath = buildProvider.VirtualPath; if (buildProviders.ContainsKey(bpPath)) { return(false); } buildProviders.Add(bpPath, buildProvider); return(true); }
BuildProvider GetBuildProviderFor(string file, BuildProviderCollection buildProviders) { if (file == null || file.Length == 0 || buildProviders == null || buildProviders.Count == 0) { return(null); } BuildProvider ret = buildProviders.GetProviderInstanceForExtension(Path.GetExtension(file)); if (ret != null && IsCorrectBuilderType(ret)) { ret.SetVirtualPath(PhysicalToVirtual(file)); return(ret); } return(null); }
public static BuildProvider GetBuildProvider(VirtualPath virtualPath, BuildProviderCollection coll) { if (virtualPath == null || String.IsNullOrEmpty(virtualPath.Original) || coll == null) { return(null); } string extension = virtualPath.Extension; BuildProvider bp = coll.GetProviderForExtension(extension); if (bp == null) { if (String.Compare(extension, ".asax", StringComparison.OrdinalIgnoreCase) == 0) { bp = new ApplicationFileBuildProvider(); } else if (StrUtils.StartsWith(virtualPath.AppRelative, "~/App_Themes/")) { bp = new ThemeDirectoryBuildProvider(); } if (bp != null) { bp.SetVirtualPath(virtualPath); } return(bp); } object[] attrs = bp.GetType().GetCustomAttributes(typeof(BuildProviderAppliesToAttribute), true); if (attrs == null || attrs.Length == 0) { return(bp); } BuildProviderAppliesTo appliesTo = ((BuildProviderAppliesToAttribute)attrs [0]).AppliesTo; if ((appliesTo & BuildProviderAppliesTo.Web) == 0) { return(null); } bp.SetVirtualPath(virtualPath); return(bp); }
public Stream CreateEmbeddedResource(BuildProvider buildProvider, string name) { if (buildProvider == null) { throw new ArgumentNullException("buildProvider"); } if (name == null || name == "") { throw new ArgumentNullException("name"); } string filename = GetTempFilePhysicalPath("resource"); Stream stream = File.OpenWrite(filename); ResourceFiles [name] = filename; return(stream); }
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); } } } }
internal static void AddArtifactReference(AssemblyBuilder assemblyBuilder, BuildProvider prov, string virtualPath) { // add the artifact as a resource to the DLL using (Stream input = VirtualPathProvider.OpenFile(virtualPath)) { // derive the resource name string name = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPath); using (Stream resStream = assemblyBuilder.CreateEmbeddedResource(prov, name)) { int byteRead = input.ReadByte(); while (byteRead != -1) { resStream.WriteByte((byte)byteRead); byteRead = input.ReadByte(); } } } }
bool IsCorrectBuilderType(BuildProvider bp) { if (bp == null) { return(false); } Type type; object[] attrs; type = bp.GetType(); attrs = type.GetCustomAttributes(true); if (attrs == null) { return(false); } BuildProviderAppliesToAttribute bpAppliesTo; bool attributeFound = false; foreach (object attr in attrs) { bpAppliesTo = attr as BuildProviderAppliesToAttribute; if (bpAppliesTo == null) { continue; } attributeFound = true; if ((bpAppliesTo.AppliesTo & BuildProviderAppliesTo.All) == BuildProviderAppliesTo.All || (bpAppliesTo.AppliesTo & BuildProviderAppliesTo.Code) == BuildProviderAppliesTo.Code) { return(true); } } if (attributeFound) { return(false); } return(true); }
private void GetBuildResultDependencies() { foreach (BuildProvider buildProvider in _buildProviders.Values) { ICollection virtualPathDependencies = buildProvider.GetBuildResultVirtualPathDependencies(); if (virtualPathDependencies == null) { continue; } foreach (string virtualPathDependency in virtualPathDependencies) { BuildProvider dependentBuildProvider = (BuildProvider)_buildProviders[virtualPathDependency]; if (dependentBuildProvider != null) { buildProvider.AddBuildProviderDependency(dependentBuildProvider); } } } }
internal ApplicationBrowserCapabilitiesCodeGenerator(BuildProvider buildProvider) { _browserOverrides = new OrderedDictionary(); _defaultBrowserOverrides = new OrderedDictionary(); _buildProvider = buildProvider; }
private static void SetupEmbeddedResource(AssemblyBuilder assemblyBuilder, BuildProvider prov, XmlElement xmlElement, string resourceName) { using (Stream resStream = assemblyBuilder.CreateEmbeddedResource(prov, resourceName)) { EntityDesignerUtils.OutputXmlElementToStream(xmlElement, resStream); } }
void AssignToGroup(BuildProvider buildProvider, List <BuildProviderGroup> groups) { if (IsDependencyCycle(buildProvider)) { throw new HttpException("Dependency cycles are not suppported: " + buildProvider.VirtualPath); } BuildProviderGroup myGroup = null; string bpVirtualPath = buildProvider.VirtualPath; string bpPath = VirtualPathUtility.GetDirectory(bpVirtualPath); bool canAdd; if (BuildManager.HasCachedItemNoLock(buildProvider.VirtualPath)) { return; } if (buildProvider is ApplicationFileBuildProvider || buildProvider is ThemeDirectoryBuildProvider) { // global.asax and theme directory go into their own assemblies myGroup = new BuildProviderGroup(); myGroup.Standalone = true; InsertGroup(myGroup, groups); } else { Type bpCodeDomType = GetBuildProviderCodeDomType(buildProvider); foreach (BuildProviderGroup group in groups) { if (group.Standalone) { continue; } if (group.Count == 0) { myGroup = group; break; } canAdd = true; foreach (BuildProvider bp in group) { if (IsDependency(buildProvider, bp)) { canAdd = false; break; } // There should be one assembly per virtual dir if (String.Compare(bpPath, VirtualPathUtility.GetDirectory(bp.VirtualPath), stringComparer) != 0) { canAdd = false; break; } // Different languages go to different assemblies if (bpCodeDomType != null) { Type type = GetBuildProviderCodeDomType(bp); if (type != null) { if (type != bpCodeDomType) { canAdd = false; break; } } } } if (!canAdd) { continue; } myGroup = group; break; } if (myGroup == null) { myGroup = new BuildProviderGroup(); InsertGroup(myGroup, groups); } } myGroup.AddProvider(buildProvider); if (String.Compare(bpPath, virtualPathDirectory, stringComparer) == 0) { myGroup.Master = true; } }
public Stream CreateEmbeddedResource(BuildProvider buildProvider, string name) { return default(Stream); }
internal void AddCodeFile(string path, BuildProvider bp) { AddCodeFile(path, bp, false); }
public AspNetAssemblyBuilder(AssemblyBuilder assemblyBuilder, BuildProvider buildProvider) { _assemblyBuilder = assemblyBuilder; _buildProvider = buildProvider; }
void WriteCodeFile(AssemblyBuilder assemblyBuilder, BuildProvider buildProvider, string name) { using (TextWriter codeFile = assemblyBuilder.CreateCodeFile(buildProvider)) { foreach (string line in File.ReadLines(name)) { codeFile.WriteLine(line); } } }
private string GetXamlVirtualPath(BuildProvider buildProvider) { return ((System.Xaml.Hosting.XamlBuildProvider)buildProvider).VirtualPath; }
void GenerateExpressionRootFactory(AssemblyBuilder assemblyBuilder, BuildProvider buildProvider, string activityNamespace, string activityName) { CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); // namespace <%= activityNamespace %> // { // public class <%= activityName %>_ExpressionRootFactory : System.ServiceModel.Activities.WorkflowService // { // public static System.Activities.XamlIntegration.ICompiledExpressionRoot CreateExpressionRoot(System.Activities.Activity activity) // { // return new <%= activityNamespace %>.<%= activityName %>(activity); // } // } // } CodeNamespace codeNamespace = new CodeNamespace(activityNamespace); CodeTypeDeclaration codeTypeDeclaration = new CodeTypeDeclaration(activityName + ExpressionRootFactorySuffix); codeTypeDeclaration.BaseTypes.Add(new CodeTypeReference(typeof(WorkflowService))); CodeMemberMethod codeMemberMethod = new CodeMemberMethod(); codeMemberMethod.Name = CreateExpressionRootMethodName; codeMemberMethod.Attributes = MemberAttributes.Public | MemberAttributes.Static; codeMemberMethod.ReturnType = new CodeTypeReference(typeof(ICompiledExpressionRoot)); codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression( new CodeTypeReference(typeof(Activity)), ActivityParameterName)); CodeTypeReference typeRef = new CodeTypeReference(activityNamespace + "." + activityName); CodeObjectCreateExpression expr = new CodeObjectCreateExpression(typeRef, new CodeArgumentReferenceExpression(ActivityParameterName)); codeMemberMethod.Statements.Add(new CodeMethodReturnStatement(expr)); codeTypeDeclaration.Members.Add(codeMemberMethod); codeNamespace.Types.Add(codeTypeDeclaration); codeCompileUnit.Namespaces.Add(codeNamespace); assemblyBuilder.AddCodeCompileUnit(buildProvider, codeCompileUnit); }
bool TryGenerateSource(AssemblyBuilder assemblyBuilder, BuildProvider buildProvider, WorkflowService workflowService, bool isSupportedVersion, string filePath, out string activityName) { bool generatedSource; string codeFileName; this.GenerateSource(isSupportedVersion, filePath, assemblyBuilder, workflowService, out codeFileName, out generatedSource, out activityName); if (generatedSource) { this.WriteCodeFile(assemblyBuilder, buildProvider, codeFileName); this.GenerateExpressionRootFactory(assemblyBuilder, buildProvider, GeneratedNamespace, activityName); } return generatedSource; }
public TextWriter CreateCodeFile(BuildProvider buildProvider) { return default(TextWriter); }
// // Return a 'friendly' string that identifies the build provider // internal static string GetDisplayName(BuildProvider buildProvider) { // If it has a VirtualPath, use it if (buildProvider.VirtualPath != null) { return buildProvider.VirtualPath; } // Otherwise, the best we can do is the type name return buildProvider.GetType().Name; }
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); }
// // Helper methods // internal static CompilerType GetCompilerTypeFromBuildProvider( BuildProvider buildProvider) { HttpContext context = null; if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure) && (context = HttpContext.Current) != null) EtwTrace.Trace(EtwTraceType.ETW_TYPE_PARSE_ENTER, context.WorkerRequest); try { CompilerType compilerType = buildProvider.CodeCompilerType; if (compilerType != null) { CompilationUtil.CheckCompilerOptionsAllowed(compilerType.CompilerParameters.CompilerOptions, false /*config*/, null, 0); } return compilerType; } finally { if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure) && context != null) EtwTrace.Trace(EtwTraceType.ETW_TYPE_PARSE_LEAVE, context.WorkerRequest); } }
internal CodeCompileUnit GenerateCodeCompileUnit( VirtualPath virtualPath, string virtualFileString, out Type codeDomProviderType, out CompilerParameters compilerParameters, out IDictionary linePragmasTable) { // Add a pending call to make sure our thread doesn't get killed AddPendingCall(); try { BuildManager.SkipTopLevelCompilationExceptions = true; _buildManager.EnsureTopLevelFilesCompiled(); // Get the virtual file content so that we can use the correct hash code. if (virtualFileString == null) { using (Stream stream = virtualPath.OpenFile()) { TextReader reader = Util.ReaderFromStream(stream, virtualPath); virtualFileString = reader.ReadToEnd(); } } _virtualPathProvider.RegisterVirtualFile(virtualPath, virtualFileString); string cacheKey = BuildManager.GetCacheKeyFromVirtualPath(virtualPath) + "_CBMResult"; BuildResultCodeCompileUnit result = (BuildResultCodeCompileUnit)BuildManager.GetBuildResultFromCache(cacheKey, virtualPath); if (result == null) { lock (_lock) { // Don't need to check the result again since it's very unlikely in CBM scenarios. DateTime utcStart = DateTime.UtcNow; BuildProvider internalBuildProvider = GetCompilerParamsAndBuildProvider( virtualPath, out codeDomProviderType, out compilerParameters); // This is the no-compile case if (internalBuildProvider == null) { linePragmasTable = null; return(null); } CodeCompileUnit ccu = internalBuildProvider.GetCodeCompileUnit(out linePragmasTable); result = new BuildResultCodeCompileUnit(codeDomProviderType, ccu, compilerParameters, linePragmasTable); result.VirtualPath = virtualPath; result.SetCacheKey(cacheKey); FixupReferencedAssemblies(virtualPath, compilerParameters); // CodeCompileUnit could be null, do not try to fix referenced assemblies. // This happens for example when an .asmx file does not contain any code. if (ccu != null) { // VSWhidbey 501260 Add all the referenced assemblies to the CodeCompileUnit // in case the CodeDom provider needs them for code generation foreach (String assemblyString in compilerParameters.ReferencedAssemblies) { ccu.ReferencedAssemblies.Add(assemblyString); } } // Add all the dependencies, so that the ccu gets cached correctly (VSWhidbey 275091) ICollection dependencies = internalBuildProvider.VirtualPathDependencies; if (dependencies != null) { result.AddVirtualPathDependencies(dependencies); } BuildManager.CacheBuildResult(cacheKey, result, utcStart); return(ccu); } } codeDomProviderType = result.CodeDomProviderType; compilerParameters = result.CompilerParameters; linePragmasTable = result.LinePragmasTable; FixupReferencedAssemblies(virtualPath, compilerParameters); return(result.CodeCompileUnit); } finally { if (virtualFileString != null) { _virtualPathProvider.RevertVirtualFile(virtualPath); } BuildManager.SkipTopLevelCompilationExceptions = false; RemovePendingCall(); } }
internal void AddBuildProviderDependency(BuildProvider dependentBuildProvider) { if (_buildProviderDependencies == null) _buildProviderDependencies = new BuildProviderSet(); _buildProviderDependencies.Add(dependentBuildProvider); dependentBuildProvider.flags[isDependedOn] = true; }
public void AddCodeCompileUnit(BuildProvider buildProvider, CodeCompileUnit compileUnit) { BuildProvider = buildProvider; CompileUnit = compileUnit; }
public BuildProviderItem(BuildProvider bp, int listIndex, int parentIndex) { this.Provider = bp; this.ListIndex = listIndex; this.ParentIndex = parentIndex; }
// The kludge of using ICodePragmaGenerator for C# and VB code files is bad, but // it's better than allowing for potential DoS while reading a file with arbitrary // size in memory for use with the CodeSnippetCompileUnit class. // Files with extensions other than .cs and .vb use CodeSnippetCompileUnit. internal void AddCodeFile(string path, BuildProvider bp, bool isVirtual) { if (String.IsNullOrEmpty(path)) { return; } Dictionary <string, bool> codeFiles = CodeFiles; if (codeFiles.ContainsKey(path)) { return; } codeFiles.Add(path, true); string extension = Path.GetExtension(path); if (extension == null || extension.Length == 0) { return; // maybe better to throw an exception here? } extension = extension.Substring(1); string filename = GetTempFilePhysicalPath(extension); ICodePragmaGenerator pragmaGenerator; switch (extension.ToLowerInvariant()) { case "cs": pragmaGenerator = new CSharpCodePragmaGenerator(); break; case "vb": pragmaGenerator = new VBCodePragmaGenerator(); break; default: pragmaGenerator = null; break; } if (isVirtual) { VirtualFile vf = HostingEnvironment.VirtualPathProvider.GetFile(path); if (vf == null) { throw new HttpException(404, "Virtual file '" + path + "' does not exist."); } if (vf is DefaultVirtualFile) { path = HostingEnvironment.MapPath(path); } CopyFileWithChecksum(vf.Open(), filename, path, pragmaGenerator); } else { CopyFileWithChecksum(path, filename, path, pragmaGenerator); } if (pragmaGenerator != null) { if (bp != null) { AddPathToBuilderMap(filename, bp); } SourceFiles.Add(filename); } }
public List <BuildProviderGroup> Build(bool single) { if (StrUtils.StartsWith(virtualPath.AppRelative, "~/App_Themes/")) { var themebp = new ThemeDirectoryBuildProvider(); themebp.SetVirtualPath(virtualPath); return(GetSingleBuildProviderGroup(themebp)); } CompilationSection section = CompilationSection; BuildProviderCollection bpcoll = section != null ? section.BuildProviders : null; if (bpcoll == null || bpcoll.Count == 0) { return(null); } if (virtualPath.IsFake) { BuildProvider bp = GetBuildProvider(virtualPath, bpcoll); if (bp == null) { return(null); } return(GetSingleBuildProviderGroup(bp)); } if (single) { AddVirtualFile(GetVirtualFile(virtualPath.Absolute), bpcoll); } else { var cache = new Dictionary <string, bool> (dictionaryComparer); AddVirtualDir(GetVirtualDirectory(virtualPath.Absolute), bpcoll, cache); cache = null; if (buildProviders == null || buildProviders.Count == 0) { AddVirtualFile(GetVirtualFile(virtualPath.Absolute), bpcoll); } } if (buildProviders == null || buildProviders.Count == 0) { return(null); } var buildProviderGroups = new List <BuildProviderGroup> (); foreach (BuildProvider bp in buildProviders.Values) { AssignToGroup(bp, buildProviderGroups); } if (buildProviderGroups == null || buildProviderGroups.Count == 0) { buildProviderGroups = null; return(null); } // We need to reverse the order, so that the build happens from the least // dependant assemblies to the most dependant ones, more or less. buildProviderGroups.Reverse(); return(buildProviderGroups); }
public CodeUnit(BuildProvider bp, CodeCompileUnit unit) { this.BuildProvider = bp; this.Unit = unit; }
public void AddCodeCompileUnit(BuildProvider buildProvider, CodeCompileUnit compileUnit) { InnerBuilder.AddCodeCompileUnit(buildProvider, compileUnit); }
public void AddCodeCompileUnit(BuildProvider buildProvider, System.CodeDom.CodeCompileUnit compileUnit) { }