private static Package PreLoadPackage(PackageSession session, ILogger log, string filePath, bool isSystemPackage, PackageCollection loadedPackages, PackageLoadParameters loadParameters) { if (session == null) { throw new ArgumentNullException("session"); } if (log == null) { throw new ArgumentNullException("log"); } if (filePath == null) { throw new ArgumentNullException("filePath"); } if (loadedPackages == null) { throw new ArgumentNullException("loadedPackages"); } if (loadParameters == null) { throw new ArgumentNullException("loadParameters"); } try { var packageId = Package.GetPackageIdFromFile(filePath); // Check that the package was not already loaded, otherwise return the same instance if (session.Packages.ContainsById(packageId)) { return(session.Packages.Find(packageId)); } // Package is already loaded, use the instance if (loadedPackages.ContainsById(packageId)) { return(loadedPackages.Find(packageId)); } // Load the package without loading any assets var package = Package.LoadRaw(log, filePath); package.IsSystem = isSystemPackage; // Convert UPath to absolute (Package only) // Removed for now because it is called again in PackageSession.LoadAssembliesAndAssets (and running it twice result in dirty package) // If we remove it from here (and call it only in the other method), templates are not loaded (Because they are loaded via the package store that do not use PreLoadPackage) //if (loadParameters.ConvertUPathToAbsolute) //{ // var analysis = new PackageAnalysis(package, new PackageAnalysisParameters() // { // ConvertUPathTo = UPathType.Absolute, // SetDirtyFlagOnAssetWhenFixingAbsoluteUFile = true, // IsProcessingUPaths = true, // }); // analysis.Run(log); //} // If the package doesn't have a meta name, fix it here (This is supposed to be done in the above disabled analysis - but we still need to do it!) if (string.IsNullOrWhiteSpace(package.Meta.Name) && package.FullPath != null) { package.Meta.Name = package.FullPath.GetFileName(); package.IsDirty = true; } // Add the package has loaded before loading dependencies loadedPackages.Add(package); // Package has been loaded, register it in constraints so that we force each subsequent loads to use this one (or fails if version doesn't match) session.constraintProvider.AddConstraint(package.Meta.Name, new VersionSpec(package.Meta.Version.ToSemanticVersion())); // Load package dependencies // This will perform necessary asset upgrades // TODO: We should probably split package loading in two recursive top-level passes (right now those two passes are mixed, making it more difficult to make proper checks) // - First, load raw packages with their dependencies recursively, then resolve dependencies and constraints (and print errors/warnings) // - Then, if everything is OK, load the actual references and assets for each packages PreLoadPackageDependencies(session, log, package, loadedPackages, loadParameters); // Add the package to the session but don't freeze it yet session.Packages.Add(package); return(package); } catch (Exception ex) { log.Error("Error while pre-loading package [{0}]", ex, filePath); } return(null); }
private static Package PreLoadPackage(PackageSession session, ILogger log, string filePath, bool isSystemPackage, PackageCollection loadedPackages, PackageLoadParameters loadParameters) { if (session == null) { throw new ArgumentNullException("session"); } if (log == null) { throw new ArgumentNullException("log"); } if (filePath == null) { throw new ArgumentNullException("filePath"); } if (loadedPackages == null) { throw new ArgumentNullException("loadedPackages"); } if (loadParameters == null) { throw new ArgumentNullException("loadParameters"); } try { var packageId = Package.GetPackageIdFromFile(filePath); // Check that the package was not already loaded, otherwise return the same instance if (session.Packages.ContainsById(packageId)) { return(session.Packages.Find(packageId)); } // Package is already loaded, use the instance if (loadedPackages.ContainsById(packageId)) { return(loadedPackages.Find(packageId)); } // Load the package without loading assets var newLoadParameters = loadParameters.Clone(); newLoadParameters.AssemblyContainer = session.assemblyContainer; // Load the package var package = Package.Load(log, filePath, newLoadParameters); package.IsSystem = isSystemPackage; // Add the package has loaded before loading dependencies loadedPackages.Add(package); // Load package dependencies PreLoadPackageDependencies(session, log, package, loadedPackages, loadParameters); // Add the package to the session but don't freeze it yet session.Packages.Add(package); // Validate assets from package package.ValidateAssets(loadParameters.GenerateNewAssetIds); // Freeze the package after loading the assets session.FreezePackage(package); return(package); } catch (Exception ex) { log.Error("Error while pre-loading package [{0}]", ex, filePath); } return(null); }