mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Using hintpath on package builder
--HG-- branch : dev
This commit is contained in:
@@ -8,14 +8,16 @@ using System.Xml.Linq;
|
|||||||
using NuGet;
|
using NuGet;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
using Orchard.FileSystems.VirtualPath;
|
||||||
using Orchard.FileSystems.WebSite;
|
using Orchard.FileSystems.WebSite;
|
||||||
|
using Orchard.Utility.Extensions;
|
||||||
using NuGetPackageBuilder = NuGet.PackageBuilder;
|
using NuGetPackageBuilder = NuGet.PackageBuilder;
|
||||||
|
|
||||||
namespace Orchard.Packaging.Services {
|
namespace Orchard.Packaging.Services {
|
||||||
[OrchardFeature("PackagingServices")]
|
[OrchardFeature("PackagingServices")]
|
||||||
public class PackageBuilder : IPackageBuilder {
|
public class PackageBuilder : IPackageBuilder {
|
||||||
private readonly IWebSiteFolder _webSiteFolder;
|
private readonly IWebSiteFolder _webSiteFolder;
|
||||||
|
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||||
|
|
||||||
private static readonly string[] _ignoredThemeExtensions = new[] {
|
private static readonly string[] _ignoredThemeExtensions = new[] {
|
||||||
"obj", "pdb", "exclude"
|
"obj", "pdb", "exclude"
|
||||||
@@ -31,8 +33,10 @@ namespace Orchard.Packaging.Services {
|
|||||||
_ignoredThemeExtensions.Contains(Path.GetExtension(filePath) ?? "");
|
_ignoredThemeExtensions.Contains(Path.GetExtension(filePath) ?? "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public PackageBuilder(IWebSiteFolder webSiteFolder) {
|
public PackageBuilder(IWebSiteFolder webSiteFolder,
|
||||||
|
IVirtualPathProvider virtualPathProvider) {
|
||||||
_webSiteFolder = webSiteFolder;
|
_webSiteFolder = webSiteFolder;
|
||||||
|
_virtualPathProvider = virtualPathProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream BuildPackage(ExtensionDescriptor extensionDescriptor) {
|
public Stream BuildPackage(ExtensionDescriptor extensionDescriptor) {
|
||||||
@@ -95,7 +99,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void EmbedReferenceFiles(CreateContext context) {
|
private void EmbedReferenceFiles(CreateContext context) {
|
||||||
var entries = context.Project
|
var entries = context.Project
|
||||||
.Elements(Ns("Project"))
|
.Elements(Ns("Project"))
|
||||||
.Elements(Ns("ItemGroup"))
|
.Elements(Ns("ItemGroup"))
|
||||||
@@ -108,13 +112,11 @@ namespace Orchard.Packaging.Services {
|
|||||||
|
|
||||||
foreach (var entry in entries) {
|
foreach (var entry in entries) {
|
||||||
var assemblyName = new AssemblyName(entry.Include.Value);
|
var assemblyName = new AssemblyName(entry.Include.Value);
|
||||||
string hintPath = entry.HintPath != null ? entry.HintPath.Value : null;
|
string virtualPath = _virtualPathProvider.GetReferenceVirtualPath(context.SourcePath, assemblyName.Name, entry.HintPath != null ? entry.HintPath.Value : null);
|
||||||
|
|
||||||
string virtualPath = "bin/" + assemblyName.Name + ".dll";
|
if (!string.IsNullOrEmpty(virtualPath)) {
|
||||||
if (context.SourceFolder.FileExists(context.SourcePath + virtualPath)) {
|
|
||||||
EmbedVirtualFile(context, virtualPath, MediaTypeNames.Application.Octet);
|
EmbedVirtualFile(context, virtualPath, MediaTypeNames.Application.Octet);
|
||||||
}
|
}
|
||||||
else if (hintPath != null) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Orchard.Environment.Extensions.Models;
|
|||||||
using Orchard.FileSystems.Dependencies;
|
using Orchard.FileSystems.Dependencies;
|
||||||
using Orchard.FileSystems.VirtualPath;
|
using Orchard.FileSystems.VirtualPath;
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
namespace Orchard.Environment.Extensions.Loaders {
|
namespace Orchard.Environment.Extensions.Loaders {
|
||||||
public class DynamicExtensionLoader : ExtensionLoaderBase {
|
public class DynamicExtensionLoader : ExtensionLoaderBase {
|
||||||
@@ -94,14 +95,14 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
if (projectPath == null)
|
if (projectPath == null)
|
||||||
return Enumerable.Empty<ExtensionReferenceProbeEntry>();
|
return Enumerable.Empty<ExtensionReferenceProbeEntry>();
|
||||||
|
|
||||||
using(var stream = _virtualPathProvider.OpenFile(projectPath)) {
|
using (var stream = _virtualPathProvider.OpenFile(projectPath)) {
|
||||||
var projectFile = _projectFileParser.Parse(stream);
|
var projectFile = _projectFileParser.Parse(stream);
|
||||||
|
|
||||||
return projectFile.References.Select(r => new ExtensionReferenceProbeEntry {
|
return projectFile.References.Select(r => new ExtensionReferenceProbeEntry {
|
||||||
Descriptor = descriptor,
|
Descriptor = descriptor,
|
||||||
Loader = this,
|
Loader = this,
|
||||||
Name = r.SimpleName,
|
Name = r.SimpleName,
|
||||||
VirtualPath = GetReferenceVirtualPath(projectPath, r.SimpleName, r.Path)
|
VirtualPath = _virtualPathProvider.GetProjectReferenceVirtualPath(projectPath, r.SimpleName, r.Path)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,24 +130,6 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetReferenceVirtualPath(string projectPath, string referenceName, string hintPath) {
|
|
||||||
var path = _virtualPathProvider.GetDirectoryName(projectPath);
|
|
||||||
|
|
||||||
// Check if hint path is valid
|
|
||||||
if (!string.IsNullOrEmpty(hintPath)) {
|
|
||||||
hintPath = _virtualPathProvider.Combine(path, hintPath);
|
|
||||||
if (_virtualPathProvider.FileExists(hintPath))
|
|
||||||
return hintPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall back to bin directory
|
|
||||||
path = _virtualPathProvider.Combine(path, "bin", referenceName + ".dll");
|
|
||||||
if (_virtualPathProvider.FileExists(path))
|
|
||||||
return path;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Assembly LoadReference(DependencyReferenceDescriptor reference) {
|
public override Assembly LoadReference(DependencyReferenceDescriptor reference) {
|
||||||
// DynamicExtensionLoader has 2 types of references: assemblies from module bin directory
|
// DynamicExtensionLoader has 2 types of references: assemblies from module bin directory
|
||||||
// and .csproj.
|
// and .csproj.
|
||||||
@@ -207,7 +190,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
// Add Project and Library References
|
// Add Project and Library References
|
||||||
foreach (ReferenceDescriptor referenceDescriptor in projectFile.References.Where(reference => !string.IsNullOrEmpty(reference.Path))) {
|
foreach (ReferenceDescriptor referenceDescriptor in projectFile.References.Where(reference => !string.IsNullOrEmpty(reference.Path))) {
|
||||||
string path = referenceDescriptor.ReferenceType == ReferenceType.Library
|
string path = referenceDescriptor.ReferenceType == ReferenceType.Library
|
||||||
? GetReferenceVirtualPath(projectPath, referenceDescriptor.SimpleName, referenceDescriptor.Path)
|
? _virtualPathProvider.GetProjectReferenceVirtualPath(projectPath, referenceDescriptor.SimpleName, referenceDescriptor.Path)
|
||||||
: _virtualPathProvider.Combine(basePath, referenceDescriptor.Path);
|
: _virtualPathProvider.Combine(basePath, referenceDescriptor.Path);
|
||||||
|
|
||||||
if (_virtualPathProvider.FileExists(path)) {
|
if (_virtualPathProvider.FileExists(path)) {
|
||||||
|
|||||||
@@ -488,6 +488,7 @@
|
|||||||
<Compile Include="Messaging\Services\IMessagingChannel.cs" />
|
<Compile Include="Messaging\Services\IMessagingChannel.cs" />
|
||||||
<Compile Include="IWorkContextAccessor.cs" />
|
<Compile Include="IWorkContextAccessor.cs" />
|
||||||
<Compile Include="Utility\Extensions\ControllerExtensions.cs" />
|
<Compile Include="Utility\Extensions\ControllerExtensions.cs" />
|
||||||
|
<Compile Include="Utility\Extensions\VirtualPathProviderExtensions.cs" />
|
||||||
<Compile Include="Validation\PathValidation.cs" />
|
<Compile Include="Validation\PathValidation.cs" />
|
||||||
<Compile Include="WorkContextExtensions.cs" />
|
<Compile Include="WorkContextExtensions.cs" />
|
||||||
<Compile Include="Mvc\ViewEngines\Razor\RazorCompilationEventsShim.cs" />
|
<Compile Include="Mvc\ViewEngines\Razor\RazorCompilationEventsShim.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using Orchard.FileSystems.VirtualPath;
|
||||||
|
|
||||||
|
namespace Orchard.Utility.Extensions {
|
||||||
|
public static class VirtualPathProviderExtensions {
|
||||||
|
public static string GetProjectReferenceVirtualPath(this IVirtualPathProvider virtualPathProvider, string projectPath, string referenceName, string hintPath) {
|
||||||
|
|
||||||
|
string basePath = virtualPathProvider.GetDirectoryName(projectPath);
|
||||||
|
string virtualPath = virtualPathProvider.GetReferenceVirtualPath(basePath, referenceName, hintPath);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(virtualPath)) {
|
||||||
|
return virtualPathProvider.Combine(basePath, virtualPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetReferenceVirtualPath(this IVirtualPathProvider virtualPathProvider, string basePath, string referenceName, string hintPath) {
|
||||||
|
// Check if hint path is valid
|
||||||
|
if (!string.IsNullOrEmpty(hintPath)) {
|
||||||
|
if (virtualPathProvider.FileExists(virtualPathProvider.Combine(basePath, hintPath)))
|
||||||
|
return hintPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to bin directory
|
||||||
|
string relativePath = virtualPathProvider.Combine("bin", referenceName + ".dll");
|
||||||
|
if (virtualPathProvider.FileExists(virtualPathProvider.Combine(basePath, relativePath)))
|
||||||
|
return relativePath;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user