/// <summary> /// When building with only a xsproj in the solution, the SolutionX variables are not /// defined, so we have to define them here. /// </summary> /// <param name="project">The project where the properties are defined.</param> internal static void DefineSolutionProperties(ProjectNode project) { IVsSolution solution = XHelperMethods.GetService <IVsSolution, SVsSolution>(project.Site); object solutionPathObj; ThreadHelper.ThrowIfNotOnUIThread(); ErrorHandler.ThrowOnFailure(solution.GetProperty((int)__VSPROPID.VSPROPID_SolutionFileName, out solutionPathObj)); string solutionPath = (string)solutionPathObj; XPackageSettings settings = XPackageSettings.Instance; string devEnvDir = XHelperMethods.EnsureTrailingDirectoryChar(Path.GetDirectoryName(settings.DevEnvPath)); string[][] properties = new string[][] { new string[] { XProjectFileConstants.DevEnvDir, devEnvDir }, new string[] { XProjectFileConstants.SolutionPath, solutionPath }, new string[] { XProjectFileConstants.SolutionDir, XHelperMethods.EnsureTrailingDirectoryChar(Path.GetDirectoryName(solutionPath)) }, new string[] { XProjectFileConstants.SolutionExt, Path.GetExtension(solutionPath) }, new string[] { XProjectFileConstants.SolutionFileName, Path.GetFileName(solutionPath) }, new string[] { XProjectFileConstants.SolutionName, Path.GetFileNameWithoutExtension(solutionPath) }, }; foreach (string[] property in properties) { string propertyName = property[0]; string propertyValue = property[1]; project.BuildProject.SetGlobalProperty(propertyName, propertyValue); } }
public static string GetRelativePath(string basePath, string subPath) { VerifyStringArgument(basePath, "basePath"); VerifyStringArgument(subPath, "subPath"); if (!Path.IsPathRooted(basePath)) { throw new ArgumentException("The 'basePath' is not rooted."); } if (!Path.IsPathRooted(subPath)) { return(subPath); } if (!String.Equals(Path.GetPathRoot(basePath), Path.GetPathRoot(subPath), StringComparison.OrdinalIgnoreCase)) { // both paths have different roots so we can't make them relative return(subPath); } // Url.MakeRelative method requires the base path to be ended with a '\' if it is a folder, // otherwise it considers it as a file so we need to make sure that the folder path is right basePath = XHelperMethods.EnsureTrailingDirectoryChar(basePath.Trim()); Url url = new Url(basePath); return(url.MakeRelative(new Url(subPath))); }
private void AddFolderButton_Click(object sender, EventArgs e) { string folder = XHelperMethods.EnsureTrailingDirectoryChar(this.folderTextBox.Text); if (this.pathsListBox.FindStringExact(folder) == ListBox.NoMatches) { CancelEventArgs ce = new CancelEventArgs(); this.OnFolderValidating(ce); if (!ce.Cancel) { this.folderTextBox.Text = folder; this.pathsListBox.SelectedIndex = this.pathsListBox.Items.Add(folder); this.OnFoldersChanged(EventArgs.Empty); } } }
private void UpdateButton_Click(object sender, EventArgs e) { string folder = XHelperMethods.EnsureTrailingDirectoryChar(this.folderTextBox.Text); int selectedIndex = this.pathsListBox.SelectedIndex; if (this.pathsListBox.SelectedItem.ToString() != folder) { CancelEventArgs ce = new CancelEventArgs(); this.OnFolderValidating(ce); if (!ce.Cancel) { this.pathsListBox.Items[selectedIndex] = folder; if (this.FoldersChanged != null) { this.FoldersChanged(this, new EventArgs()); } } } }