diff --git a/src/Umbraco.Core/Packaging/PackagesRepository.cs b/src/Umbraco.Core/Packaging/PackagesRepository.cs index a24890d5f2..90cd7433b7 100644 --- a/src/Umbraco.Core/Packaging/PackagesRepository.cs +++ b/src/Umbraco.Core/Packaging/PackagesRepository.cs @@ -414,9 +414,10 @@ namespace Umbraco.Cms.Core.Packaging root.Add(macros); - // get the partial views for macros and package those - IEnumerable views = packagedMacros.Select(x => x.MacroSource).Where(x => x.EndsWith(".cshtml")); - PackageMacroPartialViews(views, root); + // Get the partial views for macros and package those (exclude views outside of the default directory, e.g. App_Plugins\*\Views) + IEnumerable views = packagedMacros.Where(x => x.MacroSource.StartsWith(Constants.SystemDirectories.MacroPartials)) + .Select(x => x.MacroSource.Substring(Constants.SystemDirectories.MacroPartials.Length).Replace('/', '\\')); + PackageStaticFiles(views, root, "MacroPartialViews", "View", _fileSystems.MacroPartialsFileSystem); } private void PackageStylesheets(PackageDefinition definition, XContainer root) @@ -487,33 +488,6 @@ namespace Umbraco.Cms.Core.Packaging root.Add(templatesXml); } - private void PackageMacroPartialViews(IEnumerable viewPaths, XContainer root) - { - var viewsXml = new XElement("MacroPartialViews"); - foreach (var viewPath in viewPaths) - { - // TODO: See TODO note in MacrosController about the inconsistencies of usages of partial views - // and how paths are saved. We have no choice currently but to assume that all views are 100% always - // on the content path. - - var physicalPath = _hostingEnvironment.MapPathContentRoot(viewPath); - if (!File.Exists(physicalPath)) - { - throw new InvalidOperationException("Could not find partial view at path " + viewPath); - } - - var fileContents = File.ReadAllText(physicalPath, Encoding.UTF8); - - viewsXml.Add( - new XElement( - "View", - new XAttribute("path", viewPath), - new XCData(fileContents))); - } - - root.Add(viewsXml); - } - private void PackageDocumentTypes(PackageDefinition definition, XContainer root) { var contentTypes = new HashSet(); diff --git a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs index 70ce46164c..7a63701559 100644 --- a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs @@ -1270,6 +1270,17 @@ namespace Umbraco.Cms.Infrastructure.Packaging throw new InvalidOperationException("No path attribute found"); } + // Remove prefix to maintain backwards compatibility + if (path.StartsWith(Constants.SystemDirectories.MacroPartials)) + { + path = path.Substring(Constants.SystemDirectories.MacroPartials.Length); + } + else if (path.StartsWith("~")) + { + _logger.LogWarning("Importing macro partial views outside of the Views/MacroPartials directory is not supported: {Path}", path); + continue; + } + IPartialView macroPartialView = _fileService.GetPartialViewMacro(path); // only update if it doesn't exist