public void Patch(AssemblyVersion assemblyVersion, AssemblyFileVersion assemblyFileVersion, string sourceBase, IEnumerable<AssemblyInfoFile> assemblyInfoFiles, AssemblyMetaData assemblyMetaData = null)
        {
            if (assemblyVersion == null)
            {
                throw new ArgumentNullException("assemblyVersion");
            }

            if (assemblyFileVersion == null)
            {
                throw new ArgumentNullException("assemblyFileVersion");
            }

            if (sourceBase == null)
            {
                throw new ArgumentNullException("sourceBase");
            }

            if (assemblyInfoFiles == null)
            {
                throw new ArgumentNullException("assemblyInfoFiles");
            }

            var patcher = new AssemblyPatcher(sourceBase, _logger);
            
            PatchResult result = patcher.Patch(assemblyInfoFiles.ToList(), assemblyVersion, assemblyFileVersion, assemblyMetaData);
            
            patcher.SavePatchResult(result);
        }
        public void Patch(AssemblyVersion assemblyVersion, AssemblyFileVersion assemblyFileVersion, string sourceBase,
            string assemblyfilePattern = "AssemblyInfo.cs", AssemblyMetaData assemblyMetaData = null)
        {
            if (assemblyVersion == null)
            {
                throw new ArgumentNullException("assemblyVersion");
            }

            if (assemblyFileVersion == null)
            {
                throw new ArgumentNullException("assemblyFileVersion");
            }

            if (sourceBase == null)
            {
                throw new ArgumentNullException("sourceBase");
            }

            var patcher = new AssemblyPatcher(sourceBase, _logger);

            IReadOnlyCollection<AssemblyInfoFile> assemblyInfoFiles =
                Directory.EnumerateFiles(sourceBase, assemblyfilePattern, SearchOption.AllDirectories)
                    .Where(file =>
                        file.IndexOf(patcher.PatchedassemblyinfosPath,
                            StringComparison.InvariantCultureIgnoreCase) < 0)
                    .Where(
                        file =>
                            file.IndexOf(string.Format("{0}packages{0}", Path.DirectorySeparatorChar),
                                StringComparison.InvariantCultureIgnoreCase) < 0)
                    .Select(file => new AssemblyInfoFile(file))
                    .ToReadOnly();
            
            Patch(assemblyVersion, assemblyFileVersion,sourceBase,assemblyInfoFiles,assemblyMetaData);
        }
        PatchResult Patch(AssemblyInfoFile assemblyInfoFile,
                          AssemblyVersion assemblyVersion,
                          AssemblyFileVersion assemblyFileVersion, AssemblyMetaData assemblyMetaData = null)
        {
            CheckArguments(assemblyInfoFile, assemblyVersion, assemblyFileVersion);


            var patchResult = new PatchResult();

            AssemblyInfoPatchResult result = PatchAssemblyInfo(assemblyVersion, assemblyFileVersion, assemblyInfoFile, assemblyMetaData);

            patchResult.Add(result);

            return(patchResult);
        }
        PatchResult Patch(AssemblyInfoFile assemblyInfoFile,
            AssemblyVersion assemblyVersion,
            AssemblyFileVersion assemblyFileVersion, AssemblyMetaData assemblyMetaData = null)
        {
            CheckArguments(assemblyInfoFile, assemblyVersion, assemblyFileVersion);


            var patchResult = new PatchResult();

            AssemblyInfoPatchResult result = PatchAssemblyInfo(assemblyVersion, assemblyFileVersion, assemblyInfoFile, assemblyMetaData);

            patchResult.Add(result);

            return patchResult;
        }
        static void CheckArguments(IEnumerable <AssemblyInfoFile> assemblyInfoFiles, AssemblyVersion assemblyVersion,
                                   AssemblyFileVersion assemblyFileVersion)
        {
            if (assemblyInfoFiles == null)
            {
                throw new ArgumentNullException(nameof(assemblyInfoFiles));
            }

            if (assemblyVersion == null)
            {
                throw new ArgumentNullException(nameof(assemblyVersion));
            }
            if (assemblyFileVersion == null)
            {
                throw new ArgumentNullException(nameof(assemblyFileVersion));
            }
        }
        static void CheckArguments(AssemblyInfoFile assemblyInfoFile, AssemblyVersion assemblyVersion,
                                   AssemblyFileVersion assemblyFileVersion)
        {
            if (assemblyInfoFile == null)
            {
                throw new ArgumentNullException(nameof(assemblyInfoFile));
            }

            if (assemblyVersion == null)
            {
                throw new ArgumentNullException(nameof(assemblyVersion));
            }
            if (assemblyFileVersion == null)
            {
                throw new ArgumentNullException(nameof(assemblyFileVersion));
            }
        }
        public void Patch(
            AssemblyVersion assemblyVersion,
            AssemblyFileVersion assemblyFileVersion,
            string sourceBase,
            string assemblyfilePattern        = "AssemblyInfo.cs",
            AssemblyMetaData assemblyMetaData = null)
        {
            if (assemblyVersion == null)
            {
                throw new ArgumentNullException(nameof(assemblyVersion));
            }

            if (assemblyFileVersion == null)
            {
                throw new ArgumentNullException(nameof(assemblyFileVersion));
            }

            if (sourceBase == null)
            {
                throw new ArgumentNullException(nameof(sourceBase));
            }

            var patcher = new AssemblyPatcher(sourceBase, _logger);

            IReadOnlyCollection <AssemblyInfoFile> assemblyInfoFiles =
                Directory.EnumerateFiles(sourceBase, assemblyfilePattern, SearchOption.AllDirectories)
                .Where(file =>
                       file.IndexOf(patcher.PatchedassemblyinfosPath,
                                    StringComparison.InvariantCultureIgnoreCase) < 0)
                .Where(
                    file =>
                    file.IndexOf(string.Format("{0}packages{0}", Path.DirectorySeparatorChar),
                                 StringComparison.InvariantCultureIgnoreCase) < 0)
                .Select(file => new AssemblyInfoFile(file))
                .ToReadOnly();

            Patch(assemblyVersion, assemblyFileVersion, sourceBase, assemblyInfoFiles, assemblyMetaData);
        }
        public void Patch(
            AssemblyVersion assemblyVersion,
            AssemblyFileVersion assemblyFileVersion,
            string sourceBase,
            IEnumerable <AssemblyInfoFile> assemblyInfoFiles,
            AssemblyMetaData assemblyMetaData = null)
        {
            if (assemblyVersion == null)
            {
                throw new ArgumentNullException(nameof(assemblyVersion));
            }

            if (assemblyFileVersion == null)
            {
                throw new ArgumentNullException(nameof(assemblyFileVersion));
            }

            if (sourceBase == null)
            {
                throw new ArgumentNullException(nameof(sourceBase));
            }

            if (assemblyInfoFiles == null)
            {
                throw new ArgumentNullException(nameof(assemblyInfoFiles));
            }

            var patcher = new AssemblyPatcher(sourceBase, _logger);

            PatchResult result = patcher.Patch(assemblyInfoFiles.ToList(),
                                               assemblyVersion,
                                               assemblyFileVersion,
                                               assemblyMetaData);

            patcher.SavePatchResult(result);
        }
        public PatchResult Patch(IReadOnlyCollection<AssemblyInfoFile> assemblyInfoFiles, AssemblyVersion assemblyVersion, AssemblyFileVersion assemblyFileVersion, AssemblyMetaData assemblyMetaData = null)
        {
            CheckArguments(assemblyInfoFiles, assemblyVersion, assemblyFileVersion);

            if (!assemblyInfoFiles.Any())
            {
                return new PatchResult();
            }

            var patchResult = new PatchResult();


            List<AssemblyInfoPatchResult> patchResults = assemblyInfoFiles
                .Select(assemblyInfoFile =>
                    PatchAssemblyInfo(assemblyVersion, assemblyFileVersion, assemblyInfoFile, assemblyMetaData))
                .ToList();

            patchResults.Where(result => result.Succeeded).ToList().ForEach(patchResult.Add);

            return patchResult;
        }
Пример #10
0
        static void CheckArguments(IEnumerable<AssemblyInfoFile> assemblyInfoFiles, AssemblyVersion assemblyVersion,
            AssemblyFileVersion assemblyFileVersion)
        {
            if (assemblyInfoFiles == null)
            {
                throw new ArgumentNullException("assemblyInfoFiles");
            }

            if (assemblyVersion == null)
            {
                throw new ArgumentNullException("assemblyVersion");
            }
            if (assemblyFileVersion == null)
            {
                throw new ArgumentNullException("assemblyFileVersion");
            }
        }
Пример #11
0
        static void CheckArguments(AssemblyInfoFile assemblyInfoFile, AssemblyVersion assemblyVersion,
            AssemblyFileVersion assemblyFileVersion)
        {
            if (assemblyInfoFile == null)
            {
                throw new ArgumentNullException("assemblyInfoFile");
            }

            if (assemblyVersion == null)
            {
                throw new ArgumentNullException("assemblyVersion");
            }
            if (assemblyFileVersion == null)
            {
                throw new ArgumentNullException("assemblyFileVersion");
            }
        }
Пример #12
0
        AssemblyInfoPatchResult PatchAssemblyInfo(AssemblyVersion assemblyVersion,
            AssemblyFileVersion assemblyFileVersion,
            AssemblyInfoFile assemblyInfoFile, 
            AssemblyMetaData assemblyMetaData)
        {
            string backupBasePath = BackupBasePath();
            var backupDirectory = new DirectoryInfo(backupBasePath);

            _logger.WriteVerbose(string.Format("Patching assembly file '{0}', assembly version {1}, assembly file version {2}", assemblyInfoFile.FullPath, assemblyVersion.Version, assemblyFileVersion.Version));

            try
            {
                _logger.WriteDebug(string.Format("Assembly info patch backup directory is '{0}'", backupDirectory.FullName));
                if (!backupDirectory.Exists)
                {
                    _logger.WriteVerbose(string.Format("Creating assembly info patch backup directory '{0}'", backupDirectory.FullName));
                    backupDirectory.Create();
                    backupDirectory.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(
                    string.Format("Backup base path is '{0}', exists: {1}", backupBasePath, backupDirectory.Exists), ex);
            }

            var sourceFileName = new FileInfo(assemblyInfoFile.FullPath);

            string relativePath = sourceFileName.FullName.Substring(_sourceBase.Length);

            string fileBackupPath = Path.Combine(BackupBasePath(), relativePath.TrimStart(Path.DirectorySeparatorChar));

            var backupFile = new FileInfo(fileBackupPath);

            DirectoryInfo fileBackupBackupDirectory = backupFile.Directory;

            if (fileBackupBackupDirectory == null)
            {
                throw new InvalidOperationException("The backup file directory is null");
            }

            if (!fileBackupBackupDirectory.Exists)
            {
                try
                {
                    _logger.WriteVerbose(string.Format("Creating assembly info patch backup directory '{0}' for file '{1}'", fileBackupBackupDirectory.FullName, assemblyInfoFile.FullPath));
                    fileBackupBackupDirectory.Create();
                }
                catch (Exception ex)
                {
                    throw new IOException(
                        string.Format("Could not create directory '{0}'", fileBackupBackupDirectory.FullName), ex);
                }
            }

            _logger.WriteVerbose(string.Format("Copying file '{0}' to backup '{1}'", sourceFileName.FullName, fileBackupPath));
            File.Copy(sourceFileName.FullName, fileBackupPath, true);
            
            AssemblyVersion oldAssemblyVersion = null;
            AssemblyFileVersion oldAssemblyFileVersion = null;
            Encoding encoding = Encoding.UTF8;

            string tmpPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".cs");

            _logger.WriteVerbose(string.Format("Copying file '{0}' to temp file '{1}'", sourceFileName.FullName, tmpPath));

            string oldDescription = null;
            string oldCompany = null;
            string oldCopyright = null;
            string oldTrademark = null;
            string oldProduct = null;
            string oldConfiguration = null;

            File.Copy(sourceFileName.FullName, tmpPath);
            using (var reader = new StreamReader(backupFile.FullName, encoding))
            {
                using (var writer = new StreamWriter(tmpPath, false, encoding))
                {
                    while (!reader.EndOfStream)
                    {
                        string readLine = reader.ReadLineWithEol();

                        string writtenLine;

                        bool isAssemblyVersionLine =
                            readLine.IndexOf("[assembly: AssemblyVersion(",
                                StringComparison.InvariantCultureIgnoreCase) >= 0;


                        bool isAssemblyFileVersionLine =
                            readLine.IndexOf("[assembly: AssemblyFileVersion(",
                                StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyDescriptionLine =
                            readLine.IndexOf("[assembly: AssemblyDescription(",
                                StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyCompanyLine =
                            readLine.IndexOf("[assembly: AssemblyCompany(",
                                StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyTrademarkLine =
                            readLine.IndexOf("[assembly: AssemblyTrademark(",
                                StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyCopyrightLine =
                            readLine.IndexOf("[assembly: AssemblyCopyright(",
                                StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyProductLine =
                            readLine.IndexOf("[assembly: AssemblyProduct(",
                                StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyConfigurationLine =
                            readLine.IndexOf("[assembly: AssemblyConfiguration(",
                                StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool lineIsComment = readLine.Trim().StartsWith("//");

                        if (lineIsComment)
                        {
                            writtenLine = readLine;
                        }
                        else if (isAssemblyVersionLine)
                        {
                            oldAssemblyVersion = new AssemblyVersion(ParseVersion(readLine));

                            writtenLine = string.Format("[assembly: AssemblyVersion(\"{0}.{1}.{2}.{3}\")]",
                                assemblyVersion.Version.Major,
                                assemblyVersion.Version.Minor,
                                assemblyVersion.Version.Build,
                                assemblyVersion.Version.Revision) + readLine.NewLine();
                        }
                        else if (isAssemblyFileVersionLine)
                        {
                            oldAssemblyFileVersion = new AssemblyFileVersion(ParseVersion(readLine));
                            writtenLine = string.Format("[assembly: AssemblyFileVersion(\"{0}.{1}.{2}.{3}\")]",
                                assemblyFileVersion.Version.Major,
                                assemblyFileVersion.Version.Minor,
                                assemblyFileVersion.Version.Build,
                                assemblyFileVersion.Version.Revision) + readLine.NewLine();
                        }
                        else if (assemblyMetaData != null)
                        {
                            if (isAssemblyDescriptionLine && assemblyMetaData.Description != null)
                            {
                                oldDescription = ParseAttribute(readLine);
                                writtenLine = string.Format("[assembly: AssemblyDescription(\"{0}\")]{1}",
                                    assemblyMetaData.Description, readLine.NewLine());
                            }
                            else if (isAssemblyConfigurationLine && assemblyMetaData.Configuration != null)
                            {
                                oldConfiguration = ParseAttribute(readLine);
                                writtenLine = string.Format("[assembly: AssemblyConfiguration(\"{0}\")]{1}",
                                    assemblyMetaData.Configuration, readLine.NewLine());
                            }
                            else if (isAssemblyCopyrightLine && assemblyMetaData.Copyright != null)
                            {
                                oldCopyright = ParseAttribute(readLine);
                                writtenLine = string.Format("[assembly: AssemblyCopyright(\"{0}\")]{1}",
                                    assemblyMetaData.Copyright, readLine.NewLine());
                            }
                            else if (isAssemblyCompanyLine && assemblyMetaData.Company != null)
                            {
                                oldCompany = ParseAttribute(readLine);
                                writtenLine = string.Format("[assembly: AssemblyCompany(\"{0}\")]{1}",
                                    assemblyMetaData.Company, readLine.NewLine());
                            }
                            else if (isAssemblyTrademarkLine && assemblyMetaData.Trademark != null)
                            {
                                oldTrademark = ParseAttribute(readLine);
                                writtenLine = string.Format("[assembly: AssemblyTrademark(\"{0}\")]{1}",
                                    assemblyMetaData.Trademark, readLine.NewLine());
                            }
                            else if (isAssemblyProductLine && assemblyMetaData.Product != null)
                            {
                                oldProduct = ParseAttribute(readLine);
                                writtenLine = string.Format("[assembly: AssemblyProduct(\"{0}\")]{1}",
                                    assemblyMetaData.Product, readLine.NewLine());
                            }
                            else
                            {
                                writtenLine = readLine;
                            }
                        }
                        else
                        {
                            writtenLine = readLine;
                        }

                        writer.Write(writtenLine);
                    }
                }
            }


            if (oldAssemblyVersion == null)
            {
                _logger.WriteWarning(string.Format("Could not find assembly version in file {0}", assemblyInfoFile.FullPath));
            }
            if (oldAssemblyFileVersion == null)
            {
                _logger.WriteWarning(string.Format("Could not find assembly file version in file {0}", assemblyInfoFile.FullPath));
            }
            AssemblyInfoPatchResult result;
            if (oldAssemblyVersion != null && oldAssemblyFileVersion != null)
            {

                if (assemblyVersion.Version != oldAssemblyVersion.Version ||
                    assemblyFileVersion.Version != oldAssemblyFileVersion.Version)
                {
                    if (File.Exists(sourceFileName.FullName))
                    {
                        File.Delete(sourceFileName.FullName);
                    }
                    File.Copy(tmpPath, sourceFileName.FullName);
                }

                var oldAssemblyMetadata = new AssemblyMetaData(oldDescription, oldConfiguration, oldCompany, oldProduct, oldCopyright, oldTrademark);

                result = new AssemblyInfoPatchResult(assemblyInfoFile.FullPath, fileBackupPath,
                    oldAssemblyVersion, assemblyVersion, oldAssemblyFileVersion,
                    assemblyFileVersion, newAssemblyMetadata: assemblyMetaData, oldAssemblyMetadata: oldAssemblyMetadata);
            }
            else
            {
                result = AssemblyInfoPatchResult.Failed(backupFile.FullName);
            }

            _logger.WriteVerbose(string.Format("Deleting temp file '{0}'", tmpPath));
            File.Delete(tmpPath);

            _logger.WriteVerbose(string.Format("Deleting backup file '{0}'", backupFile.FullName));
            File.Delete(backupFile.FullName);

            if (!fileBackupBackupDirectory.EnumerateDirectories().Any() &&
                !fileBackupBackupDirectory.EnumerateFiles().Any())
            {
                fileBackupBackupDirectory.Delete();
            }

            return result;
        }
Пример #13
0
        public PatchResult Patch(IReadOnlyCollection <AssemblyInfoFile> assemblyInfoFiles, AssemblyVersion assemblyVersion, AssemblyFileVersion assemblyFileVersion, AssemblyMetaData assemblyMetaData = null)
        {
            CheckArguments(assemblyInfoFiles, assemblyVersion, assemblyFileVersion);

            if (!assemblyInfoFiles.Any())
            {
                return(new PatchResult());
            }

            var patchResult = new PatchResult();


            List <AssemblyInfoPatchResult> patchResults = assemblyInfoFiles
                                                          .Select(assemblyInfoFile =>
                                                                  PatchAssemblyInfo(assemblyVersion, assemblyFileVersion, assemblyInfoFile, assemblyMetaData))
                                                          .ToList();

            patchResults.Where(result => result.Succeeded).ToList().ForEach(patchResult.Add);

            return(patchResult);
        }
Пример #14
0
        AssemblyInfoPatchResult PatchAssemblyInfo(AssemblyVersion assemblyVersion,
                                                  AssemblyFileVersion assemblyFileVersion,
                                                  AssemblyInfoFile assemblyInfoFile,
                                                  AssemblyMetaData assemblyMetaData)
        {
            string backupBasePath  = BackupBasePath();
            var    backupDirectory = new DirectoryInfo(backupBasePath);

            _logger?.Invoke(
                $"Patching assembly file '{assemblyInfoFile.FullPath}', assembly version {assemblyVersion.Version}, assembly file version {assemblyFileVersion.Version}");

            try
            {
                _logger?.Invoke($"Assembly info patch backup directory is '{backupDirectory.FullName}'");
                if (!backupDirectory.Exists)
                {
                    _logger?.Invoke($"Creating assembly info patch backup directory '{backupDirectory.FullName}'");
                    backupDirectory.Create();
                    backupDirectory.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(
                          $"Backup base path is '{backupBasePath}', exists: {backupDirectory.Exists}", ex);
            }

            var sourceFileName = new FileInfo(assemblyInfoFile.FullPath);

            string relativePath = sourceFileName.FullName.Substring(_sourceBase.Length);

            string fileBackupPath = Path.Combine(BackupBasePath(), relativePath.TrimStart(Path.DirectorySeparatorChar));

            var backupFile = new FileInfo(fileBackupPath);

            DirectoryInfo fileBackupBackupDirectory = backupFile.Directory;

            if (fileBackupBackupDirectory == null)
            {
                throw new InvalidOperationException("The backup file directory is null");
            }

            if (!fileBackupBackupDirectory.Exists)
            {
                try
                {
                    _logger?.Invoke(
                        $"Creating assembly info patch backup directory '{fileBackupBackupDirectory.FullName}' for file '{assemblyInfoFile.FullPath}'");
                    fileBackupBackupDirectory.Create();
                }
                catch (Exception ex)
                {
                    throw new IOException(
                              $"Could not create directory '{fileBackupBackupDirectory.FullName}'", ex);
                }
            }

            _logger?.Invoke($"Copying file '{sourceFileName.FullName}' to backup '{fileBackupPath}'");
            File.Copy(sourceFileName.FullName, fileBackupPath, true);

            AssemblyVersion     oldAssemblyVersion     = null;
            AssemblyFileVersion oldAssemblyFileVersion = null;
            Encoding            encoding = Encoding.UTF8;

            string tmpPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".cs");

            _logger?.Invoke($"Copying file '{sourceFileName.FullName}' to temp file '{tmpPath}'");

            string oldDescription   = null;
            string oldCompany       = null;
            string oldCopyright     = null;
            string oldTrademark     = null;
            string oldProduct       = null;
            string oldConfiguration = null;

            File.Copy(sourceFileName.FullName, tmpPath);
            using (var reader = new StreamReader(backupFile.FullName, encoding))
            {
                using (var writer = new StreamWriter(tmpPath, false, encoding))
                {
                    while (!reader.EndOfStream)
                    {
                        string readLine = reader.ReadLineWithEol();

                        string writtenLine;

                        bool isAssemblyVersionLine =
                            readLine.IndexOf("[assembly: AssemblyVersion(",
                                             StringComparison.InvariantCultureIgnoreCase) >= 0;


                        bool isAssemblyFileVersionLine =
                            readLine.IndexOf("[assembly: AssemblyFileVersion(",
                                             StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyDescriptionLine =
                            readLine.IndexOf("[assembly: AssemblyDescription(",
                                             StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyCompanyLine =
                            readLine.IndexOf("[assembly: AssemblyCompany(",
                                             StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyTrademarkLine =
                            readLine.IndexOf("[assembly: AssemblyTrademark(",
                                             StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyCopyrightLine =
                            readLine.IndexOf("[assembly: AssemblyCopyright(",
                                             StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyProductLine =
                            readLine.IndexOf("[assembly: AssemblyProduct(",
                                             StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool isAssemblyConfigurationLine =
                            readLine.IndexOf("[assembly: AssemblyConfiguration(",
                                             StringComparison.InvariantCultureIgnoreCase) >= 0;

                        bool lineIsComment = readLine.Trim().StartsWith("//");

                        if (lineIsComment)
                        {
                            writtenLine = readLine;
                        }
                        else if (isAssemblyVersionLine)
                        {
                            oldAssemblyVersion = new AssemblyVersion(ParseVersion(readLine));

                            writtenLine =
                                $"[assembly: AssemblyVersion(\"{assemblyVersion.Version.Major}.{assemblyVersion.Version.Minor}.{assemblyVersion.Version.Build}.{assemblyVersion.Version.Revision}\")]" + readLine.NewLine();
                        }
                        else if (isAssemblyFileVersionLine)
                        {
                            oldAssemblyFileVersion = new AssemblyFileVersion(ParseVersion(readLine));
                            writtenLine            =
                                $"[assembly: AssemblyFileVersion(\"{assemblyFileVersion.Version.Major}.{assemblyFileVersion.Version.Minor}.{assemblyFileVersion.Version.Build}.{assemblyFileVersion.Version.Revision}\")]" + readLine.NewLine();
                        }
                        else if (assemblyMetaData != null)
                        {
                            if (isAssemblyDescriptionLine && assemblyMetaData.Description != null)
                            {
                                oldDescription = ParseAttribute(readLine);
                                writtenLine    =
                                    $"[assembly: AssemblyDescription(\"{assemblyMetaData.Description}\")]{readLine.NewLine()}";
                            }
                            else if (isAssemblyConfigurationLine && assemblyMetaData.Configuration != null)
                            {
                                oldConfiguration = ParseAttribute(readLine);
                                writtenLine      =
                                    $"[assembly: AssemblyConfiguration(\"{assemblyMetaData.Configuration}\")]{readLine.NewLine()}";
                            }
                            else if (isAssemblyCopyrightLine && assemblyMetaData.Copyright != null)
                            {
                                oldCopyright = ParseAttribute(readLine);
                                writtenLine  =
                                    $"[assembly: AssemblyCopyright(\"{assemblyMetaData.Copyright}\")]{readLine.NewLine()}";
                            }
                            else if (isAssemblyCompanyLine && assemblyMetaData.Company != null)
                            {
                                oldCompany  = ParseAttribute(readLine);
                                writtenLine =
                                    $"[assembly: AssemblyCompany(\"{assemblyMetaData.Company}\")]{readLine.NewLine()}";
                            }
                            else if (isAssemblyTrademarkLine && assemblyMetaData.Trademark != null)
                            {
                                oldTrademark = ParseAttribute(readLine);
                                writtenLine  =
                                    $"[assembly: AssemblyTrademark(\"{assemblyMetaData.Trademark}\")]{readLine.NewLine()}";
                            }
                            else if (isAssemblyProductLine && assemblyMetaData.Product != null)
                            {
                                oldProduct  = ParseAttribute(readLine);
                                writtenLine =
                                    $"[assembly: AssemblyProduct(\"{assemblyMetaData.Product}\")]{readLine.NewLine()}";
                            }
                            else
                            {
                                writtenLine = readLine;
                            }
                        }
                        else
                        {
                            writtenLine = readLine;
                        }

                        writer.Write(writtenLine);
                    }
                }
            }


            if (oldAssemblyVersion == null)
            {
                _logger?.Invoke($"Could not find assembly version in file {assemblyInfoFile.FullPath}");
            }
            if (oldAssemblyFileVersion == null)
            {
                _logger?.Invoke($"Could not find assembly file version in file {assemblyInfoFile.FullPath}");
            }
            AssemblyInfoPatchResult result;

            if (oldAssemblyVersion != null && oldAssemblyFileVersion != null)
            {
                if (assemblyVersion.Version != oldAssemblyVersion.Version ||
                    assemblyFileVersion.Version != oldAssemblyFileVersion.Version)
                {
                    if (File.Exists(sourceFileName.FullName))
                    {
                        File.Delete(sourceFileName.FullName);
                    }
                    File.Copy(tmpPath, sourceFileName.FullName);
                }

                var oldAssemblyMetadata = new AssemblyMetaData(oldDescription, oldConfiguration, oldCompany, oldProduct, oldCopyright, oldTrademark);

                result = new AssemblyInfoPatchResult(assemblyInfoFile.FullPath, fileBackupPath,
                                                     oldAssemblyVersion, assemblyVersion, oldAssemblyFileVersion,
                                                     assemblyFileVersion, newAssemblyMetadata: assemblyMetaData, oldAssemblyMetadata: oldAssemblyMetadata);
            }
            else
            {
                result = AssemblyInfoPatchResult.Failed(backupFile.FullName);
            }

            _logger?.Invoke($"Deleting temp file '{tmpPath}'");
            File.Delete(tmpPath);

            _logger?.Invoke($"Deleting backup file '{backupFile.FullName}'");
            File.Delete(backupFile.FullName);

            if (!fileBackupBackupDirectory.EnumerateDirectories().Any() &&
                !fileBackupBackupDirectory.EnumerateFiles().Any())
            {
                fileBackupBackupDirectory.Delete();
            }

            return(result);
        }