static public string GetProjectOutputAssemblyName(Project project)
        {
            EnvDTE.Configuration activeConfig = project.ConfigurationManager.ActiveConfiguration;

            string outputFileName = project.Properties.Item("OutputFileName").Value.ToString();

            return(outputFileName);
        }
        static public string GetProjectNamespaceName(Project project)
        {
            EnvDTE.Configuration activeConfig = project.ConfigurationManager.ActiveConfiguration;

            string defaultNamespace = project.Properties.Item("DefaultNamespace").Value.ToString();

            return(defaultNamespace);
        }
Exemple #3
0
        /// <summary>
        /// Returns the full path of the assembly a project builds.
        /// </summary>
        /// <returns>The full path of the assembly this project builds.</returns>
        internal static string GetOutputPath(EnvDTE.Project automationProjectObject)
        {
            // Get the configuration manager from the project.
            EnvDTE.ConfigurationManager confManager = automationProjectObject.ConfigurationManager;
            if (null == confManager)
            {
                return(null);
            }

            // Get the active configuration.
            EnvDTE.Configuration config = confManager.ActiveConfiguration;
            if (null == config)
            {
                return(null);
            }

            // Get the output path for the current configuration.
            EnvDTE.Property outputPathProperty = config.Properties.Item("OutputPath");
            if (null == outputPathProperty)
            {
                return(null);
            }

            string outputPath = outputPathProperty.Value.ToString();

            // 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(automationProjectObject.FullName);
                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.
            EnvDTE.Property assemblyNameProperty = null;
            try
            {
                assemblyNameProperty = automationProjectObject.Properties.Item("OutputFileName");
            }
            catch (ArgumentException)
            {
            }

            if (null == assemblyNameProperty)
            {
                return(null);
            }
            else
            {
                outputPath = System.IO.Path.Combine(outputPath, assemblyNameProperty.Value.ToString());
            }

            // build the full path adding the name of the assembly to the output path.

            return(outputPath);
        }
Exemple #4
0
        /// <summary>
        /// Get the active code file, project and configuration
        /// </summary>
        /// <returns>true if we have found an active C/C++ document</returns>
        bool GetActiveVCFile(out VCFile vcFile, out VCProject vcProject, out VCConfiguration vcCfg)
        {
            vcFile    = null;
            vcProject = null;
            vcCfg     = null;

            if (_applicationObject.ActiveDocument != null)
            {
                // GUID equates to 'code file' as far as I can make out
                if (_applicationObject.ActiveDocument.Kind == "{8E7B96A8-E33D-11D0-A6D5-00C04FB67F6A}" &&
                    _applicationObject.ActiveDocument.Language == "C/C++")
                {
                    // GUID equates to physical file on disk [http://msdn.microsoft.com/en-us/library/z4bcch80(VS.80).aspx]
                    if (_applicationObject.ActiveDocument.ProjectItem.Kind == "{6BB5F8EE-4483-11D3-8BCF-00C04F8EC28C}")
                    {
                        // leap of faith
                        vcFile    = (VCFile)_applicationObject.ActiveDocument.ProjectItem.Object;
                        vcProject = (VCProject)vcFile.project;

                        if (vcFile.FileType != eFileType.eFileTypeCppCode)
                        {
                            return(false);
                        }

                        // save the file (should be optional!)
                        if (!_applicationObject.ActiveDocument.Saved)
                        {
                            _applicationObject.ActiveDocument.Save(vcFile.FullPath);
                        }

                        // get current configuration to pass to the bridge
                        EnvDTE.Configuration cfg = _applicationObject.ActiveDocument.ProjectItem.ConfigurationManager.ActiveConfiguration;

                        try
                        {
                            IVCCollection cfgArray = (IVCCollection)vcProject.Configurations;
                            foreach (VCConfiguration vcr in cfgArray)
                            {
                                if (vcr.ConfigurationName == cfg.ConfigurationName &&
                                    vcr.Platform.Name == cfg.PlatformName)
                                {
                                    vcCfg = vcr;
                                }
                            }
                        }
                        catch (System.Exception)
                        {
                            return(false);
                        }

                        return(true);
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// Gets the full name of the output directory
        /// </summary>
        /// <param name="project"></param>
        /// <returns>The output for the build files on success. Otherwise string.Empty is returned</returns>
        static public string GetProjectOutputDirectory(Project project)
        {
            //Build ... Output path

            EnvDTE.Configuration activeConfig = project.ConfigurationManager.ActiveConfiguration;

            string outputpath = activeConfig.Properties.Item("OutputPath").Value.ToString();

            return(outputpath);
        }
        static public string GetProjectOutputAssemblyNameExtensionless(Project project)
        {
            EnvDTE.Configuration activeConfig = project.ConfigurationManager.ActiveConfiguration;

            string outputFileName = project.Properties.Item("OutputFileName").Value.ToString();

            int tvIndex = outputFileName.LastIndexOf('.');

            if (tvIndex > -1)
            {
                return(outputFileName.Substring(0, tvIndex));
            }

            return(outputFileName);
        }
        private static int BuildSolution(string fileName, bool convertToX86)
        {
            //Separate name of Solution
            string solutionName = FlatRedBall.IO.FileManager.RemovePath(fileName);

            //Register MessageFilter to prevent failed RPC messages
            MessageFilter.Register();

            mInstance.Solution.Open(fileName);

            mInstance.Solution.SolutionBuild.SolutionConfigurations.Item("Debug").Activate();
            object o = mInstance.Solution.SolutionBuild.ActiveConfiguration;

            if (convertToX86)
            {
                foreach (EnvDTE.Project proj in mInstance.Solution.Projects)
                {
                    if (proj.ConfigurationManager == null)
                    {
                        continue;
                    }
                    System.Diagnostics.Trace.WriteLine(proj.Name);
                    EnvDTE.Configuration config = proj.ConfigurationManager.ActiveConfiguration;
                    EnvDTE.Property      prop   = config.Properties.Item("PlatformTarget");
                    prop.Value = "x86";
                }
            }

            mInstance.Solution.SolutionBuild.Build(true);

            if (mInstance.Solution.SolutionBuild.LastBuildInfo == 0)
            {
                // instanceHandle.Quit();
                // MessageFilter.Revoke();
                return(0);
            }
            else
            {
                mInstance.MainWindow.Activate();
                MessageFilter.Revoke();
                return(mInstance.Solution.SolutionBuild.LastBuildInfo);
            }
        }
        public static EnvDTE.Properties GetDtePropertiesFromHierarchy(IVsHierarchy hierarchy = null)
        {
            EnvDTE.Project project = GetDTEProjectFromHierarchy(hierarchy);
            if (project == null)
            {
                return(null);
            }

            EnvDTE.ConfigurationManager configManager = project.ConfigurationManager;
            if (configManager == null)
            {
                return(null);
            }

            EnvDTE.Configuration activeConfig = configManager.ActiveConfiguration;
            if (activeConfig == null)
            {
                return(null);
            }

            return(activeConfig.Properties);
        }
Exemple #9
0
        public static string GetProjectOutputBuildFolder(EnvDTE.Project proj)
        {
            string absoluteOutputPath = null;
            string projectFolder      = Path.GetDirectoryName(proj.FullName);

            try
            {
                //Get the configuration manager of the project
                EnvDTE.ConfigurationManager configManager = proj.ConfigurationManager;

                if (configManager == null)
                {
                    QCPluginUtilities.OutputCommandString("The project " + proj.Name + " doesn't have a configuration manager", QCPluginUtilities.Severity.Error);
                }
                else
                {
                    //Get the active project configuration
                    EnvDTE.Configuration activeConfiguration = configManager.ActiveConfiguration;

                    //Get the output folder
                    string outputPath = activeConfiguration.Properties.Item("OutputPath").Value.ToString();

                    //The output folder can have these patterns:
                    //1) "\\server\folder"
                    //2) "drive:\folder"
                    //3) "..\..\folder"
                    //4) "folder"
                    if (outputPath.StartsWith(Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString()))
                    {
                        //This is the case 1: "\\server\folder"
                        absoluteOutputPath = outputPath;
                    }
                    else if (outputPath.Length >= 2 && outputPath[1] == Path.VolumeSeparatorChar)
                    {
                        //This is the case 2: "drive:\folder"
                        absoluteOutputPath = outputPath;
                    }
                    else if (outputPath.IndexOf("..\\") > -1)
                    {
                        //This is the case 3: "..\..\folder"
                        while (outputPath.StartsWith("..\\"))
                        {
                            outputPath    = outputPath.Substring(3);
                            projectFolder = Path.GetDirectoryName(projectFolder);
                        }

                        absoluteOutputPath = Path.Combine(projectFolder, outputPath);
                    }
                    else
                    {
                        //This is the case 4: "folder"
                        projectFolder      = Path.GetDirectoryName(proj.FullName);
                        absoluteOutputPath = Path.Combine(projectFolder, outputPath);
                    }
                }
            }
            catch (Exception ex)
            {
                QCPluginUtilities.OutputCommandString("Get project output build folder error: " + ex.ToString(), QCPluginUtilities.Severity.Error);
            }

            return(absoluteOutputPath);
        }
Exemple #10
0
        /// <summary>
        /// Compile the project that is set as the 'startup project' in the solution
        /// </summary>
        public void BuildActiveProject(object buildConfig)
        {
            // cast the input object; this is designed to be run with ParameterizedThreadStart, so we have to accept 'object'...
            ProjectBuildConfig config = (buildConfig as ProjectBuildConfig);

            if (config == null)
            {
                throw new InvalidCastException("BuildActiveProject called with invalid argument - ProjectBuildConfig required");
            }

            // mark the build as ready-to-go
            config.BuildBegun(true);

            CVXBuildSystem buildSystem;

            try
            {
                buildSystem = new CVXBuildSystem(_vsOutputWindow, _outputPane);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "ClangVSx Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                config.BuildFinished(false);
                return;
            }

            try
            {
                // loop through the startup projects
                foreach (object startUpProj in (Array)_applicationObject.Solution.SolutionBuild.StartupProjects)
                {
                    // is this project a VC++ one? the guid is hardcoded because it doesn't seem to be included
                    // anywhere else in the constants, EnvDTE, etc..!
                    Project p = _applicationObject.Solution.Item(startUpProj);

                    if (p.Kind.ToUpper().Equals("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"))
                    {
                        WriteToOutputPane("Building Project : " + p.Name + "\n");

                        VCProject vcProject = p.Object as VCProject;
                        if (vcProject == null)
                        {
                            WriteToOutputPane("Error : Could not cast project to VCProject.\n");
                            config.BuildFinished(false);
                            return;
                        }

                        EnvDTE.Configuration cfg = p.ConfigurationManager.ActiveConfiguration;

                        VCConfiguration vcCfg = null;
                        try
                        {
                            IVCCollection cfgArray = (IVCCollection)vcProject.Configurations;
                            foreach (VCConfiguration vcr in cfgArray)
                            {
                                if (vcr.ConfigurationName == cfg.ConfigurationName &&
                                    vcr.Platform.Name == cfg.PlatformName)
                                {
                                    vcCfg = vcr;
                                }
                            }
                        }
                        catch (System.Exception)
                        {
                            WriteToOutputPane("Error - failed to determine VC configuration\n");
                        }

                        if (vcCfg == null)
                        {
                            WriteToOutputPane("Error : Could not find '" + cfg.ConfigurationName + "' configuration!\n");
                        }
                        else
                        {
                            WriteToOutputPane("Configuration : " + vcCfg.Name + "\n");
                        }

                        bool result = buildSystem.BuildProject(vcProject, vcCfg, config.JustLink);
                        config.BuildFinished(result);
                        return;
                    }
                    else
                    {
                        WriteToOutputPane("Ignoring non-C++ Project : " + p.Name + "\n");
                    }
                }
            }
            catch (System.Exception ex)
            {
                WriteToOutputPane("Exception During Build : \n" + ex.Message + "\n");
            }
            finally
            {
                config.BuildFinished(false);
            }
        }
        public static Property FindProperty(this Configuration configuration, ConfigurationProperty configurationProperty)
        {
            string configPropertyStr = configurationProperty.ToString();

            return(configuration.Properties.Cast <Property>().Single(property => property.Name == configPropertyStr));
        }
Exemple #12
0
        public ProjectDescription(Project project)
        {
            this.solution = (Solution)project.Parent;
            this.project  = project;

            ThreadHelper.ThrowIfNotOnUIThread();
            var dteProj = project.DteProject();

            EnvDTE.Configuration conf = dteProj.ConfigurationManager.ActiveConfiguration;
            //foreach (Property item in conf.Properties)
            //{
            //	SD.Debug.WriteLine( $"{item.Name} = {item.Value}" );
            //}


            // Get the MSBuild property storage
            IVsBuildPropertyStorage propertyStorage = GetPropertyStorage(project);

            try
            {
                this.platformTarget = (string)conf.Properties.Item("PlatformTarget").Value;
            }
            catch { }
            try
            {
                this.targetFramework = (string)dteProj.Properties.Item("TargetFrameworkMoniker").Value;
            }
            catch { }


            string outputPath     = (string)conf.Properties.Item("OutputPath").Value;
            string fullPath       = dteProj.Properties.Item("FullPath").Value as string;
            string outputFileName = GetBuildProperty(propertyStorage, "TargetFileName");

            if (String.IsNullOrEmpty(outputFileName))
            {
                int outputType = (int)dteProj.Properties.Item("OutputType").Value;
                // .NET Core Executables are dlls.
                if (this.targetFramework.StartsWith(".NETCoreApp"))
                {
                    outputType = 2;
                }
                outputFileName = (string)dteProj.Properties.Item("AssemblyName").Value + (outputType == 2 ? ".dll" : ".exe");
            }

            if (project.GetVsHierarchy().IsCapabilityMatch("CPS"))
            {
                // new .csproj format
                objPath = GetBuildProperty(propertyStorage, "IntermediateOutputPath");
                string configuration = GetBuildProperty(propertyStorage, "Configuration");
                debug = configuration == "Debug";
            }
            else
            {
                // old .csproj format
                string debugInfo = (string)conf.Properties.Item("DebugInfo").Value;
                debug   = debugInfo == "full";
                objPath = (string)conf.Properties.Item("IntermediatePath").Value;
            }
            binFile  = Path.Combine(fullPath, outputPath);
            binFile  = Path.Combine(binFile, outputFileName);
            projPath = Path.GetDirectoryName(dteProj.FileName) + "\\";
            string sign = GetBuildProperty(propertyStorage, "SignAssembly");

            if (!String.IsNullOrEmpty(sign) && String.Compare(sign, "true", true) == 0)
            {
                keyFile = GetBuildProperty(propertyStorage, "AssemblyOriginatorKeyFile");
            }
            else
            {
                keyFile = null;
            }
        }