Normalize line endings on sln before injecting projects (#8088)

Fixes #7699
This commit is contained in:
Jay Harris
2018-08-09 12:25:06 -07:00
committed by Sébastien Ros
parent 0f5048dcb3
commit 6a7d4cc178

View File

@@ -436,6 +436,7 @@ namespace Orchard.CodeGeneration.Commands {
var projectReference = string.Format("EndProject\r\nProject(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"{0}\", \"Orchard.Web\\{2}\\{0}\\{0}.csproj\", \"{{{1}}}\"\r\n", projectName, projectGuid, containingFolder);
var projectConfiguationPlatforms = string.Format("\t{{{0}}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{{{0}}}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{{{0}}}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{{{0}}}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\t", projectGuid);
var solutionText = File.ReadAllText(solutionPath);
solutionText = NormalizeLineEndings(solutionText);
solutionText = solutionText.Insert(solutionText.LastIndexOf("EndProject\r\n"), projectReference);
solutionText = AppendProjectSection(solutionText, "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"Orchard.Web\"", "ProjectDependencies", string.Format("\t{{{0}}} = {{{0}}}\r\n\t", projectGuid));
solutionText = AppendGlobalSection(solutionText, "ProjectConfigurationPlatforms", projectConfiguationPlatforms);
@@ -446,6 +447,10 @@ namespace Orchard.CodeGeneration.Commands {
}
}
private string NormalizeLineEndings(string input) {
return input.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n");
}
private string AppendGlobalSection(string solutionText, string sectionName, string content) {
var sectionStart = solutionText.IndexOf(string.Format("GlobalSection({0})", sectionName));
var sectionEnd = solutionText.IndexOf("EndGlobalSection", sectionStart);