public void TestAssemblyMappingSQLConnectorGetAllNewDllPathsTest() { var nsMap = NSMappingSQLConnector.GetInstance().GetOrCreateOldNSMap(id, "A"); AssertAditional.SetEquals(new HashSet <string> { }, instance.GetAllNewDllPaths(id), "initial value"); var mapA = instance.GetOrCreateOldAssemblyMap(id, "path"); SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, "A", "A", nsMap, mapA); var targetA = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, "A"); AssertAditional.SetEquals(new HashSet <string> { null }, instance.GetAllNewDllPaths(id), "null entry"); var mapB = instance.GetOrCreateOldAssemblyMap(id, "path2"); SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, "B", "B", nsMap, mapB); var targetB = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, "B"); instance.UpdateAssemblyMapping(mapB, targetB, "pathNew", "name"); SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(targetB, "B"); AssertAditional.SetEquals(new HashSet <string> { null, "pathNew" }, instance.GetAllNewDllPaths(id), "first entry"); var mapC = instance.GetOrCreateOldAssemblyMap(id, "path3"); var mapD = instance.GetOrCreateOldAssemblyMap(id, "path3"); SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, "C", "C", nsMap, mapA); var targetC = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, "C"); SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, "D", "D", nsMap, mapA); var targetD = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, "D"); instance.UpdateAssemblyMapping(mapC, targetC, "pathNew2", "name2"); instance.UpdateAssemblyMapping(mapD, targetD, "pathNew3", "name3"); SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(targetC, "C"); SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(targetD, "D"); AssertAditional.SetEquals(new HashSet <string> { null, "pathNew", "pathNew2", "pathNew3" }, instance.GetAllNewDllPaths(id), "repeat old name"); var mapE = instance.GetOrCreateOldAssemblyMap(id, "path4"); SDKMappingSQLConnector.GetInstance().SaveOldSDKMapping(id, "E", "E", nsMap, mapA); var targetE = SDKMappingSQLConnector.GetInstance().GetSDKMappingByIdentifiers(id, "E"); instance.UpdateAssemblyMapping(mapE, targetE, "pathNew", "name"); SDKMappingSQLConnector.GetInstance().UpdateSDKMapping(targetE, "E"); AssertAditional.SetEquals(new HashSet <string> { null, "pathNew", "pathNew2", "pathNew3" }, instance.GetAllNewDllPaths(id), "dupplicate new entry"); }
// add <Reference> tags to the new sdk private void AddNewDllReferences(string csprojFilePath, string hintPathRoot, string newRelativeOutputPath, string xmlElementHintPathName, string xmlElementReferenceName, XNamespace ns, XDocument xdoc) { asMappingConnector.GetAllNewDllPaths(sdkId); var elements = asMappingConnector.GetAllNewDllPathsWithFullName(sdkId); string originalCurrentWorkingDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(new FileInfo(csprojFilePath).DirectoryName); // find the common path string commonPath = GetLongestCommonPrefix(new string[] { Path.GetFullPath(hintPathRoot), elements.ElementAt(0).Key }); // From stackoverflow: "Then you may need to cut the prefix on the right hand" string[] commonPathSplit = commonPath.Split('\\'); commonPathSplit.SetValue("", commonPathSplit.Length - 1); commonPath = String.Join("\\", commonPathSplit); // find how many folders up the common path is from the hintpath root // number of relative paths string[] hintSplit = Path.GetFullPath(csprojFilePath).Split('\\'); int numberOfRelativePathsDifference = hintSplit.Length - commonPathSplit.Length; // create relative path string prependedRelativePath = ""; for (int i = 0; i < numberOfRelativePathsDifference; i++) { prependedRelativePath += "..\\"; } Directory.SetCurrentDirectory(originalCurrentWorkingDirectory); foreach (var element in elements) { // new hint path = number of relative paths + (new path - common path) string hintpathRightSide = element.Key.Substring(commonPath.Length); string hintpath = prependedRelativePath + hintpathRightSide; // create new reference element XElement addedref = new XElement(ns + xmlElementReferenceName, new XAttribute("Include", element.Value), new XElement(ns + "SpecificVersion", "False"), new XElement(ns + xmlElementHintPathName, hintpath), new XElement(ns + "Private", "False") ); // add the element to the xml xdoc.Descendants(ns + "ItemGroup").First().AddFirst(addedref); } }