/// <summary> /// Rewrite this csproj file to migrate from packages.config to project.json: /// - Generate project.json /// - Replace {None Include="packages.confing"} to {None Include="project.json"} /// - Remove {References} reletated to NuGet packages /// - Remove packages.config /// </summary> /// <returns>true if any change</returns> public bool MigrateToProjectJson() { if (!HasPackagesConfig) { return(false); } ProjectJson.GeneratePackageJson(TargetFrameworkVersion, Folder, PackagesConfig.Packages); foreach (var r in GetElements("Reference")) { if (PackagesConfig.Packages.Any(x => r.Attribute("Include").Value.StartsWith(x.Id + ","))) { r.Remove(); } } foreach (var n in GetElements("None")) { var include = n.Attribute("Include"); if (include.Value == PackagesConfName) { n.ReplaceAll(new XAttribute("Include", ProjectJson.ProjectJsonName)); } } File.Delete(PackagesConfig.Path); return(true); }
/// <summary> /// Generate a wrap project.json file for *.xproj. /// </summary> /// <param name="wrapFolder"></param> public void GenerateWrapJson(string wrapFolder) { ProjectJson.GenerateWrapJson(TargetFrameworkVersion, wrapFolder, RelativePath, Dependencies); }