public void ConfigProperties() { using (PackageTestEnvironment testEnv = new PackageTestEnvironment()) { IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage; Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage."); // Get (2 different configs) string propertyName = "ConfigProperty"; string value = null; int hr = buildProperty.GetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual("DebugValue", value); hr = buildProperty.GetPropertyValue(propertyName, "Release", (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual("ReleaseValue", value); // Set (with get to confirm) string newValue = "UpdatedConfig"; hr = buildProperty.SetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, newValue); Assert.AreEqual <int>(VSConstants.S_OK, hr, "SetPropertyValue failed"); hr = buildProperty.GetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual(newValue, value); } }
bool IPropertyAccessor.TryGetProperty(string propertyName, out object result) { if (this.vsBuild != null) { string value = ""; if (ErrorHandler.Succeeded(vsBuild.GetPropertyValue( propertyName, "", (uint)_PersistStorageType.PST_USER_FILE, out value))) { result = value; return true; } if (msBuildProject != null && dteProject != null) { var configName = this.dteProject.ConfigurationManager.ActiveConfiguration.ConfigurationName + "|" + this.dteProject.ConfigurationManager.ActiveConfiguration.PlatformName; if (ErrorHandler.Succeeded(vsBuild.GetPropertyValue( propertyName, configName, (uint)_PersistStorageType.PST_USER_FILE, out value))) { result = value; return true; } } } // We always succeed, but return null. This // is easier for the calling code than catching // a binder exception. result = null; return true; }
public void GlobalProperties() { using (PackageTestEnvironment testEnv = new PackageTestEnvironment()) { IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage; Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage."); // Get string propertyName = "GlobalProperty"; string value = null; int hr = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual("Global", value); // Set (with get to confirm) string newValue = "UpdatedGlobal"; hr = buildProperty.SetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, newValue); Assert.AreEqual <int>(VSConstants.S_OK, hr, "SetPropertyValue failed"); hr = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual(newValue, value); // Remove (with get to confirm) hr = buildProperty.RemoveProperty(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE); Assert.AreEqual <int>(VSConstants.S_OK, hr, "RemoveProperty failed"); hr = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual(String.Empty, value); } }
/// <summary> /// Retreive the value of the specified property from storage /// </summary> /// <param name="propertyName">Name of the property to retrieve</param> /// <returns></returns> public string GetPropertyValue(string propertyName) { // Handle multiple properties string[] propertyNames = propertyName.Split(','); string[] propertyValues = new string[propertyNames.Length]; bool initialized = false; if (configs == null) { for (int i = 0; i < propertyNames.Length; i++) { buildPropStorage.GetPropertyValue(propertyNames[i], String.Empty, (uint)_PersistStorageType.PST_PROJECT_FILE, out propertyValues[i]); } } else { foreach (string config in configs) { string[] configValues = new string[propertyNames.Length]; for (int i = 0; i < propertyNames.Length; i++) { buildPropStorage.GetPropertyValue(propertyNames[i], config, (uint)_PersistStorageType.PST_PROJECT_FILE, out configValues[i]); } if (!initialized) { Array.Copy(configValues, propertyValues, propertyNames.Length); initialized = true; } else { bool equals = true; for (int i = 0; i < propertyNames.Length; i++) { if (!(equals = (propertyValues[i] != configValues[i]))) { break; } } if (!equals) { // multiple config with different value for the property for (int i = 0; i < propertyNames.Length; i++) { propertyValues[i] = string.Empty; } break; } } } } return(string.Join(",", propertyValues)); }
private bool PrepareNodeStartupInfo(string uniqueName) { string targetDir = null; string startupInfoFile = "startupinfo.xml"; string startupFile = null; string nodeExeArguments; propertiesList.TryGetValue(NodejsUwpConstants.NodeExeArguments, out nodeExeArguments); string scriptArguments; propertiesList.TryGetValue(NodejsUwpConstants.ScriptArguments, out scriptArguments); string canonicalName = null; EnvDTE.DTE dte = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE)); IVsSolution solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution)); IVsHierarchy hierarchy; solution.GetProjectOfUniqueName(uniqueName, out hierarchy); IVsBuildPropertyStorage bps = hierarchy as IVsBuildPropertyStorage; get_CanonicalName(out canonicalName); bps.GetPropertyValue("TargetDir", canonicalName, (uint)_PersistStorageType.PST_PROJECT_FILE, out targetDir); string nodeStartupInfoFilePath = string.Format(CultureInfo.InvariantCulture, "{0}{1}", targetDir, startupInfoFile); // Get values to put into startupinfo.xml bps.GetPropertyValue("StartupFile", canonicalName, (uint)_PersistStorageType.PST_PROJECT_FILE, out startupFile); if (string.IsNullOrEmpty(startupFile)) { MessageBox.Show("A startup file for the project has not been selected.", "NTVS IoT Extension", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } XDocument xdoc = new XDocument(); XElement srcTree = new XElement("StartupInfo", new XElement("Script", startupFile), new XElement("NodeOptions", nodeExeArguments), new XElement("ScriptArgs", scriptArguments) ); xdoc.Add(srcTree); // Make sure file is writable File.SetAttributes(nodeStartupInfoFilePath, FileAttributes.Normal); xdoc.Save(nodeStartupInfoFilePath); return(true); }
public object GetProperty(bool perUser, string configName, string propertyName, object defaultValue) { System.Diagnostics.Debug.Assert(defaultValue != null); object value = null; #if false // throws and seems to never work // first try to read it from the config object itself object config = GetConfigObject(configName); if (config != null) { value = GetDynamicProperty(propertyName, config); } #endif // otherwise, try to read it from the buildstorage if (value == null && buildStorage != null) { string stringValue; int hr = buildStorage.GetPropertyValue(propertyName, configName , (uint)(perUser ? _PersistStorageType.PST_USER_FILE : _PersistStorageType.PST_PROJECT_FILE) , out stringValue); if (hr == 0) { value = stringValue; } } // return the found value if (value != null) { if (defaultValue != null) { try { return(Convert.ChangeType(value, defaultValue.GetType(), CultureInfo.InvariantCulture)); } catch (System.InvalidCastException) { return(defaultValue); } } else { return(value); } } else { return(defaultValue); } }
private string GetOutputFileName() { if (!string.IsNullOrEmpty(_outputFile)) { return(_outputFile); } IVsSolution solution = WebEssentialsPackage.GetGlobalService <IVsSolution>(typeof(SVsSolution)); Project project = ProjectHelpers.GetProject(SourceFilePath); IVsHierarchy hierarchy = null; if (project != null && solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy) != VSConstants.S_OK) { return(string.Empty); } IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage; if (buildPropertyStorage == null) { _outputFile = Path.ChangeExtension(SourceFilePath, ".js"); } else { string outputFile, outputDir; string config = WebEssentialsPackage.DTE.Solution.SolutionBuild.ActiveConfiguration.Name; int resultFile = buildPropertyStorage.GetPropertyValue("TypeScriptOutFile", config, (uint)_PersistStorageType.PST_PROJECT_FILE, out outputFile); int resultDir = buildPropertyStorage.GetPropertyValue("TypeScriptOutDir", config, (uint)_PersistStorageType.PST_PROJECT_FILE, out outputDir); if (!string.IsNullOrEmpty(outputFile) && resultFile == VSConstants.S_OK) { _outputFile = Path.Combine(ProjectHelpers.GetRootFolder(project), outputFile); } else if (!string.IsNullOrEmpty(outputDir) && resultDir == VSConstants.S_OK) { string dir = Path.Combine(ProjectHelpers.GetRootFolder(project), outputDir); string file = Path.ChangeExtension(Path.GetFileName(SourceFilePath), ".js"); _outputFile = Path.Combine(dir, file); } } if (string.IsNullOrEmpty(_outputFile)) { _outputFile = Path.ChangeExtension(SourceFilePath, ".js"); } return(_outputFile); }
public async Task <string> GetPropertyValueAsync(string propertyName) { Assumes.NotNullOrEmpty(propertyName); await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); if (_propertyStorage != null) { string output = null; var result = _propertyStorage.GetPropertyValue( pszPropName: propertyName, pszConfigName: null, storage: (uint)_PersistStorageType.PST_PROJECT_FILE, pbstrPropValue: out output); if (result == VSConstants.S_OK && !string.IsNullOrWhiteSpace(output)) { return(output); } } try { var property = _project.Properties.Item(propertyName); return(property?.Value as string); } catch (ArgumentException) { // If the property doesn't exist this will throw an argument exception } return(null); }
public void TestGlobalPropertyMatch() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); Microsoft.Build.BuildEngine.Project buildProject = typeof(ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(project, new object[] { }) as Microsoft.Build.BuildEngine.Project; IVsHierarchy nestedProject = Utilities.GetNestedHierarchy(project, "ANestedProject"); IVsBuildPropertyStorage nestedProjectPropertyStorage = nestedProject as IVsBuildPropertyStorage; foreach (string property in Enum.GetNames(typeof(GlobalProperty))) { string nestedProjectGlobalProperty; // We will pass in the debug configuration since the GetPropertyValue will change the global property to whatever does not exist as configuration like empty or null. nestedProjectPropertyStorage.GetPropertyValue(property, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out nestedProjectGlobalProperty); string parentProjectGlobalProperty = buildProject.GlobalProperties[property].Value; bool result; bool isBoolean = (Boolean.TryParse(parentProjectGlobalProperty, out result) == true); Assert.IsTrue(String.Compare(nestedProjectGlobalProperty, parentProjectGlobalProperty, isBoolean ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0, "The following global Properties do not match for Property: " + property + " Nested :" + nestedProjectGlobalProperty + " Parent:" + parentProjectGlobalProperty); } }); }
public string GetProjectProperty(Project dteProject, string propertyName, string configuration) { if (dteProject == null) { throw new ArgumentNullException(nameof(dteProject)); } if (string.IsNullOrWhiteSpace(propertyName)) { throw new ArgumentNullException(nameof(propertyName)); } string value = null; IVsHierarchy projectHierarchy = this.GetIVsHierarchy(dteProject); IVsBuildPropertyStorage propertyStorage = projectHierarchy as IVsBuildPropertyStorage; if (propertyStorage != null) { var hr = propertyStorage.GetPropertyValue(propertyName, configuration, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); // E_XML_ATTRIBUTE_NOT_FOUND is returned when the property does not exist - this is OK. Debug.Assert(!ErrorHandler.Succeeded(hr) || hr != E_XML_ATTRIBUTE_NOT_FOUND, $"Failed to get the property '{propertyName}' for project '{dteProject.Name}'."); } else { Debug.Fail("Could not get IVsBuildPropertyStorage for EnvDTE.Project"); } return(value); }
public T GetPropertyValue <T>([CallerMemberName] string memberName = "") { object value = null; if (pendingValuesToBePersisted.TryGetValue(memberName, out value)) { return((T)value); } string valueAsString; if (ErrorHandler.Succeeded( vsBuildPropertyStorage.GetPropertyValue( memberName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out valueAsString))) { if (typeof(T) != typeof(string)) { value = TypeDescriptor .GetConverter(typeof(T)) .ConvertFromString(valueAsString); } else { value = valueAsString; } } return(value != null ? (T)value : default(T)); }
private static bool IsOldSlowCheetahInstalled(IVsBuildPropertyStorage buildPropertyStorage) { buildPropertyStorage.GetPropertyValue("SlowCheetahImport", null, (uint)_PersistStorageType.PST_PROJECT_FILE, out string propertyValue); if (!string.IsNullOrEmpty(propertyValue)) { return(true); } buildPropertyStorage.GetPropertyValue("SlowCheetahTargets", null, (uint)_PersistStorageType.PST_PROJECT_FILE, out propertyValue); if (!string.IsNullOrEmpty(propertyValue)) { return(true); } return(false); }
/// <summary> /// Returns a string to display in the command-line combo box, based on project state /// </summary> /// <returns>String to display</returns> private string MakeCommandLineComboText() { string Text = ""; IVsHierarchy ProjectHierarchy; if (UnrealVSPackage.Instance.SolutionBuildManager.get_StartupProject(out ProjectHierarchy) == VSConstants.S_OK && ProjectHierarchy != null) { Project SelectedStartupProject = Utils.HierarchyObjectToProject(ProjectHierarchy); if (SelectedStartupProject != null) { Configuration SelectedConfiguration = SelectedStartupProject.ConfigurationManager.ActiveConfiguration; if (SelectedConfiguration != null) { IVsBuildPropertyStorage PropertyStorage = ProjectHierarchy as IVsBuildPropertyStorage; if (PropertyStorage != null) { // Query the property store for the debugger arguments string ConfigurationName = String.Format("{0}|{1}", SelectedConfiguration.ConfigurationName, SelectedConfiguration.PlatformName); if (PropertyStorage.GetPropertyValue("LocalDebuggerCommandArguments", ConfigurationName, (uint)_PersistStorageType.PST_USER_FILE, out Text) != VSConstants.S_OK) { if (PropertyStorage.GetPropertyValue("StartArguments", ConfigurationName, (uint)_PersistStorageType.PST_USER_FILE, out Text) != VSConstants.S_OK) { Text = ""; } } // for "Game" projects automatically remove the game project filename from the start of the command line var ActiveConfiguration = (SolutionConfiguration2)UnrealVSPackage.Instance.DTE.Solution.SolutionBuild.ActiveConfiguration; if (UnrealVSPackage.Instance.IsUE4Loaded && Utils.IsGameProject(SelectedStartupProject) && Utils.HasUProjectCommandLineArg(ActiveConfiguration.Name)) { string AutoPrefix = Utils.GetAutoUProjectCommandLinePrefix(SelectedStartupProject); if (!string.IsNullOrEmpty(AutoPrefix)) { if (Text.Trim().StartsWith(AutoPrefix, StringComparison.OrdinalIgnoreCase)) { Text = Text.Trim().Substring(AutoPrefix.Length).Trim(); } } } } } } } return(Text); }
private string GetOutputFileName() { if (!string.IsNullOrEmpty(_outputFile)) { return(_outputFile); } IVsSolution solution = EditorExtensionsPackage.GetGlobalService <IVsSolution>(typeof(SVsSolution)); Project project = ProjectHelpers.GetProject(SourceFilePath); IVsHierarchy hierarchy; ErrorHandler.ThrowOnFailure(solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy)); IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage; if (buildPropertyStorage == null) { _outputFile = Path.ChangeExtension(SourceFilePath, ".js"); } else { string outputFile, outputDir; string config = EditorExtensionsPackage.DTE.Solution.SolutionBuild.ActiveConfiguration.Name; ErrorHandler.ThrowOnFailure(buildPropertyStorage.GetPropertyValue("TypeScriptOutFile", config, (uint)_PersistStorageType.PST_PROJECT_FILE, out outputFile)); ErrorHandler.ThrowOnFailure(buildPropertyStorage.GetPropertyValue("TypeScriptOutDir", config, (uint)_PersistStorageType.PST_PROJECT_FILE, out outputDir)); if (!string.IsNullOrEmpty(outputFile)) { _outputFile = Path.Combine(ProjectHelpers.GetRootFolder(project), outputFile); } else if (!string.IsNullOrEmpty(outputDir)) { string dir = Path.Combine(ProjectHelpers.GetRootFolder(project), outputDir); string file = Path.ChangeExtension(Path.GetFileName(SourceFilePath), ".js"); _outputFile = Path.Combine(dir, file); } } if (string.IsNullOrEmpty(_outputFile)) { _outputFile = Path.ChangeExtension(SourceFilePath, ".js"); } return(_outputFile); }
/// <summary> /// Reads a property from the project's .user file. /// </summary> /// <param name="project">The project to read the property from.</param> /// <param name="propertyName">The name of the property to read.</param> /// <returns>The value of the property.</returns> public string GetUserProperty(Project project, string propertyName) { ThreadHelper.ThrowIfNotOnUIThread(); IVsBuildPropertyStorage propertyStore = GetProjectPropertyStore(project); ErrorHandler.ThrowOnFailure( propertyStore.GetPropertyValue(propertyName, null, UserFileFlag, out string value), HrPropertyNotFound); return(value); }
string GetBuildProperty(IVsBuildPropertyStorage propertyStorage, string key, string configuration = "") { string result = null; if (propertyStorage != null) { propertyStorage.GetPropertyValue(key, configuration, (uint)_PersistStorageType.PST_PROJECT_FILE, out result); } return(result); }
public static string GetMSBuildPropertyValue(this IVsBuildPropertyStorage storage, string property, string defaultValue) { string value = null; if (storage.GetPropertyValue(property, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value) == VSConstants.S_OK) { return(value); } return(defaultValue); }
int IVsBuildPropertyStorage.GetPropertyValue(string propertyName, string configName, uint storage, out string propertyValue) { propertyValue = null; IVsBuildPropertyStorage cfg = _innerCfg as IVsBuildPropertyStorage; if (cfg != null) { return(cfg.GetPropertyValue(propertyName, configName, storage, out propertyValue)); } return(VSConstants.S_OK); }
internal static string GetTypeScriptBackedJavaScriptFile(IVsProject project, string pathToFile) { //Need to deal with the format being relative and explicit IVsBuildPropertyStorage props = (IVsBuildPropertyStorage)project; String outDir; ErrorHandler.ThrowOnFailure(props.GetPropertyValue(NodeProjectProperty.TypeScriptOutDir, null, 0, out outDir)); string projHome = GetProjectHome(project); return(GetTypeScriptBackedJavaScriptFile(projHome, outDir, pathToFile)); }
private string GetStringPropertyValue(string propertyName) { IVsSolution solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution)); IVsHierarchy hierarchy; solution.GetProjectOfUniqueName(GetProjectUniqueName(), out hierarchy); IVsBuildPropertyStorage bps = hierarchy as IVsBuildPropertyStorage; string property = null; bps.GetPropertyValue(propertyName, this.GetBaseCfgCanonicalName(), (uint)_PersistStorageType.PST_PROJECT_FILE, out property); return(property); }
bool IsCSharpXamlForHtml5(string pszMkDocument) { //------------------------------------------------- // Check if project is of type "C#/XAML for HTML5": //------------------------------------------------- bool isCSharpXamlForHtml5 = false; // default value. EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)vsServiceProvider.GetService(typeof(EnvDTE.DTE)); var projectItem = dte.Solution.FindProjectItem(pszMkDocument); var project = projectItem.ContainingProject; string projectUniqueName = project.UniqueName; IVsSolution solution = GetService(typeof(SVsSolution)) as IVsSolution; IVsHierarchy hierarchy; solution.GetProjectOfUniqueName(projectUniqueName, out hierarchy); IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage; if (buildPropertyStorage != null) { string value; buildPropertyStorage.GetPropertyValue("IsCSharpXamlForHtml5", "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out value); if (value != null && value.Trim().ToLower() == "true") { isCSharpXamlForHtml5 = true; } else { buildPropertyStorage.GetPropertyValue("IsOpenSilver", "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out value); if (value != null && value.Trim().ToLower() == "true") { isCSharpXamlForHtml5 = true; } } } return(isCSharpXamlForHtml5); }
Evaluate(IVsBuildPropertyStorage propertyStorage, string configName, string input) { const string pattern = @"\$\((\w+)\)"; MatchCollection matches = Regex.Matches(input, pattern); var output = input; foreach (Match match in matches) { var name = match.Groups[1].Value; string value; propertyStorage.GetPropertyValue(name, configName, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); output = output.Replace(string.Format("$({0})", name), value); } return(output); }
/// <summary> /// Checks the project file to see if the appropriate import has been made to slow Cheetah. /// </summary> /// <param name="buildPropertyStorage">Project's build property storage interface.</param> /// <returns>True if the SlowCheetah import is in the project file; otherwise false.</returns> #if USE_SLOWCHEETAH_TARGET_PROPERTY_FOR_IMPORT private bool IsSlowCheetahImported(IVsBuildPropertyStorage buildPropertyStorage) { // check to see if the SlowCheetahImport property is set to true by the import file string propertyValue; buildPropertyStorage.GetPropertyValue(Resources.String_SlowCheetahImportProp, "|", (uint)_PersistStorageType.PST_PROJECT_FILE, out propertyValue); if (!string.IsNullOrWhiteSpace(propertyValue)) { // this property is assigned the value of $(MSBuildThisFileFullPath), which sets it to the import path of the SlowCheetah targets file // this is to make checking of the import fast and efficient, since this is not currently supported by VS return(true); } return(false); }
private bool GetDebugFlag(string name, bool defaultValue) { string value; string canonicalName; IVsBuildPropertyStorage bps = (IVsBuildPropertyStorage)PythonConfig; get_CanonicalName(out canonicalName); int hr = bps.GetPropertyValue(name, canonicalName, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); if (Microsoft.VisualStudio.ErrorHandler.Failed(hr)) { return(defaultValue); } return(value.Equals("true", StringComparison.OrdinalIgnoreCase)); }
public string GetProjectBuildProperty(Project prj, string name) { string output = null; object service = null; IVsSolution solution = null; IVsHierarchy hierarchy = null; int? result = 0; service = GetServiceObject(prj.DTE, typeof(IVsSolution)); solution = (IVsSolution)service; result = solution?.GetProjectOfUniqueName(prj.UniqueName, out hierarchy); IVsBuildPropertyStorage buildPropStorage = (IVsBuildPropertyStorage)hierarchy; buildPropStorage?.GetPropertyValue(name, String.Empty, (uint)_PersistStorageType.PST_PROJECT_FILE, out output); return(output); }
private static string GetMSBuildProperty(IVsBuildPropertyStorage buildPropertyStorage, string name, string configName) { ThreadHelper.ThrowIfNotOnUIThread(); string output; var result = buildPropertyStorage.GetPropertyValue( name, configName, (uint)_PersistStorageType.PST_PROJECT_FILE, out output); if (result != NuGetVSConstants.S_OK || string.IsNullOrWhiteSpace(output)) { return(null); } return(output); }
bool IPropertyAccessor.TryGetProperty(string propertyName, out object result) { if (vsBuild != null) { string value = ""; if (ErrorHandler.Succeeded(vsBuild.GetPropertyValue( propertyName, configName, (uint)_PersistStorageType.PST_PROJECT_FILE, out value))) { result = value; return(true); } } // We always succeed, but return null. This // is easier for the calling code than catching // a binder exception. result = null; return(true); }
private static string GetMSBuildProperty(IVsBuildPropertyStorage buildPropertyStorage, string name) { ThreadHelper.ThrowIfNotOnUIThread(); string output; // passing pszConfigName as null since string.Empty causes it to reevaluate // for each property read. var result = buildPropertyStorage.GetPropertyValue( pszPropName: name, pszConfigName: null, storage: (uint)_PersistStorageType.PST_PROJECT_FILE, pbstrPropValue: out output); if (result != VSConstants.S_OK || string.IsNullOrWhiteSpace(output)) { return(null); } return(output); }
public async Task <string> GetPropertyValueAsync(string propertyName) { Assumes.NotNullOrEmpty(propertyName); await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); string output = null; var result = _propertyStorage.GetPropertyValue( pszPropName: propertyName, pszConfigName: null, storage: (uint)_PersistStorageType.PST_PROJECT_FILE, pbstrPropValue: out output); if (result != VSConstants.S_OK || string.IsNullOrWhiteSpace(output)) { return(null); } return(output); }
static string GetPropertyFromCSProj(string propertyName, string configurationName, EnvDTE.Project proj) { // Credits: https://social.msdn.microsoft.com/Forums/vstudio/en-US/d3ee9c26-02ca-45cc-b930-02cbf09f18b6/modify-custom-property-without-modifying-csproj-file?forum=vsx object service = GetService(proj.DTE, typeof(IVsSolution)); IVsSolution solution = (IVsSolution)service; IVsHierarchy hierarchy; int result = solution.GetProjectOfUniqueName(proj.UniqueName, out hierarchy); if (result == 0) { IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage; if (buildPropertyStorage != null) { string value; buildPropertyStorage.GetPropertyValue(propertyName, configurationName, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); return(value ?? ""); } } return(""); }
private bool ValidateSlowCheetahTargetsAvailable(IVsBuildPropertyStorage buildPropertyStorage, string projectFullPath, string importPath, out bool addImports) { addImports = false; string importsExpression = string.Format("$({0})",Settings.Default.SlowCheetahTargets); #if USE_SLOWCHEETAH_TARGET_PROPERTY_FOR_IMPORT if (!IsSlowCheetahImported(buildPropertyStorage)) { #else if (IsSlowCheetahImported(projectFullPath, importsExpression)) { #endif return true; } if (HasUserAcceptedWarningMessage(projectFullPath, importPath)) { addImports = true; return true; } return false; } /// <summary> /// Checks the project file to see if the appropriate import has been made to slow Cheetah. /// </summary> /// <param name="buildPropertyStorage">Project's build property storage interface.</param> /// <returns>True if the SlowCheetah import is in the project file; otherwise false.</returns> #if USE_SLOWCHEETAH_TARGET_PROPERTY_FOR_IMPORT private bool IsSlowCheetahImported(IVsBuildPropertyStorage buildPropertyStorage) { // check to see if the SlowCheetahImport property is set to true by the import file string propertyValue; buildPropertyStorage.GetPropertyValue(Resources.String_SlowCheetahImportProp, "|", (uint) _PersistStorageType.PST_PROJECT_FILE, out propertyValue); if (!string.IsNullOrWhiteSpace(propertyValue)) { // this property is assigned the value of $(MSBuildThisFileFullPath), which sets it to the import path of the SlowCheetah targets file // this is to make checking of the import fast and efficient, since this is not currently supported by VS return true; } return false; }