public static void FixProjectReferences (this XmlDocument csproj, string suffix, FixReferenceDelegate fixCallback = null) { var nodes = csproj.SelectNodes ("/*/*/*[local-name() = 'ProjectReference']"); if (nodes.Count == 0) return; foreach (XmlNode n in nodes) { var name = n ["Name"].InnerText; string fixed_name = null; if (fixCallback != null && !fixCallback (name, out fixed_name)) continue; var include = n.Attributes ["Include"]; string fixed_include; if (fixed_name == null) { fixed_include = include.Value; fixed_include = fixed_include.Replace (".csproj", suffix + ".csproj"); fixed_include = fixed_include.Replace (".fsproj", suffix + ".fsproj"); } else { var unix_path = include.Value.Replace ('\\', '/'); var unix_dir = System.IO.Path.GetDirectoryName (unix_path); fixed_include = System.IO.Path.Combine (unix_dir, fixed_name + System.IO.Path.GetExtension (unix_path)); fixed_include = fixed_include.Replace ('/', '\\'); } n.Attributes ["Include"].Value = fixed_include; var nameElement = n ["Name"]; name = System.IO.Path.GetFileNameWithoutExtension (fixed_include.Replace ('\\', '/')); nameElement.InnerText = name; } }
public static void FixProjectReferences(this XmlDocument csproj, string?subdir, string suffix, FixReferenceDelegate fixCallback) { var nodes = csproj.SelectNodes("/*/*/*[local-name() = 'ProjectReference']"); foreach (XmlNode?n in nodes) { if (n == null) { continue; } var nameNode = n["Name"]; var includeAttribute = n.Attributes["Include"]; var include = includeAttribute.Value; include = include.Replace('\\', '/'); if (!fixCallback(include, subdir, suffix, out var fixed_include)) { continue; } var name = Path.GetFileNameWithoutExtension(fixed_include); fixed_include = fixed_include.Replace('/', '\\'); includeAttribute.Value = fixed_include; if (nameNode != null) { nameNode.InnerText = name; } } }
public static void FixProjectReferences(this XmlDocument csproj, string suffix, FixReferenceDelegate fixCallback) => FixProjectReferences(csproj, null, suffix, fixCallback);