/// <summary> /// Converts to the specified <paramref name="solutionVersion"/>. /// </summary> /// <param name="solutionVersion">The solution version.</param> /// <param name="ideVersion">The IDE version.</param> /// <returns><c>true</c> if successful; <c>false</c> otherwise.</returns> public ConversionResult ConvertTo(VisualStudioVersion solutionVersion, IdeVersion ideVersion) { ConversionResult result = new ConversionResult(); result.ConverterReference = this; if (!this.IsReady) { result.ConversionStatus = ConversionStatus.NotReady; return(result); } bool success = true; StreamReader reader = new StreamReader(this.solutionPath); FileStream stream = null; TextWriter writer = null; string sln = reader.ReadToEnd(); reader.Close(); // Replace the solution version. sln = sln.Replace(this.VisualStudioVersion.GetStringValue(), solutionVersion.GetStringValue()); // If possible, also update the Ide version as well. if (ideVersion != IdeVersion.Default && this.IdeVersion != IdeVersion.Default) { string oldVersion, newVersion; oldVersion = this.IdeVersion.GetStringValue() + " " + ((int)this.VisualStudioVersion).ToString(); newVersion = ideVersion.GetStringValue() + " " + ((int)solutionVersion).ToString(); sln = sln.Replace(oldVersion, newVersion); } // Now write the file back to the hard drive. try { stream = File.OpenWrite(this.solutionPath); writer = new StreamWriter(stream, Encoding.UTF8); writer.Write(sln); } catch (Exception) { success = false; } finally { this.IsReady = false; if (stream != null) { writer.Close(); } } result.ConversionStatus = ConversionStatus.Failed; result.ConverterReference = this; if (success) { this.ConvertProjects(solutionVersion); result.ConversionStatus = ConversionStatus.Succeeded; if (this.projectConversionResults != null) { foreach (ConversionResult ret in this.projectConversionResults) { if (ret.ConversionStatus != ConversionStatus.Succeeded) { result.ConversionStatus = ConversionStatus.Partial; break; } } } } return(result); }