private NuGetPackageManager CreatePackageManager(NuGetPluginProject <TMeta> project)
 {
     return(new NuGetPackageManager(
                _sourceRepositories,
                _settings,
                this,
                new NuGetDeleteOnRestartManager())
     {
         PackagesFolderNuGetProject = project
     });
 }
        public async Task <bool> InstallPluginAsync(
            PackageIdentity packageIdentity,
            TMeta metadata = default,
            bool allowPrereleaseVersions        = false,
            CancellationToken cancellationToken = default)
        {
            if (_projectMap.ContainsKey(packageIdentity.Id))
            {
                throw new ArgumentException($"Project {packageIdentity.Id} already exists");
            }

            NuGetPluginProject <TMeta> project;

            using (var pluginInstallSession = _pluginRepo.AddPlugin(packageIdentity, metadata))
            {
                project = new NuGetPluginProject <TMeta>(
                    CreatePackageManager,
                    _currentFramework,
                    _packageDirPath,
                    _pluginHomeDirPath,
                    pluginInstallSession.Plugin,
                    false);

                await project.InstallPluginAsync(
                    NuGetProjectContext,
                    _sourceRepositories.GetRepositories(),
                    allowPrereleaseVersions,
                    cancellationToken);

                pluginInstallSession.Success = true;
            }

            _projectMap[packageIdentity.Id] = project;

            return(await _pluginRepo.SaveAsync());
        }