private static IEnumerable <string> GetAllSupportedFiles() { var projectPath = ProjectPath.EndsWith("/") ? ProjectPath : ProjectPath + "/"; return(AssetDatabase.GetAllAssetPaths().Where(asset => { var absolutePath = Path.GetFullPath(asset).ConvertSeparatorsToUnity(); if (!absolutePath.StartsWith(projectPath)) { return false; } return IsSupportedExtension(Path.GetExtension(asset)); })); }
// ReSharper disable once SuggestBaseTypeForParameter public ProjectFile(List <FileToWrite> files, bool updateProjectFile, VsTfsSourceControlProvider tfs) { if (updateProjectFile && files.Count > 0) { ProjectFiles = new SortedDictionary <string, string>(StringComparer.OrdinalIgnoreCase); // ReSharper disable once AssignNullToNotNullAttribute var file = GetProjectPath(new DirectoryInfo(files[0].Directory)); ProjectFound = file != null; if (file == null) { return; } ProjectPath = file.FullName; Lines = File.ReadAllLines(ProjectPath).ToList(); ProjectDir = Path.GetDirectoryName(ProjectPath); if (!Lines.Any(l => l.Contains("<Compile Include="))) { ProjectFileIndexStart = Lines.FindLastIndex(l => l.Contains("</PropertyGroup>")) + 1; Lines.Insert(ProjectFileIndexStart, "</ItemGroup>"); Lines.Insert(ProjectFileIndexStart, "<ItemGroup>"); ProjectFileIndexStart++; } else { ProjectFileIndexStart = Lines.FindIndex(l => l.Contains("<Compile Include=")); } foreach (var line in Lines.Skip(ProjectFileIndexStart).TakeWhile(l => l.Contains("<Compile Include="))) { ProjectFiles.Add(line, line); } ProjectFileIndexEnd = ProjectFileIndexStart + ProjectFiles.Count; // Determine Line Format, defaulting if none currently exist var first = ProjectFiles.Keys.FirstOrDefault() ?? (ProjectPath.EndsWith("projitems") ? " <Compile Include=\"$(MSBuildThisFileDirectory)\" />" : " <Compile Include=\"\" />"); var startEndIndex = first.Contains("$(") ? first.IndexOf(")", first.IndexOf("$(", StringComparison.Ordinal), StringComparison.Ordinal) + 1 // Path contains Ms Build Variable : first.IndexOf("\"", StringComparison.Ordinal) + 1; LineFormat = first.Substring(0, startEndIndex) + "{0}" + first.Substring(first.LastIndexOf("\"", StringComparison.Ordinal), first.Length - first.LastIndexOf("\"", StringComparison.Ordinal)); } UpdateProjectFile = updateProjectFile; ProjectUpdated = false; Tfs = tfs; }
public static string GetProjectPath() { if (IsProjectRelativeToExecutable < 1) { if (!ProjectPath.EndsWith("/")) { return(ProjectPath + "/"); } return(ProjectPath); } else { string processPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); string combinedPath = Path.Combine(processPath, ProjectPath); combinedPath = combinedPath.Replace("\\", "/"); if (!combinedPath.EndsWith("/")) { combinedPath += "/"; } return(combinedPath); } }
private static string[] RelativeToProjectPath(string[] paths) { var projectPath = ProjectPath.EndsWith("/") ? ProjectPath : ProjectPath + "/"; return(paths.Select(d => d.StartsWith(projectPath) ? d.Substring(projectPath.Length) : d).ToArray()); }
public override bool Execute() { Console.WriteLine("Environment {0}", Environment); Console.WriteLine("Server {0}", Server); Console.WriteLine("Port {0}", Port); Console.WriteLine("ProjectPath {0}", ProjectPath); Console.WriteLine("OutputPath {0}", OutputPath); Project project; EnvironmentSettingsManager environmentManager; DeploymentResults results; DeploymentPackage package; bool result = false; //Create a temporary folder for the K2 project files string tempPath = Path.GetTempPath().Trim('\\').Trim('/'); string k2DeployFolder = tempPath + @"\K2Deploy"; DeleteDirectory(k2DeployFolder); try { Console.WriteLine("\n\n\n************** BEGIN PACKAGE ******************\n"); //Check parameters if (!ProjectPath.EndsWith(".k2proj")) { throw new ArgumentException("ProjectPath must end with .k2proj"); } //Create a temporary folder for the code string projectFolder = ProjectPath.Substring(0, ProjectPath.LastIndexOf('\\')); Console.WriteLine("\nProject Folder: " + projectFolder); //Copy the files to the temp folder Console.WriteLine("\nCreating temporary folder: " + k2DeployFolder); CopyFolder(projectFolder, k2DeployFolder); //Ensure we have access to all the files. Console.WriteLine("\nSetting writable permissions for folder: " + tempPath); bool success = SetAcl(k2DeployFolder, "F", true); if (!success) { throw new Exception("Failed to set ACLs on folder " + tempPath); } //Ensure the feils are all writable SetWritable(k2DeployFolder); //Load the project file string newProjectFile = k2DeployFolder + @"\" + ProjectPath.Substring(1 + ProjectPath.LastIndexOf('\\')); Console.WriteLine("\nLoading project file: " + newProjectFile); project = new Project(); project.Load(newProjectFile); // Compile the K2 Project Console.WriteLine("\nCompiling project file: " + newProjectFile); results = project.Compile(); //Grab the deployment package environmentManager = GetEnvironmentManager(); package = GetDeploymentPackage(project, environmentManager); Console.WriteLine("\nSetting writable permissions for folder: " + OutputPath); success = SetAcl(OutputPath, "F", true); if (!success) { throw new Exception("Failed to set ACLs on folder " + OutputPath); } //Ensure the feils are all writable SetWritable(OutputPath); Console.WriteLine("\nSaving deployment package to folder: " + OutputPath); package.Save(OutputPath, "K2DeploymentPackage"); result = true; //////Console.WriteLine("\nExecuting deployment package..."); //////results = package.Execute(); //////Console.WriteLine("\nSuccessful = " + results); //////result = results.Successful; //////Console.WriteLine("\nSuccessful = " + result); } catch (Exception ex) { Console.Write(ex.Message); throw; } finally { Console.WriteLine("\nDeleting k2DeployFolder " + k2DeployFolder); DeleteDirectory(k2DeployFolder); } Console.WriteLine("\n\n\n************** END PACKAGE ******************\n\n\n"); return(result); }
public void LoadProject(string path) { //ProjectPath = path; string fullPath = ""; if (Solution != null) { fullPath = Solution.SolutionPath.Replace(Solution.Name, ""); } if (ProjectPath.EndsWith(".csproj") || ProjectPath.EndsWith(".vbproj")) { #region Reading Project fullPath = fullPath + ProjectPath; System.Xml.XmlDocument document = new System.Xml.XmlDocument(); document.Load(fullPath); System.Xml.XmlNodeList itemGroupNodeList = document.GetElementsByTagName("ItemGroup"); foreach (System.Xml.XmlNode node in itemGroupNodeList) { foreach (System.Xml.XmlNode nodeChild in node.ChildNodes) { try { if (nodeChild.Name.ToLower() == "reference") { ProjectReference reference = new ProjectReference(); reference.Include = nodeChild.Attributes["Include"].Value; if (this.ProjectReferences == null) { this.ProjectReferences = new List <ProjectReference>(); } this.ProjectReferences.Add(reference); } else if (nodeChild.Name.ToLower() == "compile") { string [] fullFilePaths = nodeChild.Attributes["Include"].Value.Split('\\'); int count = 1; ProjectFolder folder = null; foreach (string str in fullFilePaths) { if (fullFilePaths.Length == count) { ProjectFiles file = new ProjectFiles(); file.Include = nodeChild.Attributes["Include"].Value; int index = file.Include.LastIndexOf('\\'); index++; if (index < 0) { index = 0; } file.Name = file.Include.Substring(index, file.Include.Length - index); if (folder == null) { this.ProjectFiles.Add(file); } else { folder.Files.Add(file); } } else { bool Exists = false; ProjectFolder parentFolder = folder; if (parentFolder == null) { folder = ProjectFolder.GetFolder(str, this.ProjectFolders, out Exists); } else { folder = ProjectFolder.GetFolder(str, parentFolder.Folders, out Exists); } if (!Exists) { folder.Parent = parentFolder; if (parentFolder == null) { this.ProjectFolders.Add(folder); } else { parentFolder.Folders.Add(folder); } } } count++; } } } catch (Exception ex) { continue; } } } #endregion } else { fullPath = fullPath + ProjectPath; DirectoryInfo dirInfo = new DirectoryInfo(fullPath); if (dirInfo != null) { GetFolderProjectStructure(dirInfo, null); } } }