public async Task UpdateAsync(MovingProject movingProject) { var fromThisProjectToTheOldMovingOne = GetRelativePath(FullPath, movingProject.OldFullPath); var fromThisProjectToTheOldMovingOne2 = fromThisProjectToTheOldMovingOne.Replace('\\', '/'); string projectContent; using (var file = OpenText(FullPath)) { projectContent = await file.ReadToEndAsync(); } if (!projectContent.Contains(fromThisProjectToTheOldMovingOne) && !projectContent.Contains(fromThisProjectToTheOldMovingOne2)) { return; } var fromThisProjectToTheNewMovingOne = GetRelativePath(FullPath, movingProject.NewFullPath); var fromThisProjectToTheNewMovingOne2 = fromThisProjectToTheNewMovingOne.Replace('\\', '/'); projectContent = projectContent.Replace(fromThisProjectToTheOldMovingOne, fromThisProjectToTheNewMovingOne); projectContent = projectContent.Replace(fromThisProjectToTheOldMovingOne2, fromThisProjectToTheNewMovingOne2); using (var file = CreateText(FullPath)) { await file.WriteAsync(projectContent); } }
static int Main(string[] args) { var app = new CommandLineApplication(); var projectArg = app.Argument("project", "The path to the project to rename including the extension."); projectArg.MultipleValues = false; var newNameArg = app.Argument("newName", "The new name (and path) of the project including the extension."); newNameArg.MultipleValues = false; app.HelpOption("-h | --help"); app.OnExecute(async() => { try { var workingDirectory = new WorkingDirectory(); var movingProject = new MovingProject(projectArg.Value, newNameArg.Value); movingProject.Move(); foreach (var solution in workingDirectory.EnumerateSolutions()) { await solution.UpdateAsync(movingProject); } foreach (var project in workingDirectory.EnumerateProjects()) { await project.UpdateAsync(movingProject); } } catch (Exception e) { Console.WriteLine(e); return(-1); } return(0); }); if (args.Length < 2) { app.ShowHelp(); return(-1); } return(app.Execute(args)); }
public async Task UpdateAsync(MovingProject project) { var oldProjectRelativePath = '"' + GetRelativePath(_solutionPath, project.OldFullPath) + '"'; var newProjectRelativePath = '"' + GetRelativePath(_solutionPath, project.NewFullPath) + '"'; string solutionContent; using (var file = OpenText(_solutionPath)) { solutionContent = await file.ReadToEndAsync(); } if (!solutionContent.Contains(oldProjectRelativePath)) { return; } solutionContent = solutionContent.Replace(oldProjectRelativePath, newProjectRelativePath); using (var file = CreateText(_solutionPath)) { await file.WriteAsync(solutionContent); } }