public void Migrate(string projectFolderPath) { if (LegacyProjectSummary.CanProjectBeMigrated(projectFolderPath)) { Console.WriteLine($"Migrating {projectFolderPath}"); var projectDetails = LegacyProjectSummary.ExtractDetails(projectFolderPath); var tempCSProjPath = CreateTempCSProjFile(projectDetails.CSProjPath); var xmlDoc = XDocument.Load(tempCSProjPath); var ns = xmlDoc.Root.GetDefaultNamespace(); MigratePackageReferences(projectDetails.PackageReferences, xmlDoc, ns); xmlDoc.Save(tempCSProjPath); File.Copy(projectDetails.CSProjPath, projectDetails.CSProjPath + ".old", overwrite: true); File.Copy(tempCSProjPath, projectDetails.CSProjPath, overwrite: true); if (File.Exists(projectDetails.ProjectJsonPath + ".old")) { File.Delete(projectDetails.ProjectJsonPath + ".old"); } File.Move(projectDetails.ProjectJsonPath, projectDetails.ProjectJsonPath + ".old"); if (projectDetails.AssemblyInfoPath != null && File.Exists(projectDetails.AssemblyInfoPath)) { File.Delete(projectDetails.AssemblyInfoPath); } var tempDir = Path.GetDirectoryName(tempCSProjPath); if (Directory.Exists(tempDir)) { Directory.Delete(tempDir, recursive: true); } } }
public static LegacyProjectSummary ExtractDetails(string projectFolderPath) { var projectJsonPath = Path.Combine(projectFolderPath, "project.json"); var csprojPath = Directory.GetFiles(projectFolderPath, "*.csproj", SearchOption.TopDirectoryOnly)[0]; var projectDetails = new LegacyProjectSummary() { ProjectFolderPath = projectFolderPath, CSProjPath = csprojPath, ProjectJsonPath = projectJsonPath }; projectDetails.ExtractProjectJsonDetails(); projectDetails.ExtractCSProjDetails(); projectDetails.ExtractResourceFileDetails(); projectDetails.ExtractAssemblyInfo(); return(projectDetails); }
public void Migrate(string projectFolderPath) { if (LegacyProjectSummary.CanProjectBeMigrated(projectFolderPath)) { Console.WriteLine($"Migrating {projectFolderPath}"); var tempCSProjPath = CreateTempCSProjFile(); var projectDetails = LegacyProjectSummary.ExtractDetails(projectFolderPath); var xmlRoot = XElement.Load(tempCSProjPath); var ns = xmlRoot.GetDefaultNamespace(); projectDetails.DisableGenerateAssemblyInfo(); MigrateFrameworks(projectDetails.Frameworks, xmlRoot, ns); MigrateProperties(projectDetails, xmlRoot, ns); MigrateChooseElements(projectDetails.ChooseElements, xmlRoot, ns); MigrateDependencies(projectDetails, xmlRoot, ns); MigrateImports(projectDetails.Imports, xmlRoot, ns); MigrateTargets(projectDetails.Targets, xmlRoot, ns); MigrateResourceFiles(projectDetails.ResourceFileItemGroup, xmlRoot, ns); xmlRoot = RemoveAllNamespaces(xmlRoot); xmlRoot.Save(tempCSProjPath); File.Copy(projectDetails.CSProjPath, projectDetails.CSProjPath + ".old", overwrite: true); File.Copy(tempCSProjPath, projectDetails.CSProjPath, overwrite: true); if (File.Exists(projectDetails.ProjectJsonPath + ".old")) { File.Delete(projectDetails.ProjectJsonPath + ".old"); } File.Move(projectDetails.ProjectJsonPath, projectDetails.ProjectJsonPath + ".old"); if (projectDetails.AssemblyInfoPath != null && File.Exists(projectDetails.AssemblyInfoPath)) { File.Delete(projectDetails.AssemblyInfoPath); } var tempDir = Path.GetDirectoryName(tempCSProjPath); if (Directory.Exists(tempDir)) { Directory.Delete(tempDir, recursive: true); } } }
private void MigrateProperties(LegacyProjectSummary projectDetails, XElement xmlRoot, XNamespace ns) { var propertyGroupElement = xmlRoot .Descendants() .Where(e => e.Name.LocalName == LegacyProjectSummary.PROPERTY_GROUP_TAG && e.Descendants().Where(f => f.Name.LocalName == LegacyProjectSummary.OUTPUT_TYPE_TAG).Any()) .FirstOrDefault(); var newPropertyGroup = false; if (propertyGroupElement == null) { propertyGroupElement = new XElement(LegacyProjectSummary.PROPERTY_GROUP_TAG); newPropertyGroup = true; } //propertyGroupElement.Add(projectDetails.ProjectGuid); propertyGroupElement.Add(projectDetails.RootNameSpace); //propertyGroupElement.Add(projectDetails.AssemblyName); //propertyGroupElement.Add(projectDetails.CodeAnalysisRuleSet); if (projectDetails.GenerateAssemblyInfo != null) { propertyGroupElement.Add(projectDetails.GenerateAssemblyInfo); } if (projectDetails.AssemblyInfo != null) { foreach (var assemblyInfoElement in projectDetails.AssemblyInfo) { propertyGroupElement.Add(assemblyInfoElement); } } if (newPropertyGroup) { xmlRoot.Add(propertyGroupElement, ns); } }
private void MigrateDependencies(LegacyProjectSummary projectDetails, XElement xmlRoot, XNamespace ns) { MigrateAssemblyReferences(projectDetails.AssemblyReferences, xmlRoot, ns); MigrateProjectReferences(projectDetails.ProjectReferences, xmlRoot, ns); MigratePackageReferences(projectDetails.PackageReferences, xmlRoot, ns); }