public static bool TryMerge(string solutionFilePath, string solutionFileContent, ISlnMergeLogger logger, out string resultSolutionContent) { try { // Load SlnMerge settings from .mergesttings var slnFileDirectory = Path.GetDirectoryName(solutionFilePath); var slnMergeSettings = new SlnMergeSettings(); var slnMergeSettingsPath = Path.Combine(slnFileDirectory, Path.GetFileName(solutionFilePath) + ".mergesettings"); if (File.Exists(slnMergeSettingsPath)) { logger.Debug($"Using SlnMerge Settings: {slnMergeSettingsPath}"); slnMergeSettings = SlnMergeSettings.FromFile(slnMergeSettingsPath); } else { logger.Debug($"SlnMerge Settings (Not found): {slnMergeSettingsPath}"); } if (slnMergeSettings.Disabled) { logger.Debug("SlnMerge is currently disabled."); resultSolutionContent = solutionFileContent; return(true); } // Determine a overlay solution path. var overlaySolutionFilePath = Path.Combine(slnFileDirectory, Path.GetFileNameWithoutExtension(solutionFilePath) + ".Merge.sln"); if (!string.IsNullOrEmpty(slnMergeSettings.MergeTargetSolution)) { overlaySolutionFilePath = NormalizePath(Path.Combine(slnFileDirectory, slnMergeSettings.MergeTargetSolution)); } if (!File.Exists(overlaySolutionFilePath)) { logger.Warn($"Cannot load the solution file to merge. skipped: {overlaySolutionFilePath}"); resultSolutionContent = null; return(false); } // Merge the solutions. var solutionFile = SolutionFile.Parse(solutionFilePath, solutionFileContent); var overlaySolutionFile = SolutionFile.ParseFromFile(overlaySolutionFilePath); var mergedSolutionFile = Merge(solutionFile, overlaySolutionFile, slnMergeSettings, logger); // Get file content of the merged solution. resultSolutionContent = mergedSolutionFile.ToFileContent(); } catch (Exception e) { logger.Error("Failed to merge the solutions", e); resultSolutionContent = null; return(false); } return(true); }
public static SolutionFile Parse(string path, string content) { return(SolutionFile.Parse(path, Regex.Split(content, "\r?\n"))); }
public static SolutionFile ParseFromFile(string path) { return(SolutionFile.Parse(path, File.ReadAllLines(path))); }