public static void SetupGenerated(IVsProject project, EnvDTE.Configuration configuration, String filter, List <string> files, bool generatedFilesPerConfiguration) { List <string> missing = new List <string>(); foreach (String file in files) { if (!Directory.Exists(Path.GetDirectoryName(file))) { Directory.CreateDirectory(Path.GetDirectoryName(file)); } if (!File.Exists(file)) { File.Create(file).Dispose(); } int found; uint id; VSDOCUMENTPRIORITY[] priority = new VSDOCUMENTPRIORITY[1]; project.IsDocumentInProject(file, out found, priority, out id); if (found == 0) { missing.Add(file); } } Package.Instance.VCUtil.AddGeneratedFiles(DTEUtil.GetProject(project as IVsHierarchy), configuration, filter, missing, generatedFilesPerConfiguration); }
/// <summary> /// Gets the active platform name. /// </summary> /// <param name="automationObject">The automation object.</param> /// <returns>The name of the active platform.</returns> internal static string GetActivePlatformName(EnvDTE.Project automationObject) { if (automationObject == null) { throw new ArgumentNullException("automationObject"); } string currentPlatformName = string.Empty; if (automationObject.ConfigurationManager != null) { try { EnvDTE.Configuration activeConfig = automationObject.ConfigurationManager.ActiveConfiguration; if (activeConfig != null) { currentPlatformName = activeConfig.PlatformName; } } catch (COMException ex) { if (System.Diagnostics.Debugger.IsAttached) { Debug.WriteLine("Failed to get active platform because of {0}", ex); } } } return(currentPlatformName); }
public string GetProjectQtVersion(EnvDTE.Project project) { ThreadHelper.ThrowIfNotOnUIThread(); EnvDTE.Configuration config = null; try { config = project.ConfigurationManager.ActiveConfiguration; } catch { // Accessing the ActiveConfiguration property throws an exception // if there's an "unconfigured" platform in the Solution platform combo box. config = project.ConfigurationManager.Item(1); } var version = GetProjectQtVersion(project, config); if (version == null && project.Globals.get_VariablePersists("Qt5Version")) { version = (string)project.Globals["Qt5Version"]; ExpandEnvironmentVariablesInQtVersion(ref version); return(VerifyIfQtVersionExists(version) ? version : null); } if (version == null) { version = GetSolutionQtVersion(project.DTE.Solution); } return(version); }
/// <summary> /// Gets the active configuration name. /// </summary> /// <param name="automationObject">The automation object.</param> /// <returns>The name of the active configuration.</returns> internal static string GetActiveConfigurationName(EnvDTE.Project automationObject) { Utilities.ArgumentNotNull("automationObject", automationObject); string currentConfigName = string.Empty; if (automationObject.ConfigurationManager != null) { try { EnvDTE.Configuration activeConfig = automationObject.ConfigurationManager.ActiveConfiguration; if (activeConfig != null) { currentConfigName = activeConfig.ConfigurationName; } } catch (COMException ex) { if (System.Diagnostics.Debugger.IsAttached) { Debug.WriteLine("Failed to get active configuration because of {0}", ex); } } } return(currentConfigName); }
private static EnvDTE.Properties TryGetDtePropertiesFromHierarchy(IVsHierarchy hierarchy) { try { EnvDTE.Project project = TryGetExtensibilityObject(hierarchy) as EnvDTE.Project; if (project == null) { return(null); } EnvDTE.ConfigurationManager configurationManager = project.ConfigurationManager; if (configurationManager == null) { return(null); } EnvDTE.Configuration activeConfiguration = configurationManager.ActiveConfiguration; if (activeConfiguration == null) { return(null); } return(activeConfiguration.Properties); } catch (Exception ex) { if (ErrorHandler.IsCriticalException(ex)) { throw; } return(null); } }
public BuildCallback(IVsProject project, EnvDTE.OutputWindowPane outputPane, EnvDTE.Configuration projectConfiguration) { Project = project; OutputPane = outputPane; ProjectConfiguration = projectConfiguration; }
private static void UpdateCodeAnalysisRuleSetPropertyInConfiguration(EnvDTE.Configuration config, string newRuleSetFilePath, string projectDirectoryFullPath) { var properties = config.Properties; try { var codeAnalysisRuleSetFileProperty = properties?.Item("CodeAnalysisRuleSet"); if (codeAnalysisRuleSetFileProperty != null) { var codeAnalysisRuleSetFileName = codeAnalysisRuleSetFileProperty.Value as string; if (!string.IsNullOrWhiteSpace(codeAnalysisRuleSetFileName)) { var codeAnalysisRuleSetFullPath = FileUtilities.ResolveRelativePath(codeAnalysisRuleSetFileName, projectDirectoryFullPath); codeAnalysisRuleSetFullPath = FileUtilities.NormalizeAbsolutePath(codeAnalysisRuleSetFullPath); var oldRuleSetFilePath = FileUtilities.NormalizeAbsolutePath(codeAnalysisRuleSetFullPath); if (codeAnalysisRuleSetFullPath.Equals(oldRuleSetFilePath, StringComparison.OrdinalIgnoreCase)) { var newRuleSetRelativePath = PathUtilities.GetRelativePath(projectDirectoryFullPath, newRuleSetFilePath); codeAnalysisRuleSetFileProperty.Value = newRuleSetRelativePath; } } } } catch (ArgumentException) { // Unfortunately the properties collection sometimes throws an ArgumentException // instead of returning null if the current configuration doesn't support CodeAnalysisRuleSet. // Ignore it and move on. } }
private string MakeConfigurationName(EnvDTE.Configuration configuration) { System.Windows.Threading.Dispatcher.CurrentDispatcher.VerifyAccess(); var platformName = string.Compare(configuration.PlatformName, "Any CPU") == 0 ? "AnyCPU" : configuration.PlatformName; return(string.Format("{0}|{1}", configuration.ConfigurationName, platformName)); }
public string Evaluate(EnvDTE.Configuration dteConfig, string value) { EnvDTE.Project dteProject = dteConfig.Owner as EnvDTE.Project; VCProject project = dteProject.Object as VCProject; VCConfiguration config = project.Configurations.Item(dteConfig.ConfigurationName + "|" + dteConfig.PlatformName); return(config.Evaluate(value)); }
private void OpenProjectInILSpy(EnvDTE.Project project, params string[] arguments) { EnvDTE.Configuration config = project.ConfigurationManager.ActiveConfiguration; string projectPath = Path.GetDirectoryName(project.FileName); string outputPath = config.Properties.Item("OutputPath").Value.ToString(); string assemblyFileName = project.Properties.Item("OutputFileName").Value.ToString(); OpenAssemblyInILSpy(Path.Combine(projectPath, outputPath, assemblyFileName), arguments); }
private void OpenProjectInILSpy(EnvDTE.Project project, params string[] arguments) { EnvDTE.Configuration config = project.ConfigurationManager.ActiveConfiguration; var outputFiles = config.OutputGroups.OfType <EnvDTE.OutputGroup>() .Where(g => g.FileCount > 0 && g.CanonicalName == "Built") .SelectMany(g => (object[])g.FileURLs).Select(f => f?.ToString()) .Where(CheckExtension).Select(f => f.Substring("file:///".Length)).ToArray(); OpenAssembliesInILSpy(outputFiles, arguments); }
/// <summary> /// Parses on configuration. /// </summary> private void parseConfiguration(EnvDTE.Configuration dteConfiguration) { // We create a new configuration-info object and fill it in... ProjectConfigurationInfo_CSharp configurationInfo = new ProjectConfigurationInfo_CSharp(); configurationInfo.ParentProjectInfo = m_projectInfo; configurationInfo.Name = Utils.call(() => dteConfiguration.ConfigurationName); configurationInfo.Platform = Utils.call(() => dteConfiguration.PlatformName); // We parse the configuration's properties, and set configuration // seetings from them... EnvDTE.Properties dteProperties = Utils.call(() => (dteConfiguration.Properties)); Dictionary <string, object> properties = getProperties(dteProperties); // Whether to optimize... configurationInfo.Optimize = getBoolProperty(properties, "Optimize"); // The output path and intermediate path... configurationInfo.OutputFolder = getStringProperty(properties, "OutputPath"); configurationInfo.IntermediateFolder = getStringProperty(properties, "IntermediatePath"); // Whether to treat warnings as errors... configurationInfo.ThreatWarningsAsErrors = getBoolProperty(properties, "TreatWarningsAsErrors"); // Defined constants (DEBUG, TRACE etc)... string definedConstants = getStringProperty(properties, "DefineConstants"); foreach (string definedConstant in Utils.split(definedConstants, ';')) { configurationInfo.addDefinedConstant(definedConstant); } // Whether to add debug symbols to the output... configurationInfo.Debug = getBoolProperty(properties, "DebugSymbols"); // Comma separated list of warnings to ignore... string warningsToIgnore = getStringProperty(properties, "NoWarn"); foreach (string warningToIgnore in Utils.split(warningsToIgnore, ',')) { configurationInfo.addWarningToIgnore(warningToIgnore); } // DebugInfo, e.g. "full"... configurationInfo.DebugInfo = getStringProperty(properties, "DebugInfo"); // File alignment... configurationInfo.FileAlignment = getIntProperty(properties, "FileAlignment"); // Warning level... configurationInfo.WarningLevel = getIntProperty(properties, "WarningLevel"); // We add the configuration-info to the project-info... m_projectInfo.addConfigurationInfo(configurationInfo); }
/// <summary> /// We find the collection of configurations (Release, Debug etc) /// and parse each one. /// </summary> private void parseConfigurations() { EnvDTE.ConfigurationManager configurationManager = Utils.call(() => (m_dteProject.ConfigurationManager)); int numConfigurations = Utils.call(() => (configurationManager.Count)); for (int i = 1; i <= numConfigurations; ++i) { EnvDTE.Configuration dteConfiguration = Utils.call(() => (configurationManager.Item(i, "") as EnvDTE.Configuration)); parseConfiguration(dteConfiguration); } }
public static string ToDisplayName([CanBeNull] this EnvDTE.Configuration configuration) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); if (configuration == null) { return("<undefined>"); } return(configuration.ConfigurationName + "|" + configuration.PlatformName); }
public void AddGeneratedFiles(EnvDTE.Project dteProject, EnvDTE.Configuration config, string filterName, List <string> paths, bool generatedFilesPerConfiguration) { VCProject project = dteProject.Object as VCProject; VCFilter filter = FindOrCreateFilter(project, filterName); if (generatedFilesPerConfiguration) { filter = FindOrCreateFilter(filter, config.PlatformName); filter = FindOrCreateFilter(filter, config.ConfigurationName); } string configurationName = config.ConfigurationName; string platformName = config.PlatformName; foreach (string path in paths) { if (!File.Exists(path)) { File.Create(path).Dispose(); } VCFile file = filter.AddFile(path); try { // // Remove the file otherwise it will be considered up to date. // File.Delete(path); } catch (Exception) { } // // Exclude the file from all other configurations // if (generatedFilesPerConfiguration) { foreach (VCFileConfiguration c in file.FileConfigurations) { if (!c.ProjectConfiguration.ConfigurationName.Equals(configurationName) || !c.ProjectConfiguration.Platform.Name.Equals(platformName)) { c.ExcludedFromBuild = true; } } } } }
private void OpenProjectOutputInILSpyCallback(object sender, EventArgs e) { var explorer = ((EnvDTE80.DTE2)GetGlobalService(typeof(EnvDTE.DTE))).ToolWindows.SolutionExplorer; var items = (object[])explorer.SelectedItems; foreach (EnvDTE.UIHierarchyItem item in items) { EnvDTE.Project project = (EnvDTE.Project)item.Object; EnvDTE.Configuration config = project.ConfigurationManager.ActiveConfiguration; string projectPath = Path.GetDirectoryName(project.FileName); string outputPath = config.Properties.Item("OutputPath").Value.ToString(); string assemblyFileName = project.Properties.Item("OutputFileName").Value.ToString(); OpenAssemblyInILSpy(Path.Combine(projectPath, outputPath, assemblyFileName)); } }
private void OpenCodeItemInILSpyCallback(object sender, EventArgs e) { var document = (EnvDTE.Document)(((EnvDTE80.DTE2)GetGlobalService(typeof(EnvDTE.DTE))).ActiveDocument); var selection = (EnvDTE.TextPoint)((EnvDTE.TextSelection)document.Selection).ActivePoint; var projectItem = document.ProjectItem; string navigateTo = null; // Find the full name of the method or class enclosing the current selection. // Note that order of testing is important, need to get the narrowest, most // internal element first. // // Add a prefix to match the ILSpy command line (see doc\Command Line.txt). // The prefix characters are documented in Appendix A of the C# specification: // E Event // F Field // M Method (including constructors, destructors, and operators) // N Namespace // P Property (including indexers) // T Type (such as class, delegate, enum, interface, and struct) navigateTo = GetCodeElementFullName("/navigateTo:M:", projectItem, selection, EnvDTE.vsCMElement.vsCMElementFunction); if (navigateTo == null) { navigateTo = GetCodeElementFullName("/navigateTo:E:", projectItem, selection, EnvDTE.vsCMElement.vsCMElementEvent); } if (navigateTo == null) { navigateTo = GetCodeElementFullName("/navigateTo:P:", projectItem, selection, EnvDTE.vsCMElement.vsCMElementProperty); } if (navigateTo == null) { navigateTo = GetCodeElementFullName("/navigateTo:T:", projectItem, selection, EnvDTE.vsCMElement.vsCMElementDelegate, EnvDTE.vsCMElement.vsCMElementEnum, EnvDTE.vsCMElement.vsCMElementInterface, EnvDTE.vsCMElement.vsCMElementStruct, EnvDTE.vsCMElement.vsCMElementClass); } EnvDTE.Project project = projectItem.ContainingProject; EnvDTE.Configuration config = project.ConfigurationManager.ActiveConfiguration; string projectPath = Path.GetDirectoryName(project.FileName); string outputPath = config.Properties.Item("OutputPath").Value.ToString(); string assemblyFileName = project.Properties.Item("OutputFileName").Value.ToString(); // Note that if navigateTo is still null this will just open ILSpy on the assembly. OpenAssemblyInILSpy(Path.Combine(projectPath, outputPath, assemblyFileName), navigateTo); }
/// <summary> /// Gets the active configuration name. /// </summary> /// <param name="automationObject">The automation object.</param> /// <returns>The name of the active configuartion.</returns> internal static string GetActiveConfigurationName(EnvDTE.Project automationObject) { Utilities.ArgumentNotNull("automationObject", automationObject); string currentConfigName = string.Empty; if (automationObject.ConfigurationManager != null) { EnvDTE.Configuration activeConfig = automationObject.ConfigurationManager.ActiveConfiguration; if (activeConfig != null) { currentConfigName = activeConfig.ConfigurationName; } } return(currentConfigName); }
EnvDTE.Property GetPropertySave(string name, bool onConfig) { EnvDTE.Property property = null; EnvDTE.Properties props = null; ThreadHelper.ThrowIfNotOnUIThread(); try { if (onConfig) { EnvDTE.ConfigurationManager confManager = this.ReferencedProjectObject.ConfigurationManager; if (null != confManager) { // Get the active configuration. EnvDTE.Configuration config = confManager.ActiveConfiguration; if (null != config) { // Get the output path for the current configuration. var obj = config.Properties; EnvDTE.Properties props1 = obj; if (null != props1) { property = props1.Item(name); } } } } else { // Most project types should implement the OutputPath property on their // configuration-dependent Properties object above. But if it wasn't found // there, check the project node Properties. props = this.ReferencedProjectObject.Properties; if (null != props) { property = props.Item(name); } } } catch (COMException) { } catch (ArgumentException) { } return(property); }
private void cbox_boardList_SelectionChanged(object sender, SelectionChangedEventArgs e) { // check if any solution is OPEN if (AVRonArduinoPackage.dte.Solution.Count > 0) { // check if any project is OPEN and GET it EnvDTE.Project project; if (AVRonArduinoPackage.dte.Solution.Projects.Count > 0) { project = AVRonArduinoPackage.dte.Solution.Projects.Item(1); // not sure why first project is at 1 and not at 0 if (project.Properties != null) { EnvDTE.Configuration configuration = project.ConfigurationManager.ActiveConfiguration; string postBuild = "", comPort = ""; if (cbox_portList.SelectedIndex != -1 && cbox_portList.Items.Count > 0) { comPort = cbox_portList.SelectedItem.ToString(); } string avrdudeAddress = AVRonArduinoPackage.path2 + "\\Extensions\\AVRonArduino\\avrdude\\"; int i = cbox_boardList.SelectedIndex - 1; if (i > 0) { project.Properties.Item("DeviceName").Value = boardDeviceList[i]; postBuild = avrdudeAddress + "avrdude -v -p " + boardDeviceList[i] + " -c " + boardProgrammerList[i] + " -P " + comPort + " -b " + boardBaudList[i] + " -D -U flash:w:$(AssemblyName).hex:i"; //$(AssemblyName) is Atmel Studio MACRO configuration.Properties.Item("PostBuildEventCommand").Value = postBuild; } // COMMANDS FROM ARDUINO // ORG: C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM1 -b115200 -D -Uflash:w:C:\Users\zaid\AppData\Local\Temp\build7239693675212912702.tmp/sketch_aug26a.cpp.hex:i // UNO: avrdude -C avrdude.conf -v -p atmega328p -c arduino -P COM1 -b 115200 -D -U flash:w:sketch_aug26a.cpp.hex:i // NANO: avrdude -C avrdude.conf -v -p atmega328p -c arduino -P COM1 -b 57600 -D -U flash:w:sketch_aug26a.cpp.hex:i // MEGA: avrdude -C avrdude.conf -v -p atmega2560 -c wiring -P COM1 -b 115200 -D -U flash:w:sketch_aug26a.cpp.hex:i // LENO: ???? /* LINKS: * https://msdn.microsoft.com/en-us/library/ms228959.aspx * http://stackoverflow.com/questions/25020255/change-the-debug-properties-of-visual-studio-project-programmatically-by-envdte * https://msdn.microsoft.com/en-us/library/aa984055(v=vs.100).aspx * https://msdn.microsoft.com/en-us/library/aa983813(v=vs.100).aspx * but it actually is PostBuildEventCommand */ } } } }
/// <summary> /// Gets the active configuration name. /// </summary> /// <param name="automationObject">The automation object.</param> /// <returns>The name of the active configuartion.</returns> public static string GetActiveConfigurationName(EnvDTE.Project automationObject) { if (automationObject == null) { throw new ArgumentNullException("automationObject"); } string currentConfigName = string.Empty; if (automationObject.ConfigurationManager != null) { EnvDTE.Configuration activeConfig = automationObject.ConfigurationManager.ActiveConfiguration; if (activeConfig != null) { currentConfigName = activeConfig.ConfigurationName; } } return(currentConfigName); }
public string GetProjectQtVersion(EnvDTE.Project project, EnvDTE.Configuration config) { ThreadHelper.ThrowIfNotOnUIThread(); if (QtProject.GetFormatVersion(project) >= Resources.qtMinFormatVersion_Settings) { return(QtProject.GetPropertyValue(project, config, "QtInstall")); } var key = "Qt5Version " + config.PlatformName; if (!project.Globals.get_VariablePersists(key)) { return(null); } var version = (string)project.Globals[key]; ExpandEnvironmentVariablesInQtVersion(ref version); return(VerifyIfQtVersionExists(version) ? version : null); }
public void AddGeneratedFile(IVsProject project, VCFilter filter, string path, EnvDTE.Configuration config) { int found; uint id; VSDOCUMENTPRIORITY[] priority = new VSDOCUMENTPRIORITY[1]; project.IsDocumentInProject(path, out found, priority, out id); if (found == 0) { if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } if (!File.Exists(path)) { File.Create(path).Dispose(); } VCFile file = null; if (config == null) { file = filter.AddFile(path); } else { filter = FindOrCreateFilter(filter, config.PlatformName); filter = FindOrCreateFilter(filter, config.ConfigurationName); file = filter.AddFile(path); foreach (VCFileConfiguration c in file.FileConfigurations) { if (!c.ProjectConfiguration.ConfigurationName.Equals(config.ConfigurationName) || !c.ProjectConfiguration.Platform.Name.Equals(config.PlatformName)) { c.ExcludedFromBuild = true; } } } try { // // Remove the file otherwise it will be considered up to date. // File.Delete(path); } catch (Exception) { } } }
public override void ExecuteCommandImpl(object sender, EventArgs args) { var project = projectManager.SelectedProject; EnvDTE.Configuration config = project.ConfigurationManager.ActiveConfiguration; EnvDTE.Properties props = config.Properties; var outputPath = props.Item("OutputPath"); var dllFullPath = Path.Combine(project.Properties.Item("FullPath").Value.ToString(), outputPath.Value.ToString(), project.Properties.Item("OutputFileName").Value.ToString()); var selectedMethodName = projectManager.MethodName; string projectConfigPath = projectManager.ProjectConfigPath; MethodInfo methodInformation = projectConfigurationManager.CurrentProjectConfiguraiton.MethodInfos.FirstOrDefault(m => m.MethodName == selectedMethodName); string selectedMethodPath = projectManager.MethodPath; string sourceCode = File.ReadAllText(selectedMethodPath, new UTF8Encoding(true)); var tree = CSharpSyntaxTree.ParseText(sourceCode); SyntaxNode root = tree.GetRoot(); var member = root.DescendantNodes() .OfType <NamespaceDeclarationSyntax>() .FirstOrDefault(); var className = GetFullClassName(member); var methodName = GetMethodName(member); //(me as IdentifierNameSyntax).Identifier.ValueText //var selectedClassName = //ProjectConfiguraiton projectConfiguration = projectConfigurationManager.Load(projectConfigPath); projectManager.ExecuteCommand("Build.BuildSolution"); var currentDllPath = System.Reflection.Assembly.GetExecutingAssembly().Location; var directoryPath = Path.GetDirectoryName(currentDllPath); var launcherPath = Path.Combine(directoryPath, "MethodLauncher", "MethodLauncher.exe"); string packageMethodFolderPath = this.projectConfigurationManager.CurrentProjectConfiguraiton.UseCommonProjectStructure ? methodInformation.Package.MethodFolderPath : string.Empty; string methodWorkingFolder = Path.Combine(projectManager.ServerMethodFolderPath, packageMethodFolderPath, methodInformation.MethodName); ICodeProvider codeProvider = codeProviderFactory.GetCodeProvider(projectManager.Language); string methodCode = codeProvider.LoadMethodCode(methodWorkingFolder, sourceCode); var debugMethodView = dialogFactory.GetDebugMethodView(projectConfigurationManager, methodInformation, methodCode, projectConfigPath, project.Name, project.FullName); var debugMethodViewResult = debugMethodView.ShowDialog(); if (debugMethodViewResult?.DialogOperationResult != true) { return; } string projectDirectoryPath = Path.GetDirectoryName(projectManager.SelectedProject.FileName); string launcherConfigPath = Path.Combine(projectDirectoryPath, "LauncherConfig.xml"); CreateLauncherConfigFile(dllFullPath, className, methodName, debugMethodViewResult, launcherConfigPath, CommonData.EventSpecificDataTypeList.FirstOrDefault(ev => ev.EventSpecificData.ToString() == methodInformation.EventData.ToString()).EventDataClass, methodInformation.TemplateName); ProcessStartInfo startInfo = new ProcessStartInfo(launcherPath); startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.Arguments = launcherConfigPath + " " + authManager.InnovatorUser.passwordHash; Process process = Process.Start(startInfo); projectManager.AttachToProcess(process); }
internal void getProjectFileInfo(string fileName, out string name, out string outputFile, out string configurationName, out string buildPath) { EnvDTE._DTE dte = null; EnvDTE.Configuration config = null; string Name, OutputFile, ConfigurationName, BuildPath; buildPath = String.Empty; configurationName = String.Empty; outputFile = String.Empty; name = String.Empty; try { EnvDTE.Project proj = null; EnvDTE.OutputGroup group = null; string outputURLDir, projectFileDir; Object[] OutputFiles = null; Object[] OutputURLs = null; int nIndex; dte = (EnvDTE._DTE) new VisualStudio_DTE_7_1(); dte.Solution.AddFromFile(fileName, false); proj = dte.Solution.Projects.Item(1); Name = proj.Name; config = proj.ConfigurationManager.ActiveConfiguration; ConfigurationName = config.ConfigurationName; // Loop through the possibly-many set of output groups, looking for the // one that has the build output. If we don't can't locate it, we will // attempt to use the first one in the list. nIndex = config.OutputGroups.Count; do { group = config.OutputGroups.Item(nIndex); nIndex--; } while ((nIndex > 0) && (group.CanonicalName != "Built")); OutputFiles = (Object[])group.FileNames; OutputFile = (string)OutputFiles[0]; OutputURLs = (Object[])group.FileURLs; outputURLDir = (string)OutputURLs[0]; // Given a full URL to the file path (file://c:\....) and the base path // to the project file (c:\...), determine the set of additional directories // into which the build is being performed. projectFileDir = getPath(fileName); projectFileDir = projectFileDir.ToUpper(); outputURLDir = outputURLDir.ToUpper(); nIndex = outputURLDir.LastIndexOf(projectFileDir); BuildPath = outputURLDir.Substring(nIndex + projectFileDir.Length); BuildPath = getPath(BuildPath); name = Name; outputFile = OutputFile; configurationName = ConfigurationName; buildPath = BuildPath; } catch (System.Exception) { throw new System.Exception(SharedSupport.GetLocalizedString("ProjectInfo_ProjFileInvalid")); } finally { if (dte != null) { try { dte.Solution.Close(false); dte.Quit(); } catch (System.Exception) { // Ignore errors when shutting down out-of-process IDE. } } } }
public static string ConfigurationString(EnvDTE.Configuration configuration) { return(string.Format("{0}|{1}", configuration.ConfigurationName, configuration.PlatformName)); }
private string GetReferencedProjectOutputPath() { // Make sure that the referenced project implements the automation object. if (null == this.ReferencedProject) { return(null); } // Get the configuration manager from the project. EnvDTE.ConfigurationManager confManager = this.ReferencedProject.ConfigurationManager; if (null == confManager) { return(null); } // Get the active configuration. EnvDTE.Configuration config = null; try { config = confManager.ActiveConfiguration; } catch (ArgumentException) { // 4951: exeception happens sometimes when ToolBox queries references on worker thread // (apparently hitting a race or bad state of referenced project's ConfigurationManager) return(null); } if (null == config) { return(null); } // Get the output path for the current configuration. string outputPath = null; try { EnvDTE.Property outputPathProperty = config.Properties.Item("OutputPath"); if (null == outputPathProperty) { return(null); } outputPath = outputPathProperty.Value.ToString(); } catch (System.Runtime.InteropServices.COMException) { // just catch the exception and return null, which means the user will see an empty 'FullPath' field of a ProjectReference property. return(null); } // Ususally the output path is relative to the project path, but it is possible // to set it as an absolute path. If it is not absolute, then evaluate its value // based on the project directory. if (!System.IO.Path.IsPathRooted(outputPath)) { string projectDir = System.IO.Path.GetDirectoryName(referencedProjectFullPath); outputPath = System.IO.Path.Combine(projectDir, outputPath); } // Now get the name of the assembly from the project. // Some project system throw if the property does not exist. We expect an ArgumentException. string assemblyName = null; try { assemblyName = this.ReferencedProject.Properties.Item("OutputFileName").Value.ToString(); } catch (ArgumentException) { } catch (NullReferenceException) { } if (null == assemblyName) { try { var group = config.OutputGroups.Item("Built"); var files = (object[])group.FileNames; if (files.Length > 0) { assemblyName = (string)files[0]; } } catch (InvalidCastException) { return(null); } catch (ArgumentException) { return(null); } catch (NullReferenceException) { return(null); } } // build the full path adding the name of the assembly to the output path. outputPath = System.IO.Path.Combine(outputPath, assemblyName); return(outputPath); }
GetCppGeneratedFiles(IVsProject project) { List <string> outputDirectories = new List <string>(); List <string> headerOutputDirectories = new List <string>(); // // Check if the output directories expand to different values in each configuration, if that is the case we // add generated files per configuration, and use ExcludeFromBuild to disable the file in all the configurations // but the one matching the configuration expanded value of the properties. // // IVsBuildPropertyStorage propertyStorage = project as IVsBuildPropertyStorage; IVsCfg[] configurations = GetProjectConfigurations(project); foreach (IVsCfg config in configurations) { string value; string configName; config.get_DisplayName(out configName); propertyStorage.GetPropertyValue("IceBuilderOutputDir", configName, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); if (!string.IsNullOrEmpty(value) && !outputDirectories.Contains(value)) { outputDirectories.Add(value); } propertyStorage.GetPropertyValue("IceBuilderHeaderOutputDir", configName, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); if (!string.IsNullOrEmpty(value) && !outputDirectories.Contains(value)) { headerOutputDirectories.Add(value); } } bool generateFilesPerConfiguration = headerOutputDirectories.Count > 1 || outputDirectories.Count > 1; List <CppGeneratedFileSet> generated = new List <CppGeneratedFileSet>(); List <string> items = GetIceBuilderItems(project); if (items.Count > 0) { string projectDir = GetProjectBaseDirectory(project); string outputDir = GetOutputDir(project, false, false); string headerOutputDir = GetOutputDir(project, true, false); string sourceExt = GetEvaluatedProperty(project, PropertyNames.SourceExt, ".cpp"); string headerExt = GetEvaluatedProperty(project, PropertyNames.HeaderExt, ".h"); EnvDTE.Project p = DTEUtil.GetProject(project as IVsHierarchy); if (generateFilesPerConfiguration) { foreach (EnvDTE.Configuration configuration in p.ConfigurationManager) { string outputDirEvaluated = Path.Combine(projectDir, Package.Instance.VCUtil.Evaluate(configuration, outputDir)); string headerOutputDirEvaluated = Path.Combine(projectDir, Package.Instance.VCUtil.Evaluate(configuration, headerOutputDir)); CppGeneratedFileSet fileset = new CppGeneratedFileSet(); fileset.configuration = configuration; fileset.headers = new List <string>(); fileset.sources = new List <string>(); foreach (string item in items) { fileset.filename = item; fileset.sources.Add(Path.GetFullPath(Path.Combine(outputDirEvaluated, GetGeneratedItemPath(item, sourceExt)))); fileset.headers.Add(Path.GetFullPath(Path.Combine(headerOutputDirEvaluated, GetGeneratedItemPath(item, headerExt)))); } generated.Add(fileset); } } else { EnvDTE.Configuration configuration = p.ConfigurationManager.ActiveConfiguration; string outputDirEvaluated = Path.Combine(projectDir, Package.Instance.VCUtil.Evaluate(configuration, outputDir)); string headerOutputDirEvaluated = Path.Combine(projectDir, Package.Instance.VCUtil.Evaluate(configuration, headerOutputDir)); CppGeneratedFileSet fileset = new CppGeneratedFileSet(); fileset.configuration = configuration; fileset.headers = new List <string>(); fileset.sources = new List <string>(); foreach (string item in items) { fileset.filename = item; fileset.sources.Add(Path.GetFullPath(Path.Combine(outputDirEvaluated, GetGeneratedItemPath(item, sourceExt)))); fileset.headers.Add(Path.GetFullPath(Path.Combine(headerOutputDirEvaluated, GetGeneratedItemPath(item, headerExt)))); } generated.Add(fileset); } } return(generated); }
public static string ConfigurationString(EnvDTE.Configuration configuration) { ThreadHelper.ThrowIfNotOnUIThread(); return(string.Format("{0}|{1}", configuration.ConfigurationName, configuration.PlatformName)); }