Exemplo n.º 1
0
        public override int Execute()
        {
            var projectFilePath = string.Empty;

            if (!File.Exists(_fileOrDirectory))
            {
                projectFilePath = MsbuildProject.GetProjectFileFromDirectory(_fileOrDirectory).FullName;
            }
            else
            {
                projectFilePath = _fileOrDirectory;
            }

            var tempDgFilePath = string.Empty;

            if (!_appliedCommand.HasOption("no-restore"))
            {
                // Create a Dependency Graph file for the project
                tempDgFilePath = Path.GetTempFileName();
                GetProjectDependencyGraph(projectFilePath, tempDgFilePath);
            }

            var result = NuGetCommand.Run(
                TransformArgs(
                    _packageId,
                    tempDgFilePath,
                    projectFilePath));

            DisposeTemporaryFile(tempDgFilePath);

            return(result);
        }
Exemplo n.º 2
0
        public override int Run(string fileOrDirectory)
        {
            if (_packageNameArgument.Values.Count != 1 || string.IsNullOrWhiteSpace(_packageNameArgument.Value) || RemainingArguments.Count > 0)
            {
                throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference);
            }

            var projectFilePath = string.Empty;

            if (!File.Exists(fileOrDirectory))
            {
                projectFilePath = MsbuildProject.GetProjectFileFromDirectory(fileOrDirectory).FullName;
            }
            else
            {
                projectFilePath = fileOrDirectory;
            }

            var tempDgFilePath = string.Empty;

            if (!_noRestoreOption.HasValue())
            {
                // Create a Dependency Graph file for the project
                tempDgFilePath = Path.GetTempFileName();
                GetProjectDependencyGraph(projectFilePath, tempDgFilePath);
            }

            var result = NuGetCommand.Run(TransformArgs(_packageNameArgument.Value, tempDgFilePath, projectFilePath));

            DisposeTemporaryFile(tempDgFilePath);

            return(result);
        }
Exemplo n.º 3
0
        public override int Execute()
        {
            SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory);

            if (_appliedCommand.Arguments.Count == 0)
            {
                throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd);
            }

            PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.CouldNotFindProjectOrDirectory, true);

            var fullProjectPaths = _appliedCommand.Arguments.Select(p => {
                var fullPath = Path.GetFullPath(p);
                return(Directory.Exists(fullPath) ?
                       MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName :
                       fullPath);
            }).ToList();

            var preAddProjectCount = slnFile.Projects.Count;

            foreach (var fullProjectPath in fullProjectPaths)
            {
                slnFile.AddProject(fullProjectPath);
            }

            if (slnFile.Projects.Count > preAddProjectCount)
            {
                slnFile.Write();
            }

            return(0);
        }
Exemplo n.º 4
0
        public override int Execute()
        {
            var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), _fileOrDirectory);
            var references  = _appliedCommand.Arguments.Select(p => {
                var fullPath = Path.GetFullPath(p);
                if (!Directory.Exists(fullPath))
                {
                    return(p);
                }

                return(Path.GetRelativePath(
                           msbuildProj.ProjectRootElement.FullPath,
                           MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName
                           ));
            });

            int numberOfRemovedReferences = msbuildProj.RemoveProjectToProjectReferences(
                _appliedCommand.ValueOrDefault <string>("framework"),
                references);

            if (numberOfRemovedReferences != 0)
            {
                msbuildProj.ProjectRootElement.Save();
            }

            return(0);
        }
Exemplo n.º 5
0
        public override int Execute()
        {
            SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory);

            var baseDirectory        = PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory);
            var relativeProjectPaths = _arguments.Select(p => {
                var fullPath = Path.GetFullPath(p);
                return(Path.GetRelativePath(
                           baseDirectory,
                           Directory.Exists(fullPath) ?
                           MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName :
                           fullPath
                           ));
            });

            bool slnChanged = false;

            foreach (var path in relativeProjectPaths)
            {
                slnChanged |= slnFile.RemoveProject(path);
            }

            slnFile.RemoveEmptyConfigurationSections();

            slnFile.RemoveEmptySolutionFolders();

            if (slnChanged)
            {
                slnFile.Write();
            }

            return(0);
        }
Exemplo n.º 6
0
        public override int Execute()
        {
            var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), _fileOrDirectory, false);
            var references  = _arguments.Select(p => {
                var fullPath = Path.GetFullPath(p);
                if (!Directory.Exists(fullPath))
                {
                    return(p);
                }

                return(Path.GetRelativePath(
                           msbuildProj.ProjectRootElement.FullPath,
                           MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName
                           ));
            });

            int numberOfRemovedReferences = msbuildProj.RemoveProjectToProjectReferences(
                _parseResult.ValueForOption <string>(RemoveProjectToProjectReferenceParser.FrameworkOption),
                references);

            if (numberOfRemovedReferences != 0)
            {
                msbuildProj.ProjectRootElement.Save();
            }

            return(0);
        }
Exemplo n.º 7
0
        public override int Execute()
        {
            var projectFilePath = string.Empty;

            if (!File.Exists(_fileOrDirectory))
            {
                projectFilePath = MsbuildProject.GetProjectFileFromDirectory(_fileOrDirectory).FullName;
            }
            else
            {
                projectFilePath = _fileOrDirectory;
            }

            var packageToRemove = _appliedCommand.Arguments.Single();
            var result          = NuGetCommand.Run(TransformArgs(packageToRemove, projectFilePath));

            return(result);
        }
Exemplo n.º 8
0
        public override int Execute()
        {
            var projectFilePath = string.Empty;

            if (!File.Exists(_fileOrDirectory))
            {
                projectFilePath = MsbuildProject.GetProjectFileFromDirectory(_fileOrDirectory).FullName;
            }
            else
            {
                projectFilePath = _fileOrDirectory;
            }

            var tempDgFilePath = string.Empty;

            if (!_appliedCommand.HasOption("no-restore"))
            {
                try
                {
                    // Create a Dependency Graph file for the project
                    tempDgFilePath = Path.GetTempFileName();
                }
                catch (IOException ioex)
                {
                    // Catch IOException from Path.GetTempFileName() and throw a graceful exception to the user.
                    throw new GracefulException(string.Format(LocalizableStrings.CmdDGFileIOException, projectFilePath), ioex);
                }

                GetProjectDependencyGraph(projectFilePath, tempDgFilePath);
            }

            var result = NuGetCommand.Run(
                TransformArgs(
                    _packageId,
                    tempDgFilePath,
                    projectFilePath));

            DisposeTemporaryFile(tempDgFilePath);

            return(result);
        }
Exemplo n.º 9
0
        public override int Execute()
        {
            SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory);

            var arguments = (_parseResult.ValueForArgument <IEnumerable <string> >(SlnAddParser.ProjectPathArgument) ?? Array.Empty <string>()).ToList().AsReadOnly();

            if (arguments.Count == 0)
            {
                throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd);
            }

            PathUtility.EnsureAllPathsExist(arguments, CommonLocalizableStrings.CouldNotFindProjectOrDirectory, true);

            var fullProjectPaths = arguments.Select(p =>
            {
                var fullPath = Path.GetFullPath(p);
                return(Directory.Exists(fullPath) ?
                       MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName :
                       fullPath);
            }).ToList();

            var preAddProjectCount = slnFile.Projects.Count;

            foreach (var fullProjectPath in fullProjectPaths)
            {
                // Identify the intended solution folders
                var solutionFolders = DetermineSolutionFolder(slnFile, fullProjectPath);

                slnFile.AddProject(fullProjectPath, solutionFolders);
            }

            if (slnFile.Projects.Count > preAddProjectCount)
            {
                slnFile.Write();
            }

            return(0);
        }
Exemplo n.º 10
0
        public override int Run(string fileOrDirectory)
        {
            if (RemainingArguments.Count != 1)
            {
                throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference);
            }

            var projectFilePath = string.Empty;

            if (!File.Exists(fileOrDirectory))
            {
                projectFilePath = MsbuildProject.GetProjectFileFromDirectory(fileOrDirectory).FullName;
            }
            else
            {
                projectFilePath = fileOrDirectory;
            }

            var packageToRemove = RemainingArguments.First();
            var result          = NuGetCommand.Run(TransformArgs(packageToRemove, projectFilePath));

            return(result);
        }