Exemplo n.º 1
0
        public static string GetParametersFromFakeProperties(Microsoft.VisualStudio.VCProjectEngine.IVCRulePropertyStorage vcfprop,
                                                             System.Reflection.PropertyInfo[] props)
        {
            string parameters = "";

            foreach (var p in props)
            {
                var val = vcfprop.GetEvaluatedPropertyValue(p.Name);
                if (!string.IsNullOrEmpty(val))
                {
                    parameters = parameters + "|" + p.Name + "=" + val;
                }
            }
            return(parameters);
        }
Exemplo n.º 2
0
        // throws COMException if not found
        static void GetVCToolProps(IVsHierarchy proj, uint itemid,
                                   out Microsoft.VisualStudio.VCProjectEngine.VCFileConfiguration fcfg,
                                   out Microsoft.VisualStudio.VCProjectEngine.VCConfiguration cfg,
                                   out System.Reflection.IReflect vcrefl,
                                   out Microsoft.VisualStudio.VCProjectEngine.IVCRulePropertyStorage vcprop)
        {
            object ext;

            if (proj.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out ext) != 0)
            {
                throw new COMException();
            }

            object projext;

            if (proj.GetProperty(_VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out projext) != 0)
            {
                throw new COMException();
            }

            var envproj = projext as EnvDTE.Project;

            if (envproj == null)
            {
                throw new COMException();
            }

            var envitem = ext as EnvDTE.ProjectItem;

            if (envitem == null)
            {
                throw new COMException();
            }

            var cfgmgr     = envproj.ConfigurationManager;
            var activecfg  = cfgmgr.ActiveConfiguration;
            var activename = activecfg.ConfigurationName + "|" + activecfg.PlatformName;

            fcfg = null;
            cfg  = null;
            var vcfile = envitem.Object as Microsoft.VisualStudio.VCProjectEngine.VCFile;

            if (vcfile != null)
            {
                var vcfconfigs = vcfile.FileConfigurations as IVCCollection;
                for (int c = 1; c <= vcfconfigs.Count; c++)
                {
                    var vcfcfg = vcfconfigs.Item(c);
                    fcfg = vcfcfg as Microsoft.VisualStudio.VCProjectEngine.VCFileConfiguration;
                    if (fcfg.Name == activename)
                    {
                        break;
                    }
                    else
                    {
                        fcfg = null;
                    }
                }
                if (fcfg == null)
                {
                    throw new COMException();
                }

                var vcftool = fcfg.Tool as Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCToolBase;
                vcprop = vcftool as Microsoft.VisualStudio.VCProjectEngine.IVCRulePropertyStorage;
                if (vcftool != null && vcprop != null && vcftool.ItemType == "DCompile")
                {
                    vcrefl = vcftool as System.Reflection.IReflect;
                    if (vcrefl != null)
                    {
                        return;
                    }
                }
            }

            var vcproj = envproj.Object as Microsoft.VisualStudio.VCProjectEngine.VCProject; // Project.VisualC.VCProjectEngine.VCProjectShim;

            if (vcproj == null)
            {
                throw new COMException();
            }

            var vcconfigs = vcproj.Configurations as IVCCollection;

            for (int c = 1; c <= vcconfigs.Count; c++)
            {
                var vccfg = vcconfigs.Item(c);
                cfg = vccfg as Microsoft.VisualStudio.VCProjectEngine.VCConfiguration;
                if (cfg.Name == activename)
                {
                    break;
                }
                else
                {
                    cfg = null;
                }
            }
            if (cfg == null)
            {
                throw new COMException();
            }

            var tools = cfg.FileTools as IVCCollection;

            for (int f = 1; f <= tools.Count; f++)
            {
                var obj    = tools.Item(f);
                var vctool = obj as Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCToolBase;
                if (vctool != null && vctool.ItemType == "DCompile")
                {
                    vcprop = vctool as Microsoft.VisualStudio.VCProjectEngine.IVCRulePropertyStorage;
                    if (vcprop != null)
                    {
                        vcrefl = vctool as System.Reflection.IReflect;
                        if (vcrefl != null)
                        {
                            return;
                        }
                    }
                }
            }
            throw new COMException();
        }