/// <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); } }
// ========================================================================================= // Constructors // ========================================================================================= /// <summary> /// Initializes a new instance of the <see cref="XPackageSettings"/> class. /// </summary> /// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use.</param> public XPackageSettings(IServiceProvider serviceProvider) { XHelperMethods.VerifyNonNullArgument(serviceProvider, "serviceProvider"); ThreadHelper.ThrowIfNotOnUIThread(); if (serviceProvider != null) { // get the Visual Studio registry root ILocalRegistry3 localRegistry = XHelperMethods.GetService <ILocalRegistry3, SLocalRegistry>(serviceProvider); ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out this.visualStudioRegistryRoot)); } Instance = this; }