/// <summary> /// Initializes a new instance of the <see cref="Configurator"/> class. This overload /// allows passing in a <see cref="Preprocessor"/> that can be reused and pre-configured /// with directives not sourced from the script. /// </summary> /// <param name="engine">The engine to configure.</param> /// <param name="preprocessor">The preprocessor.</param> public Configurator(Engine engine, Preprocessor preprocessor) { _engine = engine; _preprocessor = preprocessor; _assemblyResolver = new AssemblyResolver(_scriptManager); AssemblyLoader = new AssemblyLoader(engine.FileSystem, engine.Assemblies, _assemblyResolver); PackageInstaller = new PackageInstaller(engine.FileSystem, AssemblyLoader); ClassCatalog = new ClassCatalog(); // Add this namespace and assembly engine.Namespaces.Add(typeof(ScriptBase).Namespace); engine.Assemblies.Add(typeof(ScriptBase).Assembly); }
public void InstallPackage(PackageInstaller installer, bool updatePackages, SourceRepository localSourceRepository, List <SourceRepository> sourceRepositories) { string versionString = _version == null ? string.Empty : " " + _version; Trace.Verbose($"Installing package {_packageId}{versionString} (with dependencies)"); ResolutionContext resolutionContext = new ResolutionContext( DependencyBehavior.Lowest, _allowPrereleaseVersions, _allowUnlisted, VersionConstraints.None); // Get the installed version NuGetVersion installedVersion = NuGetPackageManager.GetLatestVersionAsync(_packageId, installer.CurrentFramework, resolutionContext, localSourceRepository, installer.Logger, CancellationToken.None).Result; // Does the installed version match the requested version NuGetVersion matchingVersion = installedVersion; if (installedVersion != null && (_version == null || installedVersion == _version) && !updatePackages && !_getLatest) { Trace.Verbose($"Package {_packageId}{versionString} is satisfied by version {installedVersion}"); } else if (_version != null) { matchingVersion = _version; } else { // Get the latest version matchingVersion = NuGetPackageManager.GetLatestVersionAsync(_packageId, installer.CurrentFramework, resolutionContext, sourceRepositories, installer.Logger, CancellationToken.None).Result; } // Install the requested version (do even if we're up to date to ensure dependencies are installed) installer.PackageManager.InstallPackageAsync(installer.PackageManager.PackagesFolderNuGetProject, new PackageIdentity(_packageId, matchingVersion), resolutionContext, installer.ProjectContext, sourceRepositories, Array.Empty <SourceRepository>(), CancellationToken.None).Wait(); Trace.Verbose($"Installed package {_packageId} {matchingVersion}"); }