Exemplo n.º 1
0
            public override void Write(ICommand command)
            {
                var helpArgs = new string[] { "--help" };

                if (command.Equals(RootCommand))
                {
                    Console.Out.WriteLine(HelpUsageText.UsageText);
                }
                else if (command.Name.Equals(NuGetCommandParser.GetCommand().Name))
                {
                    NuGetCommand.Run(helpArgs);
                }
                else if (command.Name.Equals(MSBuildCommandParser.GetCommand().Name))
                {
                    new MSBuildForwardingApp(helpArgs).Execute();
                }
                else if (command.Name.Equals(NewCommandParser.GetCommand().Name))
                {
                    NewCommandShim.Run(helpArgs);
                }
                else if (command.Name.Equals(VSTestCommandParser.GetCommand().Name))
                {
                    new VSTestForwardingApp(helpArgs).Execute();
                }
                else
                {
                    if (command.Name.Equals(ListProjectToProjectReferencesCommandParser.GetCommand().Name))
                    {
                        ListCommandParser.SlnOrProjectArgument.Name        = CommonLocalizableStrings.ProjectArgumentName;
                        ListCommandParser.SlnOrProjectArgument.Description = CommonLocalizableStrings.ProjectArgumentDescription;
                    }

                    base.Write(command);
                }
            }
Exemplo n.º 2
0
        public void ItCanNewRestoreBuildRunCleanMSBuildProject()
        {
            var    directory        = TestAssets.CreateTestDirectory();
            string projectDirectory = directory.FullName;

            string newArgs   = "console --debug:ephemeral-hive --no-restore";
            var    newResult = new NewCommandShim()
                               .WithWorkingDirectory(projectDirectory)
                               .ExecuteWithCapturedOutput(newArgs);

            newResult.Should().Pass();

            string projectPath = Directory.GetFiles(projectDirectory, "*.csproj").Single();

            //  Override TargetFramework since there aren't .NET Core 3 templates yet
            //  https://github.com/dotnet/core-sdk/issues/24 tracks removing this workaround
            XDocument project = XDocument.Load(projectPath);
            var       ns      = project.Root.Name.Namespace;

            project.Root.Element(ns + "PropertyGroup")
            .Element(ns + "TargetFramework")
            .Value = "netcoreapp3.0";
            project.Save(projectPath);


            new RestoreCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute("/p:SkipInvalidConfigurations=true")
            .Should().Pass();

            new BuildCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();

            var runCommand = new RunCommand()
                             .WithWorkingDirectory(projectDirectory);

            //  Set DOTNET_ROOT as workaround for https://github.com/dotnet/cli/issues/10196
            runCommand = runCommand.WithEnvironmentVariable(Environment.Is64BitProcess ? "DOTNET_ROOT": "DOTNET_ROOT(x86)",
                                                            Path.GetDirectoryName(DotnetUnderTest.FullName));

            runCommand.ExecuteWithCapturedOutput()
            .Should().Pass()
            .And.HaveStdOutContaining("Hello World!");

            var binDirectory = new DirectoryInfo(projectDirectory).Sub("bin");

            binDirectory.Should().HaveFilesMatching("*.dll", SearchOption.AllDirectories);

            new CleanCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();

            binDirectory.Should().NotHaveFilesMatching("*.dll", SearchOption.AllDirectories);
        }
Exemplo n.º 3
0
        public void ItCanNewRestoreBuildRunCleanMSBuildProject()
        {
            using (DisposableDirectory directory = Temp.CreateDirectory())
            {
                string projectDirectory = directory.Path;

                string newArgs   = "console --debug:ephemeral-hive --no-restore";
                var    newResult = new NewCommandShim()
                                   .WithWorkingDirectory(projectDirectory)
                                   .ExecuteWithCapturedOutput(newArgs);

                newResult.Should().Pass();

                string projectPath = Directory.GetFiles(projectDirectory, "*.csproj").Single();

                //  Override TargetFramework since there aren't .NET Core 3 templates yet
                //  https://github.com/dotnet/core-sdk/issues/24 tracks removing this workaround
                XDocument project = XDocument.Load(projectPath);
                var       ns      = project.Root.Name.Namespace;
                project.Root.Element(ns + "PropertyGroup")
                .Element(ns + "TargetFramework")
                .Value = "netcoreapp3.0";
                project.Save(projectPath);


                new RestoreCommand()
                .WithWorkingDirectory(projectDirectory)
                .Execute("/p:SkipInvalidConfigurations=true")
                .Should().Pass();

                new BuildCommand()
                .WithWorkingDirectory(projectDirectory)
                .Execute()
                .Should().Pass();

                new RunCommand()
                .WithWorkingDirectory(projectDirectory)
                .ExecuteWithCapturedOutput()
                .Should().Pass()
                .And.HaveStdOutContaining("Hello World!");

                var binDirectory = new DirectoryInfo(projectDirectory).Sub("bin");
                binDirectory.Should().HaveFilesMatching("*.dll", SearchOption.AllDirectories);

                new CleanCommand()
                .WithWorkingDirectory(projectDirectory)
                .Execute()
                .Should().Pass();

                binDirectory.Should().NotHaveFilesMatching("*.dll", SearchOption.AllDirectories);
            }
        }
Exemplo n.º 4
0
            public override void Write(HelpContext context)
            {
                var command  = context.Command;
                var helpArgs = new string[] { "--help" };

                if (command.Equals(RootCommand))
                {
                    Console.Out.WriteLine(HelpUsageText.UsageText);
                }
                else if (command.Name.Equals(NuGetCommandParser.GetCommand().Name))
                {
                    NuGetCommand.Run(helpArgs);
                }
                else if (command.Name.Equals(MSBuildCommandParser.GetCommand().Name))
                {
                    new MSBuildForwardingApp(helpArgs).Execute();
                }
                else if (command.Name.Equals(NewCommandParser.GetCommand().Name))
                {
                    NewCommandShim.Run(helpArgs);
                }
                else if (command.Name.Equals(VSTestCommandParser.GetCommand().Name))
                {
                    new VSTestForwardingApp(helpArgs).Execute();
                }
                else
                {
                    if (command.Name.Equals(ListProjectToProjectReferencesCommandParser.GetCommand().Name))
                    {
                        ListCommandParser.SlnOrProjectArgument.Name        = CommonLocalizableStrings.ProjectArgumentName;
                        ListCommandParser.SlnOrProjectArgument.Description = CommonLocalizableStrings.ProjectArgumentDescription;
                    }
                    else if (command.Name.Equals(AddPackageParser.GetCommand().Name) || command.Name.Equals(AddCommandParser.GetCommand().Name))
                    {
                        // Don't show package suggestions in help
                        AddPackageParser.CmdPackageArgument.Suggestions.Clear();
                    }

                    base.Write(context);
                }
            }
Exemplo n.º 5
0
        private static Command ConstructCommand()
        {
            var command = new DocumentedCommand("new", DocsLink);

            command.AddArgument(Argument);
            command.AddOption(ListOption);
            command.AddOption(NameOption);
            command.AddOption(OutputOption);
            command.AddOption(InstallOption);
            command.AddOption(UninstallOption);
            command.AddOption(InteractiveOption);
            command.AddOption(NuGetSourceOption);
            command.AddOption(TypeOption);
            command.AddOption(DryRunOption);
            command.AddOption(ForceOption);
            command.AddOption(LanguageOption);
            command.AddOption(UpdateCheckOption);
            command.AddOption(UpdateApplyOption);
            command.AddOption(ColumnsOption);

            command.Handler = CommandHandler.Create <ParseResult>((ParseResult parseResult) => NewCommandShim.Run(parseResult.GetArguments()));

            return(command);
        }