private static void FindCodeAssetsInProject(ICollection<PackageLoadingAssetFile> list, Package package) { if (package.IsSystem) return; var profile = package.Profiles.FindSharedProfile(); if (profile == null) return; foreach (var libs in profile.ProjectReferences.Where(x => x.Type == ProjectType.Library)) { var realFullPath = UPath.Combine(package.RootDirectory, libs.Location); string defaultNamespace; var codePaths = FindCodeAssetsInProject(realFullPath, out defaultNamespace); libs.RootNamespace = defaultNamespace; var dir = new UDirectory(realFullPath.GetFullDirectory()); var parentDir = dir.GetParent(); foreach (var codePath in codePaths) { list.Add(new PackageLoadingAssetFile(codePath, parentDir, realFullPath)); } } }
public void TestUPathGetParent() { // First directories var dir = new UDirectory("c:/"); Assert.AreEqual("c:/", dir.GetParent().FullPath); dir = new UDirectory("c:/a"); Assert.AreEqual("c:/", dir.GetParent().FullPath); dir = new UDirectory("c:/a/b"); Assert.AreEqual("c:/a", dir.GetParent().FullPath); dir = new UDirectory("/"); Assert.AreEqual("/", dir.GetParent().FullPath); dir = new UDirectory("/a"); Assert.AreEqual("/", dir.GetParent().FullPath); dir = new UDirectory("/a/b"); Assert.AreEqual("/a", dir.GetParent().FullPath); dir = new UDirectory("a"); Assert.AreEqual("", dir.GetParent().FullPath); dir = new UDirectory("a/b"); Assert.AreEqual("a", dir.GetParent().FullPath); // Now with files. var file = new UFile("c:/a.txt"); Assert.AreEqual("c:/", file.GetParent().FullPath); file = new UFile("c:/a/b.txt"); Assert.AreEqual("c:/a", file.GetParent().FullPath); file = new UFile("/a.txt"); Assert.AreEqual("/", file.GetParent().FullPath); file = new UFile("/a/b.txt"); Assert.AreEqual("/a", file.GetParent().FullPath); file = new UFile("a.txt"); Assert.AreEqual("", file.GetParent().FullPath); file = new UFile("a/b.txt"); Assert.AreEqual("a", file.GetParent().FullPath); }
private static void FindCodeAssetsInProject(ICollection<PackageLoadingAssetFile> list, Package package) { if (!package.IsSystem) //user code case { var profile = package.Profiles.FindSharedProfile(); if (profile != null) { foreach (var libs in profile.ProjectReferences.Where(x => x.Type == ProjectType.Library)) { var realFullPath = UPath.Combine(package.RootDirectory, libs.Location); var project = VSProjectHelper.LoadProject(realFullPath); var dir = new UDirectory(realFullPath.GetFullDirectory()); var parentDir = dir.GetParent(); foreach (var projectItem in project.Items.Where(x => x.ItemType == "Compile" || x.ItemType == "None"). Select(x => new UFile(x.EvaluatedInclude)). Where(x => AssetRegistry.IsProjectSourceCodeAssetFileExtension(x.GetFileExtension()))) { var csPath = UPath.Combine(dir, projectItem); list.Add(new PackageLoadingAssetFile(csPath, parentDir, realFullPath)); } project.ProjectCollection.UnloadAllProjects(); project.ProjectCollection.Dispose(); } } } }