public override void GenerateCode(AssemblyBuilder assemblyBuilder) { var context = new CompileExtensionContext { VirtualPath = this.VirtualPath, AssemblyBuilder = new AspNetAssemblyBuilder(assemblyBuilder, this) }; HostContainer.Resolve<IExtensionCompiler>().Compile(context); }
public override void GenerateCode(AssemblyBuilder assemblyBuilder) { var context = new CompileExtensionContext { VirtualPath = this.VirtualPath, AssemblyBuilder = new AspNetAssemblyBuilder(assemblyBuilder, this) }; HostContainer.Resolve <IExtensionCompiler>().Compile(context); }
public void Compile(CompileExtensionContext context) { Logger.Information("Generate code for file \"{0}\"", context.VirtualPath); var moduleName = Path.GetFileNameWithoutExtension(context.VirtualPath); var dependencyDescriptor = _dependenciesFolder.GetDescriptor(moduleName); if (dependencyDescriptor == null) return; try { var projectFileDescriptor = _projectFileParser.Parse(context.VirtualPath); // Add source files var directory = _virtualPathProvider.GetDirectoryName(context.VirtualPath); foreach (var filename in projectFileDescriptor.SourceFilenames.Select(f => _virtualPathProvider.Combine(directory, f))) { context.AssemblyBuilder.AddCodeCompileUnit(CreateCompileUnit(filename)); } var addedReferences = new HashSet<string>(StringComparer.OrdinalIgnoreCase); // Add assembly references foreach (var reference in dependencyDescriptor.References) { var referenceTemp = reference; var loader = _loaders.SingleOrDefault(l => l.Name == referenceTemp.LoaderName); if (loader == null) { Logger.Warning("Could not find loader '{0}' in active loaders", reference.LoaderName); continue; } var assembly = loader.LoadReference(reference); if (assembly == null) { Logger.Warning("Loader '{0}' could not load reference '{1}'", reference.LoaderName, reference.Name); continue; } addedReferences.Add(reference.Name); context.AssemblyBuilder.AddAssemblyReference(assembly); } _criticalErrorProvider.Clear(); // Load references specified in project file (only the ones not yet loaded) foreach (var assemblyReference in projectFileDescriptor.References) { if (addedReferences.Contains(assemblyReference.SimpleName)) continue; var assembly = _assemblyLoader.Load(assemblyReference.FullName); if (assembly != null) { context.AssemblyBuilder.AddAssemblyReference(assembly); } else { Logger.Error("Assembly reference '{0}' for project '{1}' cannot be loaded", assemblyReference.FullName, context.VirtualPath); _criticalErrorProvider.RegisterErrorMessage(T( "The assembly reference '{0}' could not be loaded for module '{1}'.\r\n\r\n" + "There are generally a few ways to solve this issue:\r\n" + "1. Install any dependent module.\r\n" + "2. Remove the assembly reference from the project file if it's not needed.\r\n" + "3. Ensure the assembly reference is present in the 'bin' directory of the module.\r\n" + "4. Ensure the assembly reference is present in the 'bin' directory of the application.\r\n" + "5. Specify the strong name of the assembly (name, version, culture, publickey) if the assembly is present in the GAC.", assemblyReference.FullName, moduleName)); throw new CoeveryCoreException(T("Assembly reference '{0}' for project '{1}' cannot be loaded", assemblyReference.FullName, context.VirtualPath)); } } } catch (Exception e) { //Note: we need to embed the "e.Message" in the exception text because // ASP.NET build manager "swallows" inner exceptions from this method. throw new CoeveryCoreException(T("Error compiling module \"{0}\" from file \"{1}\":\r\n{2}", moduleName, context.VirtualPath, e.Message), e); } }
public void Compile(CompileExtensionContext context) { Logger.Information("Generate code for file \"{0}\"", context.VirtualPath); var moduleName = Path.GetFileNameWithoutExtension(context.VirtualPath); var dependencyDescriptor = _dependenciesFolder.GetDescriptor(moduleName); if (dependencyDescriptor == null) { return; } try { var projectFileDescriptor = _projectFileParser.Parse(context.VirtualPath); // Add source files var directory = _virtualPathProvider.GetDirectoryName(context.VirtualPath); foreach (var filename in projectFileDescriptor.SourceFilenames.Select(f => _virtualPathProvider.Combine(directory, f))) { context.AssemblyBuilder.AddCodeCompileUnit(CreateCompileUnit(filename)); } var addedReferences = new HashSet <string>(StringComparer.OrdinalIgnoreCase); // Add assembly references foreach (var reference in dependencyDescriptor.References) { var referenceTemp = reference; var loader = _loaders.SingleOrDefault(l => l.Name == referenceTemp.LoaderName); if (loader == null) { Logger.Warning("Could not find loader '{0}' in active loaders", reference.LoaderName); continue; } var assembly = loader.LoadReference(reference); if (assembly == null) { Logger.Warning("Loader '{0}' could not load reference '{1}'", reference.LoaderName, reference.Name); continue; } addedReferences.Add(reference.Name); context.AssemblyBuilder.AddAssemblyReference(assembly); } _criticalErrorProvider.Clear(); // Load references specified in project file (only the ones not yet loaded) foreach (var assemblyReference in projectFileDescriptor.References) { if (addedReferences.Contains(assemblyReference.SimpleName)) { continue; } var assembly = _assemblyLoader.Load(assemblyReference.FullName); if (assembly != null) { context.AssemblyBuilder.AddAssemblyReference(assembly); } else { Logger.Error("Assembly reference '{0}' for project '{1}' cannot be loaded", assemblyReference.FullName, context.VirtualPath); _criticalErrorProvider.RegisterErrorMessage(T( "The assembly reference '{0}' could not be loaded for module '{1}'.\r\n\r\n" + "There are generally a few ways to solve this issue:\r\n" + "1. Install any dependent module.\r\n" + "2. Remove the assembly reference from the project file if it's not needed.\r\n" + "3. Ensure the assembly reference is present in the 'bin' directory of the module.\r\n" + "4. Ensure the assembly reference is present in the 'bin' directory of the application.\r\n" + "5. Specify the strong name of the assembly (name, version, culture, publickey) if the assembly is present in the GAC.", assemblyReference.FullName, moduleName)); throw new CoeveryCoreException(T("Assembly reference '{0}' for project '{1}' cannot be loaded", assemblyReference.FullName, context.VirtualPath)); } } } catch (Exception e) { //Note: we need to embed the "e.Message" in the exception text because // ASP.NET build manager "swallows" inner exceptions from this method. throw new CoeveryCoreException(T("Error compiling module \"{0}\" from file \"{1}\":\r\n{2}", moduleName, context.VirtualPath, e.Message), e); } }