Beispiel #1
0
        public async Task <bool> Execute(string packageId, string packageVersion)
        {
            // 0. Resolve the actual package id and version
            var packageIdAndVersion = await ResolvePackageIdAndVersion(packageId, packageVersion);

            if (packageIdAndVersion == null)
            {
                WriteError($"Failed to install {packageId}");
                return(false);
            }

            packageId      = packageIdAndVersion.Item1;
            packageVersion = packageIdAndVersion.Item2;

            WriteVerbose("Resolved package id: {0}", packageId);
            WriteVerbose("Resolved package version: {0}", packageVersion);

            // 1. Get the package without dependencies. We cannot resolve them now because
            // we don't know the target frameworks that the package supports

            FeedOptions.TargetPackagesFolder = _commandsRepository.PackagesRoot.Root;

            var temporaryProjectFileFullPath = CreateTemporaryProject(FeedOptions.TargetPackagesFolder, packageId, packageVersion);

            var packageFullPath = Path.Combine(
                _commandsRepository.PackagesRoot.Root,
                _commandsRepository.PathResolver.GetPackageDirectory(packageId, new SemanticVersion(packageVersion)));

            if (OverwriteCommands)
            {
                if (Directory.Exists(packageFullPath))
                {
                    WriteInfo($"Deleting {packageFullPath}");
                    FileOperationUtils.DeleteFolder(packageFullPath);
                    Directory.Delete(packageFullPath);
                }
            }

            try
            {
                RestoreCommand.RestoreDirectories.Add(temporaryProjectFileFullPath);
                if (!await RestoreCommand.Execute())
                {
                    return(false);
                }
            }
            finally
            {
                var folderToDelete = Path.GetDirectoryName(temporaryProjectFileFullPath);
                FileOperationUtils.DeleteFolder(folderToDelete);
                Directory.Delete(folderToDelete);
            }

            if (!ValidateApplicationPackage(packageFullPath))
            {
                return(false);
            }

            var packageAppFolder = Path.Combine(
                packageFullPath,
                InstallBuilder.CommandsFolderName);

            // 2. Now, that we have a valid app package, we can resolve its dependecies
            RestoreCommand.RestoreDirectories.Clear();
            RestoreCommand.RestoreDirectories.Add(packageAppFolder);
            if (!await RestoreCommand.Execute())
            {
                return(false);
            }

            // 3. Dependencies are in place, now let's install the commands
            if (!InstallCommands(packageId, packageFullPath))
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
 public InstallCommand(AddCommand addCmd, RestoreCommand restoreCmd)
 {
     _addCommand     = addCmd;
     _restoreCommand = restoreCmd;
 }
Beispiel #3
0
 public InstallGlobalCommand(IApplicationEnvironment env,
                             IAppCommandsRepository commandsRepository)
 {
     RestoreCommand      = new RestoreCommand(env);
     _commandsRepository = commandsRepository;
 }