예제 #1
0
파일: Program.cs 프로젝트: qanon1111/cli-1
        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);
        }
예제 #2
0
파일: Program.cs 프로젝트: viniqsoares/sdk
        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);
        }
예제 #3
0
        internal static CommandLineApplication CreateApplication(CommandLineApplication parentApp)
        {
            CommandLineApplication app = parentApp.Command("p2p", throwOnUnexpectedArg: false);

            app.FullName    = LocalizableStrings.AppFullName;
            app.Description = LocalizableStrings.AppDescription;
            app.HandleRemainingArguments  = true;
            app.ArgumentSeparatorHelpText = LocalizableStrings.AppHelpText;

            app.HelpOption("-h|--help");

            CommandOption frameworkOption = app.Option(
                $"-f|--framework <{CommonLocalizableStrings.CmdFramework}>",
                LocalizableStrings.CmdFrameworkDescription,
                CommandOptionType.SingleValue);

            app.OnExecute(() => {
                try
                {
                    if (!parentApp.Arguments.Any())
                    {
                        throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, Constants.ProjectOrSolutionArgumentName);
                    }

                    var projectOrDirectory = parentApp.Arguments.First().Value;
                    if (string.IsNullOrEmpty(projectOrDirectory))
                    {
                        projectOrDirectory = PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory());
                    }

                    var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), projectOrDirectory);

                    if (app.RemainingArguments.Count == 0)
                    {
                        throw new GracefulException(LocalizableStrings.SpecifyAtLeastOneReferenceToRemove);
                    }

                    List <string> references = app.RemainingArguments;

                    int numberOfRemovedReferences = msbuildProj.RemoveProjectToProjectReferences(
                        frameworkOption.Value(),
                        references);

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

                    return(0);
                }
                catch (GracefulException e)
                {
                    Reporter.Error.WriteLine(e.Message.Red());
                    app.ShowHelp();
                    return(1);
                }
            });

            return(app);
        }
예제 #4
0
파일: Program.cs 프로젝트: serdna27/cli
        public ListProjectToProjectReferences(string fileOrDirectory)
        {
            _fileOrDirectory = fileOrDirectory;
            var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), fileOrDirectory);

            var p2ps = msbuildProj.GetProjectToProjectReferences();

            foreach (var p2p in p2ps)
            {
                _items.Add(p2p.Include);
            }
        }
예제 #5
0
        public static int Run(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false)
            {
                Name        = "dotnet list p2ps",
                FullName    = LocalizableStrings.AppFullName,
                Description = LocalizableStrings.AppDescription
            };

            app.HelpOption("-h|--help");

            CommandArgument projectArgument = app.Argument($"<{LocalizableStrings.ProjectArgumentValueName}>", LocalizableStrings.ProjectArgumentDescription);

            app.OnExecute(() => {
                if (string.IsNullOrEmpty(projectArgument.Value))
                {
                    throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, $"<{LocalizableStrings.ProjectArgumentValueName}>");
                }

                var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value);

                var p2ps = msbuildProj.GetProjectToProjectReferences();
                if (p2ps.Count() == 0)
                {
                    Reporter.Output.WriteLine(string.Format(LocalizableStrings.NoReferencesFound, CommonLocalizableStrings.P2P, projectArgument.Value));
                    return(0);
                }

                Reporter.Output.WriteLine($"{CommonLocalizableStrings.ProjectReferenceOneOrMore}");
                Reporter.Output.WriteLine(new string('-', CommonLocalizableStrings.ProjectReferenceOneOrMore.Length));
                foreach (var p2p in p2ps)
                {
                    Reporter.Output.WriteLine(p2p.Include);
                }

                return(0);
            });

            try
            {
                return(app.Execute(args));
            }
            catch (GracefulException e)
            {
                Reporter.Error.WriteLine(e.Message.Red());
                app.ShowHelp();
                return(1);
            }
        }
예제 #6
0
 private static MsbuildProject GetMSBuildProject()
 {
     try
     {
         return(MsbuildProject.FromFileOrDirectory(
                    new ProjectCollection(),
                    Directory.GetCurrentDirectory(), interactive: false));
     }
     catch (Exception e)
     {
         Report(e);
         return(null);
     }
 }
예제 #7
0
파일: Program.cs 프로젝트: zumeymedia/cli
        public override int Execute()
        {
            var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), _fileOrDirectory);

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

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

            return(0);
        }
예제 #8
0
        public override int Run(string fileOrDirectory)
        {
            var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), fileOrDirectory);

            if (RemainingArguments.Count == 0)
            {
                throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToRemove);
            }

            int numberOfRemovedReferences = msbuildProj.RemoveProjectToProjectReferences(
                _frameworkOption.Value(),
                RemainingArguments);

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

            return(0);
        }
        public override int Execute()
        {
            var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), _fileOrDirectory, false);

            var p2ps = msbuildProj.GetProjectToProjectReferences();

            if (!p2ps.Any())
            {
                Reporter.Output.WriteLine(string.Format(
                                              CommonLocalizableStrings.NoReferencesFound,
                                              CommonLocalizableStrings.P2P,
                                              _fileOrDirectory));
                return(0);
            }

            Reporter.Output.WriteLine($"{CommonLocalizableStrings.ProjectReferenceOneOrMore}");
            Reporter.Output.WriteLine(new string('-', CommonLocalizableStrings.ProjectReferenceOneOrMore.Length));
            foreach (var p2p in p2ps)
            {
                Reporter.Output.WriteLine(p2p.Include);
            }

            return(0);
        }
예제 #10
0
        public static int Run(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false)
            {
                Name                      = "dotnet remove p2p",
                FullName                  = LocalizableStrings.AppFullName,
                Description               = LocalizableStrings.AppDescription,
                AllowArgumentSeparator    = true,
                ArgumentSeparatorHelpText = LocalizableStrings.AppArgumentSeparatorHelpText
            };

            app.HelpOption("-h|--help");

            CommandArgument projectArgument = app.Argument(
                $"<{LocalizableStrings.CmdArgProject}>",
                LocalizableStrings.CmdArgumentDescription);

            CommandOption frameworkOption = app.Option(
                $"-f|--framework <{LocalizableStrings.CmdFramework}>",
                LocalizableStrings.CmdFrameworkDescription,
                CommandOptionType.SingleValue);

            app.OnExecute(() => {
                if (string.IsNullOrEmpty(projectArgument.Value))
                {
                    throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, $"<{LocalizableStrings.ProjectException}>");
                }

                var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), projectArgument.Value);

                if (app.RemainingArguments.Count == 0)
                {
                    throw new GracefulException(LocalizableStrings.SpecifyAtLeastOneReferenceToRemove);
                }

                List <string> references = app.RemainingArguments;

                int numberOfRemovedReferences = msbuildProj.RemoveProjectToProjectReferences(
                    frameworkOption.Value(),
                    references);

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

                return(0);
            });

            try
            {
                return(app.Execute(args));
            }
            catch (GracefulException e)
            {
                Reporter.Error.WriteLine(e.Message.Red());
                app.ShowHelp();
                return(1);
            }
        }
예제 #11
0
        public override int Execute()
        {
            var            projects    = new ProjectCollection();
            MsbuildProject msbuildProj = MsbuildProject.FromFileOrDirectory(projects, _fileOrDirectory);

            var frameworkString = _appliedCommand.ValueOrDefault <string>("framework");

            PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.ReferenceDoesNotExist);
            List <MsbuildProject> refs = _appliedCommand.Arguments
                                         .Select((r) => MsbuildProject.FromFile(projects, r))
                                         .ToList();

            if (frameworkString == null)
            {
                foreach (var tfm in msbuildProj.GetTargetFrameworks())
                {
                    foreach (var @ref in refs)
                    {
                        if ([email protected](tfm))
                        {
                            Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString(
                                                     @ref,
                                                     msbuildProj.GetTargetFrameworks().Select((fx) => fx.GetShortFolderName())));
                            return(1);
                        }
                    }
                }
            }
            else
            {
                var framework = NuGetFramework.Parse(frameworkString);
                if (!msbuildProj.IsTargetingFramework(framework))
                {
                    Reporter.Error.WriteLine(string.Format(
                                                 CommonLocalizableStrings.ProjectDoesNotTargetFramework,
                                                 msbuildProj.ProjectRootElement.FullPath,
                                                 frameworkString));
                    return(1);
                }

                foreach (var @ref in refs)
                {
                    if ([email protected](framework))
                    {
                        Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString(
                                                 @ref,
                                                 new string[] { frameworkString }));
                        return(1);
                    }
                }
            }

            var relativePathReferences = _appliedCommand.Arguments.Select((r) =>
                                                                          PathUtility.GetRelativePath(msbuildProj.ProjectDirectory, Path.GetFullPath(r)))
                                         .ToList();

            int numberOfAddedReferences = msbuildProj.AddProjectToProjectReferences(
                frameworkString,
                relativePathReferences);

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

            return(0);
        }
예제 #12
0
        public override int Run(string fileOrDirectory)
        {
            var            projects    = new ProjectCollection();
            MsbuildProject msbuildProj = MsbuildProject.FromFileOrDirectory(projects, fileOrDirectory);

            if (RemainingArguments.Count == 0)
            {
                throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToAdd);
            }

            string frameworkString = _frameworkOption.Value();

            PathUtility.EnsureAllPathsExist(RemainingArguments, CommonLocalizableStrings.ReferenceDoesNotExist);
            List <MsbuildProject> refs = RemainingArguments
                                         .Select((r) => MsbuildProject.FromFile(projects, r))
                                         .ToList();

            if (frameworkString == null)
            {
                foreach (var tfm in msbuildProj.GetTargetFrameworks())
                {
                    foreach (var @ref in refs)
                    {
                        if ([email protected](tfm))
                        {
                            Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString(
                                                     @ref,
                                                     msbuildProj.GetTargetFrameworks().Select((fx) => fx.GetShortFolderName())));
                            return(1);
                        }
                    }
                }
            }
            else
            {
                var framework = NuGetFramework.Parse(frameworkString);
                if (!msbuildProj.IsTargettingFramework(framework))
                {
                    Reporter.Error.WriteLine(string.Format(
                                                 CommonLocalizableStrings.ProjectDoesNotTargetFramework,
                                                 msbuildProj.ProjectRootElement.FullPath,
                                                 frameworkString));
                    return(1);
                }

                foreach (var @ref in refs)
                {
                    if ([email protected](framework))
                    {
                        Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString(
                                                 @ref,
                                                 new string[] { frameworkString }));
                        return(1);
                    }
                }
            }

            var relativePathReferences = RemainingArguments.Select((r) =>
                                                                   PathUtility.GetRelativePath(msbuildProj.ProjectDirectory, Path.GetFullPath(r))).ToList();

            int numberOfAddedReferences = msbuildProj.AddProjectToProjectReferences(
                _frameworkOption.Value(),
                relativePathReferences);

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

            return(0);
        }
예제 #13
0
        public static int Run(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false)
            {
                Name                      = "dotnet remove p2p",
                FullName                  = ".NET Remove Project to Project (p2p) reference Command",
                Description               = "Command to remove project to project (p2p) reference",
                AllowArgumentSeparator    = true,
                ArgumentSeparatorHelpText = "Project to project references to remove"
            };

            app.HelpOption("-h|--help");

            CommandArgument projectArgument = app.Argument(
                "<PROJECT>",
                "The project file to modify. If a project file is not specified," +
                " it searches the current working directory for an MSBuild file that has" +
                " a file extension that ends in `proj` and uses that file.");

            CommandOption frameworkOption = app.Option(
                "-f|--framework <FRAMEWORK>",
                "Remove reference only when targetting a specific framework",
                CommandOptionType.SingleValue);

            app.OnExecute(() => {
                if (string.IsNullOrEmpty(projectArgument.Value))
                {
                    throw new GracefulException(LocalizableStrings.RequiredArgumentNotPassed, "<Project>");
                }

                var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value);

                if (app.RemainingArguments.Count == 0)
                {
                    throw new GracefulException(LocalizableStrings.SpecifyAtLeastOneReferenceToRemove);
                }

                List <string> references = app.RemainingArguments;

                int numberOfRemovedReferences = msbuildProj.RemoveProjectToProjectReferences(
                    frameworkOption.Value(),
                    references);

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

                return(0);
            });

            try
            {
                return(app.Execute(args));
            }
            catch (GracefulException e)
            {
                Reporter.Error.WriteLine(e.Message.Red());
                app.ShowHelp();
                return(1);
            }
        }
예제 #14
0
        public override int Execute()
        {
            var            projects    = new ProjectCollection();
            bool           interactive = _parseResult.HasOption(AddProjectToProjectReferenceParser.InteractiveOption);
            MsbuildProject msbuildProj = MsbuildProject.FromFileOrDirectory(
                projects,
                _fileOrDirectory,
                interactive);

            var frameworkString = _parseResult.ValueForOption <string>(AddProjectToProjectReferenceParser.FrameworkOption);

            var arguments = _parseResult.ValueForArgument <IReadOnlyCollection <string> >(AddProjectToProjectReferenceParser.ProjectPathArgument);

            PathUtility.EnsureAllPathsExist(arguments,
                                            CommonLocalizableStrings.CouldNotFindProjectOrDirectory, true);
            List <MsbuildProject> refs =
                arguments
                .Select((r) => MsbuildProject.FromFileOrDirectory(projects, r, interactive))
                .ToList();

            if (frameworkString == null)
            {
                foreach (var tfm in msbuildProj.GetTargetFrameworks())
                {
                    foreach (var @ref in refs)
                    {
                        if ([email protected](tfm))
                        {
                            Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString(
                                                     @ref,
                                                     msbuildProj.GetTargetFrameworks().Select((fx) => fx.GetShortFolderName())));
                            return(1);
                        }
                    }
                }
            }
            else
            {
                var framework = NuGetFramework.Parse(frameworkString);
                if (!msbuildProj.IsTargetingFramework(framework))
                {
                    Reporter.Error.WriteLine(string.Format(
                                                 CommonLocalizableStrings.ProjectDoesNotTargetFramework,
                                                 msbuildProj.ProjectRootElement.FullPath,
                                                 frameworkString));
                    return(1);
                }

                foreach (var @ref in refs)
                {
                    if ([email protected](framework))
                    {
                        Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString(
                                                 @ref,
                                                 new string[] { frameworkString }));
                        return(1);
                    }
                }
            }

            var relativePathReferences = refs.Select((r) =>
                                                     Path.GetRelativePath(
                                                         msbuildProj.ProjectDirectory,
                                                         r.ProjectRootElement.FullPath)).ToList();

            int numberOfAddedReferences = msbuildProj.AddProjectToProjectReferences(
                frameworkString,
                relativePathReferences);

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

            return(0);
        }
예제 #15
0
        public static int Run(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false)
            {
                Name                      = "dotnet add p2p",
                FullName                  = LocalizableStrings.AppFullName,
                Description               = LocalizableStrings.AppDescription,
                AllowArgumentSeparator    = true,
                ArgumentSeparatorHelpText = LocalizableStrings.AppHelpText
            };

            app.HelpOption("-h|--help");

            CommandArgument projectArgument = app.Argument(
                $"<{LocalizableStrings.CmdProject}>",
                LocalizableStrings.CmdProjectDescription);

            CommandOption frameworkOption = app.Option(
                $"-f|--framework <{LocalizableStrings.CmdFramework}>",
                LocalizableStrings.CmdFrameworkDescription,
                CommandOptionType.SingleValue);

            CommandOption forceOption = app.Option(
                "--force",
                LocalizableStrings.CmdForceDescription,
                CommandOptionType.NoValue);

            app.OnExecute(() => {
                if (string.IsNullOrEmpty(projectArgument.Value))
                {
                    throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, $"<{LocalizableStrings.ProjectException}>");
                }

                var projects    = new ProjectCollection();
                var msbuildProj = MsbuildProject.FromFileOrDirectory(projects, projectArgument.Value);

                if (app.RemainingArguments.Count == 0)
                {
                    throw new GracefulException(LocalizableStrings.SpecifyAtLeastOneReferenceToAdd);
                }

                string frameworkString   = frameworkOption.Value();
                List <string> references = app.RemainingArguments;
                if (!forceOption.HasValue())
                {
                    MsbuildProject.EnsureAllReferencesExist(references);
                    IEnumerable <MsbuildProject> refs = references.Select((r) => MsbuildProject.FromFile(projects, r));

                    if (frameworkString == null)
                    {
                        foreach (var tfm in msbuildProj.GetTargetFrameworks())
                        {
                            foreach (var @ref in refs)
                            {
                                if ([email protected](tfm))
                                {
                                    Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString(
                                                             @ref,
                                                             msbuildProj.GetTargetFrameworks().Select((fx) => fx.GetShortFolderName())));
                                    return(1);
                                }
                            }
                        }
                    }
                    else
                    {
                        var framework = NuGetFramework.Parse(frameworkString);
                        if (!msbuildProj.IsTargettingFramework(framework))
                        {
                            Reporter.Error.WriteLine(string.Format(CommonLocalizableStrings.ProjectDoesNotTargetFramework, msbuildProj.ProjectRootElement.FullPath, frameworkString));
                            return(1);
                        }

                        foreach (var @ref in refs)
                        {
                            if ([email protected](framework))
                            {
                                Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString(
                                                         @ref,
                                                         new string[] { frameworkString }));
                                return(1);
                            }
                        }
                    }

                    msbuildProj.ConvertPathsToRelative(ref references);
                }

                int numberOfAddedReferences = msbuildProj.AddProjectToProjectReferences(
                    frameworkOption.Value(),
                    references);

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

                return(0);
            });

            try
            {
                return(app.Execute(args));
            }
            catch (GracefulException e)
            {
                Reporter.Error.WriteLine(e.Message.Red());
                app.ShowHelp();
                return(1);
            }
        }
예제 #16
0
        internal static CommandLineApplication CreateApplication(CommandLineApplication parentApp)
        {
            CommandLineApplication app = parentApp.Command("p2p", throwOnUnexpectedArg: false);

            app.FullName    = LocalizableStrings.AppFullName;
            app.Description = LocalizableStrings.AppDescription;
            app.HandleRemainingArguments  = true;
            app.ArgumentSeparatorHelpText = LocalizableStrings.AppHelpText;

            app.HelpOption("-h|--help");

            CommandOption frameworkOption = app.Option(
                $"-f|--framework <{CommonLocalizableStrings.CmdFramework}>",
                LocalizableStrings.CmdFrameworkDescription,
                CommandOptionType.SingleValue);

            app.OnExecute(() =>
            {
                try
                {
                    if (!parentApp.Arguments.Any())
                    {
                        throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, Constants.ProjectOrSolutionArgumentName);
                    }

                    var projectOrDirectory = parentApp.Arguments.First().Value;
                    if (string.IsNullOrEmpty(projectOrDirectory))
                    {
                        projectOrDirectory = PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory());
                    }

                    var projects    = new ProjectCollection();
                    var msbuildProj = MsbuildProject.FromFileOrDirectory(projects, projectOrDirectory);

                    if (app.RemainingArguments.Count == 0)
                    {
                        throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToAdd);
                    }

                    string frameworkString   = frameworkOption.Value();
                    List <string> references = app.RemainingArguments;
                    PathUtility.EnsureAllPathsExist(references, CommonLocalizableStrings.ReferenceDoesNotExist);
                    IEnumerable <MsbuildProject> refs = references.Select((r) => MsbuildProject.FromFile(projects, r));

                    if (frameworkString == null)
                    {
                        foreach (var tfm in msbuildProj.GetTargetFrameworks())
                        {
                            foreach (var @ref in refs)
                            {
                                if ([email protected](tfm))
                                {
                                    Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString(
                                                             @ref,
                                                             msbuildProj.GetTargetFrameworks().Select((fx) => fx.GetShortFolderName())));
                                    return(1);
                                }
                            }
                        }
                    }
                    else
                    {
                        var framework = NuGetFramework.Parse(frameworkString);
                        if (!msbuildProj.IsTargettingFramework(framework))
                        {
                            Reporter.Error.WriteLine(string.Format(CommonLocalizableStrings.ProjectDoesNotTargetFramework, msbuildProj.ProjectRootElement.FullPath, frameworkString));
                            return(1);
                        }

                        foreach (var @ref in refs)
                        {
                            if ([email protected](framework))
                            {
                                Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString(
                                                         @ref,
                                                         new string[] { frameworkString }));
                                return(1);
                            }
                        }
                    }

                    var relativePathReferences = references.Select((r) =>
                                                                   PathUtility.GetRelativePath(msbuildProj.ProjectDirectory, Path.GetFullPath(r))).ToList();

                    int numberOfAddedReferences = msbuildProj.AddProjectToProjectReferences(
                        frameworkOption.Value(),
                        relativePathReferences);

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

                    return(0);
                }
                catch (GracefulException e)
                {
                    Reporter.Error.WriteLine(e.Message.Red());
                    app.ShowHelp();
                    return(1);
                }
            });

            return(app);
        }