Beispiel #1
0
        private void VerifyProject(IEnumerable <ProjectContext> projectContexts, string projectDirectory)
        {
            if (!projectContexts.Any())
            {
                MigrationErrorCodes.MIGRATE1013($"No projects found in {projectDirectory}").Throw();
            }

            var defaultProjectContext = projectContexts.First();

            var diagnostics = defaultProjectContext.ProjectFile.Diagnostics;

            if (diagnostics.Any())
            {
                MigrationErrorCodes.MIGRATE1011(
                    $"{projectDirectory}{Environment.NewLine}{string.Join(Environment.NewLine, diagnostics.Select(d => FormatDiagnosticMessage(d)))}")
                .Throw();
            }

            var compilerName =
                defaultProjectContext.ProjectFile.GetCompilerOptions(defaultProjectContext.TargetFramework, "_")
                .CompilerName;

            if (!compilerName.Equals("csc", StringComparison.OrdinalIgnoreCase))
            {
                MigrationErrorCodes.MIGRATE20013(
                    $"Cannot migrate project {defaultProjectContext.ProjectFile.ProjectFilePath} using compiler {compilerName}").Throw();
            }
        }
Beispiel #2
0
        private void VerifyProject(IEnumerable <ProjectContext> projectContexts, string projectDirectory)
        {
            if (!projectContexts.Any())
            {
                MigrationErrorCodes.MIGRATE1013(String.Format(LocalizableStrings.MIGRATE1013Arg, projectDirectory)).Throw();
            }

            var defaultProjectContext = projectContexts.First();

            var diagnostics = defaultProjectContext.ProjectFile.Diagnostics;

            if (diagnostics.Any())
            {
                MigrationErrorCodes.MIGRATE1011(
                    String.Format("{0}{1}{2}", projectDirectory, Environment.NewLine, string.Join(Environment.NewLine, diagnostics.Select(d => FormatDiagnosticMessage(d)))))
                .Throw();
            }

            var compilerName =
                defaultProjectContext.ProjectFile.GetCompilerOptions(defaultProjectContext.TargetFramework, "_")
                .CompilerName;

            if (!compilerName.Equals("csc", StringComparison.OrdinalIgnoreCase))
            {
                MigrationErrorCodes.MIGRATE20013(
                    String.Format(LocalizableStrings.CannotMigrateProjectWithCompilerError, defaultProjectContext.ProjectFile.ProjectFilePath, compilerName)).Throw();
            }
        }
Beispiel #3
0
        private void VerifyProject(
            IEnumerable <ProjectContext> projectContexts,
            string projectDirectory,
            out List <string> warningMessages)
        {
            warningMessages = null;

            if (!projectContexts.Any())
            {
                MigrationErrorCodes.MIGRATE1013(String.Format(LocalizableStrings.MIGRATE1013Arg, projectDirectory)).Throw();
            }

            var defaultProjectContext = projectContexts.First();

            var diagnostics = defaultProjectContext.ProjectFile.Diagnostics;

            if (diagnostics.Any())
            {
                var warnings = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Warning);
                if (warnings.Any())
                {
                    var migrationError = MigrationErrorCodes.MIGRATE1011(String.Format(
                                                                             "{0}{1}{2}",
                                                                             projectDirectory,
                                                                             Environment.NewLine,
                                                                             string.Join(Environment.NewLine, diagnostics.Select(d => FormatDiagnosticMessage(d)))));

                    warningMessages = new List <string>();
                    warningMessages.Add(migrationError.GetFormattedErrorMessage());
                }

                var errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error);
                if (errors.Any())
                {
                    MigrationErrorCodes.MIGRATE1011(String.Format(
                                                        "{0}{1}{2}",
                                                        projectDirectory,
                                                        Environment.NewLine,
                                                        string.Join(Environment.NewLine, diagnostics.Select(d => FormatDiagnosticMessage(d)))))
                    .Throw();
                }
            }

            var compilerName =
                defaultProjectContext.ProjectFile.GetCompilerOptions(defaultProjectContext.TargetFramework, "_")
                .CompilerName;

            if (!compilerName.Equals("csc", StringComparison.OrdinalIgnoreCase))
            {
                MigrationErrorCodes.MIGRATE20013(
                    String.Format(LocalizableStrings.CannotMigrateProjectWithCompilerError, defaultProjectContext.ProjectFile.ProjectFilePath, compilerName)).Throw();
            }
        }
Beispiel #4
0
        private void VerifyProject(IEnumerable <ProjectContext> projectContexts, string projectDirectory)
        {
            if (projectContexts.Count() > 1)
            {
                MigrationErrorCodes.MIGRATE20011($"Multi-TFM projects currently not supported.").Throw();
            }

            if (!projectContexts.Any())
            {
                MigrationErrorCodes.MIGRATE1013($"No projects found in {projectDirectory}").Throw();
            }

            var defaultProjectContext = projectContexts.First();

            if (defaultProjectContext.LockFile == null)
            {
                MigrationErrorCodes.MIGRATE1012(
                    $"project.lock.json not found in {projectDirectory}, please run dotnet restore before doing migration").Throw();
            }

            var diagnostics = defaultProjectContext.ProjectFile.Diagnostics;

            if (diagnostics.Any())
            {
                MigrationErrorCodes.MIGRATE1011(
                    $"{projectDirectory}{Environment.NewLine}{string.Join(Environment.NewLine, diagnostics.Select(d => d.Message))}")
                .Throw();
            }

            var compilerName =
                defaultProjectContext.ProjectFile.GetCompilerOptions(defaultProjectContext.TargetFramework, "_")
                .CompilerName;

            if (!compilerName.Equals("csc", StringComparison.OrdinalIgnoreCase))
            {
                MigrationErrorCodes.MIGRATE20013(
                    $"Cannot migrate project {defaultProjectContext.ProjectFile.ProjectFilePath} using compiler {compilerName}").Throw();
            }
        }