private void MigrateProject(params string[] migrateArgs)
        {
            var result =
                MigrateCommand.Run(migrateArgs);

            result.Should().Be(0);
        }
Exemple #2
0
        public void ItFailsGracefullyWhenMigratingAppWithMissingDependency()
        {
            string projectName      = "MigrateAppWithMissingDep";
            var    projectDirectory = Path.Combine(GetTestGroupTestAssetsManager("NonRestoredTestProjects").CreateTestInstance(projectName).Path, "MyApp");

            string migrationOutputFile = Path.Combine(projectDirectory, "migration-output.json");

            File.Exists(migrationOutputFile).Should().BeFalse();
            MigrateCommand.Run(new string[] { projectDirectory, "-r", migrationOutputFile, "--format-report-file-json" }).Should().NotBe(0);
            File.Exists(migrationOutputFile).Should().BeTrue();
            File.ReadAllText(migrationOutputFile).Should().Contain("MIGRATE1018");
        }
Exemple #3
0
        public static int Run(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            CommandLineApplication app = new CommandLineApplication();

            app.Name                = "dotnet migrate";
            app.FullName            = ".NET Migrate Command";
            app.Description         = "Command used to migrate project.json projects to msbuild";
            app.HandleResponseFiles = true;
            app.HelpOption("-h|--help");

            CommandArgument projectArgument = app.Argument("<PROJECT_JSON/PROJECT_DIR>",
                                                           "The path to project.json file or a directory to migrate." +
                                                           " If a directory is specified, then it will recursively search for project.json files to migrate." +
                                                           " Defaults to current directory if nothing is specified.");

            CommandOption template              = app.Option("-t|--template-file", "Base MSBuild template to use for migrated app. The default is the project included in dotnet new -t msbuild", CommandOptionType.SingleValue);
            CommandOption sdkVersion            = app.Option("-v|--sdk-package-version", "The version of the sdk package that will be referenced in the migrated app. The default is the version of the sdk in dotnet new -t msbuild", CommandOptionType.SingleValue);
            CommandOption xprojFile             = app.Option("-x|--xproj-file", "The path to the xproj file to use. Required when there is more than one xproj in a project directory.", CommandOptionType.SingleValue);
            CommandOption skipProjectReferences = app.Option("-s|--skip-project-references", "Skip migrating project references. By default project references are migrated recursively", CommandOptionType.BoolValue);

            app.OnExecute(() =>
            {
                MigrateCommand migrateCommand = new MigrateCommand(
                    template.Value(),
                    projectArgument.Value,
                    sdkVersion.Value(),
                    xprojFile.Value(),
                    skipProjectReferences.BoolValue.HasValue ? skipProjectReferences.BoolValue.Value : false);

                return(migrateCommand.Execute());
            });

            try
            {
                return(app.Execute(args));
            }
            catch (Exception ex)
            {
#if DEBUG
                Reporter.Error.WriteLine(ex.ToString());
#else
                Reporter.Error.WriteLine(ex.Message);
#endif
                return(1);
            }
        }
Exemple #4
0
        public static int Run(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            CommandLineApplication app = new CommandLineApplication();

            app.Name                = "dotnet migrate";
            app.FullName            = ".NET Migrate Command";
            app.Description         = "Command used to migrate project.json projects to msbuild";
            app.HandleResponseFiles = true;
            app.HelpOption("-h|--help");

            CommandOption template   = app.Option("-t|--template-file", "Base MSBuild template to use for migrated app. The default is the project included in dotnet new -t msbuild", CommandOptionType.SingleValue);
            CommandOption output     = app.Option("-o|--output", "Directory to output migrated project to. The default is the project directory", CommandOptionType.SingleValue);
            CommandOption project    = app.Option("-p|--project", "The path to the project to run (defaults to the current directory). Can be a path to a project.json or a project directory", CommandOptionType.SingleValue);
            CommandOption sdkVersion = app.Option("-v|--sdk-package-version", "The version of the sdk package that will be referenced in the migrated app. The default is the version of the sdk in dotnet new -t msbuild", CommandOptionType.SingleValue);
            CommandOption xprojFile  = app.Option("-x|--xproj-file", "The path to the xproj file to use. Required when there is more than one xproj in a project directory.", CommandOptionType.SingleValue);

            app.OnExecute(() =>
            {
                MigrateCommand migrateCommand = new MigrateCommand(
                    template.Value(),
                    output.Value(),
                    project.Value(),
                    sdkVersion.Value(),
                    xprojFile.Value());

                return(migrateCommand.Execute());
            });

            try
            {
                return(app.Execute(args));
            }
            catch (Exception ex)
            {
#if DEBUG
                Reporter.Error.WriteLine(ex.ToString());
#else
                Reporter.Error.WriteLine(ex.Message);
#endif
                return(1);
            }
        }
Exemple #5
0
        public static int Run(string[] args)
        {
            // IMPORTANT:
            // When updating the command line args for dotnet-migrate, we need to update the in-VS caller of dotnet migrate as well.
            // It is located at dotnet/roslyn-project-system:
            //     src/Microsoft.VisualStudio.ProjectSystem.CSharp.VS/ProjectSystem/VS/Xproj/MigrateXprojFactory.cs

            DebugHelper.HandleDebugSwitch(ref args);

            CommandLineApplication app = new CommandLineApplication();

            app.Name                = "dotnet migrate";
            app.FullName            = ".NET Migrate Command";
            app.Description         = "Command used to migrate project.json projects to msbuild";
            app.HandleResponseFiles = true;
            app.HelpOption("-h|--help");

            CommandArgument projectArgument = app.Argument("<PROJECT_JSON/GLOBAL_JSON/PROJECT_DIR>",
                                                           string.Join(Environment.NewLine,
                                                                       "The path to ",
                                                                       " - a project.json file to migrate.",
                                                                       "or",
                                                                       " - a global.json file, it will migrate the folders specified in global.json.",
                                                                       "or",
                                                                       " - a directory to migrate, it will recursively search for project.json files to migrate.",
                                                                       "Defaults to current directory if nothing is specified."));

            CommandOption template              = app.Option("-t|--template-file", "Base MSBuild template to use for migrated app. The default is the project included in dotnet new.", CommandOptionType.SingleValue);
            CommandOption sdkVersion            = app.Option("-v|--sdk-package-version", "The version of the sdk package that will be referenced in the migrated app. The default is the version of the sdk in dotnet new.", CommandOptionType.SingleValue);
            CommandOption xprojFile             = app.Option("-x|--xproj-file", "The path to the xproj file to use. Required when there is more than one xproj in a project directory.", CommandOptionType.SingleValue);
            CommandOption skipProjectReferences = app.Option("-s|--skip-project-references", "Skip migrating project references. By default project references are migrated recursively.", CommandOptionType.BoolValue);

            CommandOption reportFile             = app.Option("-r|--report-file", "Output migration report to the given file in addition to the console.", CommandOptionType.SingleValue);
            CommandOption structuredReportOutput = app.Option("--format-report-file-json", "Output migration report file as json rather than user messages.", CommandOptionType.BoolValue);
            CommandOption skipBackup             = app.Option("--skip-backup", "Skip moving project.json, global.json, and *.xproj to a `backup` directory after successful migration.", CommandOptionType.BoolValue);

            app.OnExecute(() =>
            {
                MigrateCommand migrateCommand = new MigrateCommand(
                    template.Value(),
                    projectArgument.Value,
                    sdkVersion.Value(),
                    xprojFile.Value(),
                    reportFile.Value(),
                    skipProjectReferences.BoolValue.HasValue ? skipProjectReferences.BoolValue.Value : false,
                    structuredReportOutput.BoolValue.HasValue ? structuredReportOutput.BoolValue.Value : false,
                    skipBackup.BoolValue.HasValue ? skipBackup.BoolValue.Value : false);

                return(migrateCommand.Execute());
            });

            try
            {
                return(app.Execute(args));
            }
            catch (Exception ex)
            {
#if DEBUG
                Reporter.Error.WriteLine(ex.ToString());
#else
                Reporter.Error.WriteLine(ex.Message);
#endif
                Reporter.Error.WriteLine("Migration failed.");
                return(1);
            }
        }
Exemple #6
0
        public static int Run(string[] args)
        {
            // IMPORTANT:
            // When updating the command line args for dotnet-migrate, we need to update the in-VS caller of dotnet migrate as well.
            // It is located at dotnet/roslyn-project-system:
            //     src/Microsoft.VisualStudio.ProjectSystem.CSharp.VS/ProjectSystem/VS/Xproj/MigrateXprojFactory.cs

            DebugHelper.HandleDebugSwitch(ref args);

            CommandLineApplication app = new CommandLineApplication();

            app.Name                = "dotnet migrate";
            app.FullName            = LocalizableStrings.AppFullName;
            app.Description         = LocalizableStrings.AppDescription;
            app.HandleResponseFiles = true;
            app.HelpOption("-h|--help");

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

            CommandOption template = app.Option(
                "-t|--template-file",
                LocalizableStrings.CmdTemplateDescription,
                CommandOptionType.SingleValue);
            CommandOption sdkVersion = app.Option(
                "-v|--sdk-package-version",
                LocalizableStrings.CmdVersionDescription,
                CommandOptionType.SingleValue);
            CommandOption xprojFile = app.Option(
                "-x|--xproj-file",
                LocalizableStrings.CmdXprojFileDescription,
                CommandOptionType.SingleValue);
            CommandOption skipProjectReferences = app.Option(
                "-s|--skip-project-references",
                LocalizableStrings.CmdSkipProjectReferencesDescription,
                CommandOptionType.BoolValue);

            CommandOption reportFile = app.Option(
                "-r|--report-file",
                LocalizableStrings.CmdReportFileDescription,
                CommandOptionType.SingleValue);
            CommandOption structuredReportOutput = app.Option(
                "--format-report-file-json",
                LocalizableStrings.CmdReportOutputDescription,
                CommandOptionType.BoolValue);
            CommandOption skipBackup = app.Option("--skip-backup",
                                                  LocalizableStrings.CmdSkipBackupDescription,
                                                  CommandOptionType.BoolValue);

            app.OnExecute(() =>
            {
                MigrateCommand migrateCommand = new MigrateCommand(
                    template.Value(),
                    projectArgument.Value,
                    sdkVersion.Value(),
                    xprojFile.Value(),
                    reportFile.Value(),
                    skipProjectReferences.BoolValue.HasValue ? skipProjectReferences.BoolValue.Value : false,
                    structuredReportOutput.BoolValue.HasValue ? structuredReportOutput.BoolValue.Value : false,
                    skipBackup.BoolValue.HasValue ? skipBackup.BoolValue.Value : false);

                return(migrateCommand.Execute());
            });

            try
            {
                return(app.Execute(args));
            }
            catch (Exception ex)
            {
#if DEBUG
                Reporter.Error.WriteLine(ex.ToString());
#else
                Reporter.Error.WriteLine(ex.Message);
#endif
                Reporter.Error.WriteLine(LocalizableStrings.MigrationFailedError);
                return(1);
            }
        }