Example #1
0
        private string GetProjectJsonPath(string projectJson)
        {
            projectJson = ProjectPathHelper.NormalizeProjectFilePath(projectJson);

            if (File.Exists(projectJson))
            {
                return(projectJson);
            }

            throw new GracefulException(string.Format(LocalizableStrings.MigratonUnableToFindProjectJson, projectJson));
        }
Example #2
0
        private string GetProjectJsonPath(string projectJson)
        {
            projectJson = ProjectPathHelper.NormalizeProjectFilePath(projectJson);

            if (File.Exists(projectJson))
            {
                return(projectJson);
            }

            throw new Exception($"Unable to find project file at {projectJson}");
        }
        public static ProjectContextCollection EnsureValid(this ProjectContextCollection contextCollection, string projectFilePath)
        {
            IEnumerable <DiagnosticMessage> errors;

            if (contextCollection == null)
            {
                errors = new[]
                {
                    new DiagnosticMessage(
                        ErrorCodes.DOTNET1017,
                        $"Project file does not exist '{ProjectPathHelper.NormalizeProjectFilePath(projectFilePath)}'.",
                        projectFilePath,
                        DiagnosticMessageSeverity.Error)
                };
            }
            else
            {
                errors = contextCollection
                         .ProjectDiagnostics
                         .Where(d => d.Severity == DiagnosticMessageSeverity.Error);
            }

            if (errors.Any())
            {
                StringBuilder errorMessage = new StringBuilder($"The current project is not valid because of the following errors:{Environment.NewLine}");

                foreach (DiagnosticMessage message in errors)
                {
                    errorMessage.AppendLine(message.FormattedMessage);
                }

                throw new GracefulException(errorMessage.ToString());
            }

            return(contextCollection);
        }