/// <summary> /// Parses the project-level properties, such as the project type /// and so on. /// </summary> private void parseProjectProperties() { // We convert the DTE properties to a map... EnvDTE.Properties dteProperties = Utils.call(() => (m_dteProject.Properties)); Dictionary <string, object> projectProperties = getProperties(dteProperties); // The project type (exe, library etc)... prjOutputType outputType = (prjOutputType)getIntProperty(projectProperties, "OutputType"); switch (outputType) { case prjOutputType.prjOutputTypeExe: m_projectInfo.ProjectType = ProjectInfo.ProjectTypeEnum.CSHARP_EXECUTABLE; break; case prjOutputType.prjOutputTypeLibrary: m_projectInfo.ProjectType = ProjectInfo.ProjectTypeEnum.CSHARP_LIBRARY; break; case prjOutputType.prjOutputTypeWinExe: m_projectInfo.ProjectType = ProjectInfo.ProjectTypeEnum.CSHARP_WINFORMS_EXECUTABLE; break; } // The output file name, e.g. TextLib.dll... m_projectInfo.OutputFileName = getStringProperty(projectProperties, "OutputFileName"); // The project folder, absolute and relative to the solution... m_projectInfo.RootFolderAbsolute = getStringProperty(projectProperties, "FullPath"); m_projectInfo.RootFolderRelative = Utils.makeRelativePath(m_solutionRootFolder, m_projectInfo.RootFolderAbsolute); }
/// <summary> /// Helper to check the properties of a project and determine whether it can be run in VS. /// Projects that return true can be run in the debugger by pressing the usual Start Debugging (F5) command. /// </summary> public static bool IsProjectExecutable(Project Project) { try { Logging.WriteLine("IsProjectExecutable: Attempting to determine if project " + Project.Name + " is executable"); var ConfigManager = Project.ConfigurationManager; if (ConfigManager == null) { return(false); } var ActiveProjectConfig = Project.ConfigurationManager.ActiveConfiguration; if (ActiveProjectConfig != null) { Logging.WriteLine( "IsProjectExecutable: ActiveProjectConfig=\"" + ActiveProjectConfig.ConfigurationName + "|" + ActiveProjectConfig.PlatformName + "\""); } else { Logging.WriteLine("IsProjectExecutable: Warning - ActiveProjectConfig is null!"); } bool IsExecutable = false; if (Project.Kind.Equals(GuidList.VCSharpProjectKindGuidString, StringComparison.OrdinalIgnoreCase)) { // C# project Property StartActionProp = GetProjectConfigProperty(Project, null, "StartAction"); if (StartActionProp != null) { prjStartAction StartAction = (prjStartAction)StartActionProp.Value; if (StartAction == prjStartAction.prjStartActionProject) { // Project starts the project's output file when run Property OutputTypeProp = GetProjectProperty(Project, "OutputType"); if (OutputTypeProp != null) { prjOutputType OutputType = (prjOutputType)OutputTypeProp.Value; if (OutputType == prjOutputType.prjOutputTypeWinExe || OutputType == prjOutputType.prjOutputTypeExe) { IsExecutable = true; } } } else if (StartAction == prjStartAction.prjStartActionProgram || StartAction == prjStartAction.prjStartActionURL) { // Project starts an external program or a URL when run - assume it has been set deliberately to something executable IsExecutable = true; } } } else if (Project.Kind.Equals(GuidList.VCProjectKindGuidString, StringComparison.OrdinalIgnoreCase)) { // C++ project SolutionConfiguration SolutionConfig = UnrealVSPackage.Instance.DTE.Solution.SolutionBuild.ActiveConfiguration; SolutionContext ProjectSolutionCtxt = SolutionConfig.SolutionContexts.Item(Project.UniqueName); // Get the correct config object from the VCProject string ActiveConfigName = string.Format( "{0}|{1}", ProjectSolutionCtxt.ConfigurationName, ProjectSolutionCtxt.PlatformName); // Get the VS version-specific VC project object. VCProject VCProject = new VCProject(Project, ActiveConfigName); if (VCProject != null) { // Sometimes the configurations is null. if (VCProject.Configurations != null) { var VCConfigMatch = VCProject.Configurations.FirstOrDefault(VCConfig => VCConfig.Name == ActiveConfigName); if (VCConfigMatch != null) { if (VCConfigMatch.DebugAttach) { // Project attaches to a running process IsExecutable = true; } else { // Project runs its own process if (VCConfigMatch.DebugFlavor == DebuggerFlavor.Remote) { // Project debugs remotely if (VCConfigMatch.DebugRemoteCommand.Length != 0) { // An remote program is specified to run IsExecutable = true; } } else { // Local debugger if (VCConfigMatch.DebugCommand.Length != 0 && VCConfigMatch.DebugCommand != "$(TargetPath)") { // An external program is specified to run IsExecutable = true; } else { // No command so the project runs the target file if (VCConfigMatch.ConfigType == ConfigType.Application) { IsExecutable = true; } else if (VCConfigMatch.ConfigType == ConfigType.Generic) { // Makefile if (VCConfigMatch.NMakeToolOutput.Length != 0) { string Ext = Path.GetExtension(VCConfigMatch.NMakeToolOutput); if (!IsLibraryFileExtension(Ext)) { IsExecutable = true; } } } } } } } } } } else { // @todo: support other project types Logging.WriteLine("IsProjectExecutable: Unrecognised 'Kind' in project " + Project.Name + " guid=" + Project.Kind); } return(IsExecutable); } catch (Exception ex) { Exception AppEx = new ApplicationException("IsProjectExecutable() failed", ex); Logging.WriteLine(AppEx.ToString()); throw AppEx; } }