mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Preventing ProbingExtensionLoader from copying the asp.net temporarty assembly
If loaded by name in the PrecompiledLoader then the Fusion engine threw an exception as the manifest name would not match the assembly name. Actually the ASP.NET temp folder is cached using the hash of the compilation unit which is the .csproj in our case, so it won't be rebuilt accross restarts, unless necessary. --HG-- branch : 1.x
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Orchard.Caching;
|
|
||||||
using Orchard.Environment.Extensions.Compilers;
|
using Orchard.Environment.Extensions.Compilers;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
using Orchard.FileSystems.Dependencies;
|
using Orchard.FileSystems.Dependencies;
|
||||||
@@ -13,8 +12,8 @@ using Orchard.Utility.Extensions;
|
|||||||
|
|
||||||
namespace Orchard.Environment.Extensions.Loaders {
|
namespace Orchard.Environment.Extensions.Loaders {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// In case <see cref="DynamicExtensionLoader"/> is disabled, this loader will dynamically compile the assembly
|
/// In case <see cref="DynamicExtensionLoader"/> is disabled, this loader will dynamically compile the assembly.
|
||||||
/// and save a copy to the probing folder so that next restart doesn't need to compile it again.
|
/// It won't monitor the filesystem.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProbingExtensionLoader : ExtensionLoaderBase {
|
public class ProbingExtensionLoader : ExtensionLoaderBase {
|
||||||
public static readonly string[] ExtensionsVirtualPathPrefixes = { "~/Modules/", "~/Themes/" };
|
public static readonly string[] ExtensionsVirtualPathPrefixes = { "~/Modules/", "~/Themes/" };
|
||||||
@@ -23,13 +22,11 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||||
private readonly IHostEnvironment _hostEnvironment;
|
private readonly IHostEnvironment _hostEnvironment;
|
||||||
private readonly IAssemblyProbingFolder _assemblyProbingFolder;
|
private readonly IAssemblyProbingFolder _assemblyProbingFolder;
|
||||||
private readonly IDependenciesFolder _dependenciesFolder;
|
|
||||||
private readonly IProjectFileParser _projectFileParser;
|
private readonly IProjectFileParser _projectFileParser;
|
||||||
|
|
||||||
public ProbingExtensionLoader(
|
public ProbingExtensionLoader(
|
||||||
IBuildManager buildManager,
|
IBuildManager buildManager,
|
||||||
IVirtualPathProvider virtualPathProvider,
|
IVirtualPathProvider virtualPathProvider,
|
||||||
IVirtualPathMonitor virtualPathMonitor,
|
|
||||||
IHostEnvironment hostEnvironment,
|
IHostEnvironment hostEnvironment,
|
||||||
IAssemblyProbingFolder assemblyProbingFolder,
|
IAssemblyProbingFolder assemblyProbingFolder,
|
||||||
IDependenciesFolder dependenciesFolder,
|
IDependenciesFolder dependenciesFolder,
|
||||||
@@ -41,7 +38,6 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
_hostEnvironment = hostEnvironment;
|
_hostEnvironment = hostEnvironment;
|
||||||
_assemblyProbingFolder = assemblyProbingFolder;
|
_assemblyProbingFolder = assemblyProbingFolder;
|
||||||
_projectFileParser = projectFileParser;
|
_projectFileParser = projectFileParser;
|
||||||
_dependenciesFolder = dependenciesFolder;
|
|
||||||
|
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
}
|
}
|
||||||
@@ -122,7 +118,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
if (StringComparer.OrdinalIgnoreCase.Equals(Path.GetExtension(reference.VirtualPath), ".dll"))
|
if (StringComparer.OrdinalIgnoreCase.Equals(Path.GetExtension(reference.VirtualPath), ".dll"))
|
||||||
result = _assemblyProbingFolder.LoadAssembly(reference.Name);
|
result = _assemblyProbingFolder.LoadAssembly(reference.Name);
|
||||||
else {
|
else {
|
||||||
result = ProbeAssembly(reference.Name, reference.VirtualPath);
|
result = CompileAssembly(reference.Name, reference.VirtualPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Information("Done loading reference '{0}'", reference.Name);
|
Logger.Information("Done loading reference '{0}'", reference.Name);
|
||||||
@@ -163,7 +159,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
if (projectPath == null)
|
if (projectPath == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
assembly = ProbeAssembly(descriptor.Id, projectPath);
|
assembly = CompileAssembly(descriptor.Id, projectPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (assembly == null)
|
if (assembly == null)
|
||||||
@@ -178,60 +174,13 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddDependencies(string projectPath, HashSet<string> currentSet) {
|
private Assembly CompileAssembly(string moduleName, string virtualPath) {
|
||||||
// Skip files from locations other than "~/Modules" and "~/Themes"
|
|
||||||
if (string.IsNullOrEmpty(PrefixMatch(projectPath, ExtensionsVirtualPathPrefixes))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add project path
|
|
||||||
currentSet.Add(projectPath);
|
|
||||||
|
|
||||||
// Add source file paths
|
|
||||||
var projectFile = _projectFileParser.Parse(projectPath);
|
|
||||||
string basePath = _virtualPathProvider.GetDirectoryName(projectPath);
|
|
||||||
currentSet.UnionWith(projectFile.SourceFilenames.Select(f => _virtualPathProvider.Combine(basePath, f)));
|
|
||||||
|
|
||||||
// Add Project and Library references
|
|
||||||
if (projectFile.References != null) {
|
|
||||||
foreach (ReferenceDescriptor referenceDescriptor in projectFile.References.Where(reference => !string.IsNullOrEmpty(reference.Path))) {
|
|
||||||
string path = referenceDescriptor.ReferenceType == ReferenceType.Library
|
|
||||||
? _virtualPathProvider.GetProjectReferenceVirtualPath(projectPath, referenceDescriptor.SimpleName, referenceDescriptor.Path)
|
|
||||||
: _virtualPathProvider.Combine(basePath, referenceDescriptor.Path);
|
|
||||||
|
|
||||||
// Normalize the virtual path (avoid ".." in the path name)
|
|
||||||
if (!string.IsNullOrEmpty(path)) {
|
|
||||||
path = _virtualPathProvider.ToAppRelative(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to reference the project / library file
|
|
||||||
if (!string.IsNullOrEmpty(path) && !currentSet.Contains(path) && _virtualPathProvider.TryFileExists(path)) {
|
|
||||||
switch (referenceDescriptor.ReferenceType) {
|
|
||||||
case ReferenceType.Project:
|
|
||||||
AddDependencies(path, currentSet);
|
|
||||||
break;
|
|
||||||
case ReferenceType.Library:
|
|
||||||
currentSet.Add(path);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Assembly ProbeAssembly(string moduleName, string virtualPath) {
|
|
||||||
var assembly = _buildManager.GetCompiledAssembly(virtualPath);
|
var assembly = _buildManager.GetCompiledAssembly(virtualPath);
|
||||||
if (assembly != null) {
|
//if (assembly != null) {
|
||||||
_assemblyProbingFolder.StoreAssembly(moduleName, assembly.Location);
|
// _assemblyProbingFolder.StoreAssembly(moduleName, assembly.Location);
|
||||||
return assembly;
|
//}
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return assembly;
|
||||||
}
|
|
||||||
|
|
||||||
private static string PrefixMatch(string virtualPath, params string[] prefixes) {
|
|
||||||
return prefixes
|
|
||||||
.FirstOrDefault(p => virtualPath.StartsWith(p, StringComparison.OrdinalIgnoreCase));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetProjectPath(ExtensionDescriptor descriptor) {
|
private string GetProjectPath(ExtensionDescriptor descriptor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user