コード例 #1
0
        //Code from StaticAnalysisPolicy class in the StanPolicy.dll file
        private bool ProjectUptoDate(Project project, List <PolicyFailure> failuresList)
        {
            IVsBuildableProjectCfg cfg1;
            IVsHierarchy           hierarchy1 = GetVsProjectFromDTE(project);

            IVsProjectCfg2[]        cfgArray1          = new IVsProjectCfg2[1];
            IVsSolutionBuildManager m_currBuildManager = PendingCheckin.GetService(typeof(IVsSolutionBuildManager)) as IVsSolutionBuildManager;

            m_currBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy1, cfgArray1);
            if (cfgArray1[0] == null)
            {
                return(false);
            }
            cfgArray1[0].get_BuildableProjectCfg(out cfg1);
            if (cfg1 == null)
            {
                return(false);
            }
            int[] numArray1 = new int[1];
            int[] numArray2 = new int[1];
            int   num1      = cfg1.QueryStartUpToDateCheck(1, numArray1, numArray2);

            if ((numArray1[0] != 0) && !ErrorHandler.Failed(num1))
            {
                //http://msdn2.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsbuildableprojectcfg.startuptodatecheck(VS.80).aspx
                num1 = cfg1.StartUpToDateCheck(null, 1);
                if (ErrorHandler.Failed(num1))
                {
                    string text1 = String.Format(errMessage, project.Name);
                    failuresList.Add(new PolicyFailure(text1, this));
                    return(false);
                }
            }
            return(true);
        }
コード例 #2
0
        // relative to active configuration.
        public string GetConfigProperty(string propertyName)
        {
            if (this.ProjectMgr != null)
            {
                string unifiedResult  = null;
                bool   cacheNeedReset = true;

                for (int i = 0; i < this.projectConfigs.Length; i++)
                {
                    IVsProjectCfg2 config = projectConfigs[i];
                    //string property = config.GetConfigurationProperty(propertyName, cacheNeedReset);
                    string property = null;
                    cacheNeedReset = false;

                    if (property != null && cacheNeedReset)
                    {
                        string text = property.Trim();

                        if (i == 0)
                        {
                            unifiedResult = text;
                        }
                        else if (unifiedResult != text)
                        {
                            return(""); // tristate value is blank then
                        }
                    }
                }

                return(unifiedResult);
            }

            return(String.Empty);
        }
コード例 #3
0
        /// <summary>
        /// Checks if the project build is up to date.
        /// </summary>
        public async Task <bool> ProjectIsUpToDateAsync(SolutionItem project)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsSolutionBuildManager svc = await VS.Services.GetSolutionBuildManagerAsync();

            IVsProjectCfg2[] projectConfig = new IVsProjectCfg2[1];

            project.GetItemInfo(out IVsHierarchy hierarchy, out _, out _);

            if (ErrorHandler.Succeeded(svc.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, projectConfig)))
            {
                int[] supported = new int[1];
                int[] ready     = new int[1];

                if (ErrorHandler.Succeeded(projectConfig[0].get_BuildableProjectCfg(out IVsBuildableProjectCfg buildableProjectConfig)) &&
                    ErrorHandler.Succeeded(buildableProjectConfig.QueryStartUpToDateCheck(0, supported, ready)) &&
                    supported[0] == 1)
                {
                    return(ErrorHandler.Succeeded(buildableProjectConfig.StartUpToDateCheck(null, (uint)VsUpToDateCheckFlags.VSUTDCF_DTEEONLY)));
                }
            }

            return(false);
        }
コード例 #4
0
        internal VsProjectFlavorCfg VsProjectFlavorCfgFromObject(object o)
        {
            IVsProjectCfg2 vsProjectCfg = (IVsProjectCfg2)o;
            Guid           guid         = typeof(IVsDebuggableProjectCfg).GUID;
            IntPtr         ip;

            vsProjectCfg.get_CfgType(ref guid, out ip);
            return(Marshal.GetObjectForIUnknown(ip) as VsProjectFlavorCfg);
        }
コード例 #5
0
ファイル: DjangoProjectConfig.cs プロジェクト: PeezoSlug/PTVS
        public int get_OutputGroups(uint celt, IVsOutputGroup[] rgpcfg, uint[] pcActual = null)
        {
            IVsProjectCfg2 projCfg = _pythonCfg as IVsProjectCfg2;

            if (projCfg != null)
            {
                return(projCfg.get_OutputGroups(celt, rgpcfg, pcActual));
            }
            return(VSConstants.E_NOTIMPL);
        }
コード例 #6
0
ファイル: DjangoProjectConfig.cs プロジェクト: PeezoSlug/PTVS
        public int get_VirtualRoot(out string pbstrVRoot)
        {
            IVsProjectCfg2 projCfg = _pythonCfg as IVsProjectCfg2;

            if (projCfg != null)
            {
                return(projCfg.get_VirtualRoot(out pbstrVRoot));
            }
            pbstrVRoot = null;
            return(VSConstants.E_NOTIMPL);
        }
コード例 #7
0
ファイル: DjangoProjectConfig.cs プロジェクト: PeezoSlug/PTVS
        public int OutputsRequireAppRoot(out int pfRequiresAppRoot)
        {
            IVsProjectCfg2 projCfg = _pythonCfg as IVsProjectCfg2;

            if (projCfg != null)
            {
                return(projCfg.OutputsRequireAppRoot(out pfRequiresAppRoot));
            }
            pfRequiresAppRoot = 1;
            return(VSConstants.E_NOTIMPL);
        }
コード例 #8
0
ファイル: DjangoProjectConfig.cs プロジェクト: PeezoSlug/PTVS
        public int get_IsPrivate(out int pfPrivate)
        {
            IVsProjectCfg2 projCfg = _pythonCfg as IVsProjectCfg2;

            if (projCfg != null)
            {
                return(projCfg.get_IsPrivate(out pfPrivate));
            }
            pfPrivate = 0;
            return(VSConstants.E_NOTIMPL);
        }
コード例 #9
0
ファイル: DjangoProjectConfig.cs プロジェクト: PeezoSlug/PTVS
        public int OpenOutputGroup(string szCanonicalName, out IVsOutputGroup ppIVsOutputGroup)
        {
            IVsProjectCfg2 projCfg = _pythonCfg as IVsProjectCfg2;

            if (projCfg != null)
            {
                return(projCfg.OpenOutputGroup(szCanonicalName, out ppIVsOutputGroup));
            }
            ppIVsOutputGroup = null;
            return(VSConstants.E_NOTIMPL);
        }
コード例 #10
0
        /// <summary>
        /// When building a wixproj in VS, the configuration of referenced projects cannot be determined
        /// by MSBuild or from within an MSBuild task. So we'll get them from the VS project system here.
        /// </summary>
        /// <param name="project">The project where the properties are being defined; also the project
        /// whose references are being examined.</param>
        internal static void DefineProjectReferenceConfigurations(WixProjectNode project)
        {
            StringBuilder configList = new StringBuilder();

            IVsSolutionBuildManager solutionBuildManager =
                WixHelperMethods.GetService <IVsSolutionBuildManager, SVsSolutionBuildManager>(project.Site);

            List <WixProjectReferenceNode> referenceNodes = new List <WixProjectReferenceNode>();

            project.FindNodesOfType(referenceNodes);

            foreach (WixProjectReferenceNode referenceNode in referenceNodes)
            {
                IVsHierarchy hierarchy = VsShellUtilities.GetHierarchy(referenceNode.ProjectMgr.Site, referenceNode.ReferencedProjectGuid);

                string          configuration   = null;
                IVsProjectCfg2  projectCfg2     = null;
                IVsProjectCfg[] projectCfgArray = new IVsProjectCfg[1];

                int hr = solutionBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, projectCfgArray);
                ErrorHandler.ThrowOnFailure(hr);

                projectCfg2 = projectCfgArray[0] as IVsProjectCfg2;

                if (projectCfg2 != null)
                {
                    hr = projectCfg2.get_DisplayName(out configuration);
                    if (hr != 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                }

                if (configuration != null)
                {
                    if (configList.Length > 0)
                    {
                        configList.Append(';');
                    }

                    configList.Append(referenceNode.ReferencedProjectName);
                    configList.Append('=');
                    configList.Append(configuration);
                }
            }

            if (configList.Length > 0)
            {
                project.BuildProject.SetGlobalProperty("VSProjectConfigurations", configList.ToString());
            }
        }
コード例 #11
0
 public virtual int get_ProjectCfg(out IVsProjectCfg2 ppIVsProjectCfg2)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     ppIVsProjectCfg2 = (IVsProjectCfg2)this._projectCfg;
     return(VSConstants.S_OK);
 }
コード例 #12
0
        private static IEnumerable<string> EnumerateOutputs(IVsProjectCfg2 config, string canonicalName) {
            var actual = new uint[1];
            ErrorHandler.ThrowOnFailure(config.get_OutputGroups(0, null, actual));
            var groups = new IVsOutputGroup[actual[0]];
            ErrorHandler.ThrowOnFailure(config.get_OutputGroups((uint)groups.Length, groups, actual));

            var group = groups.FirstOrDefault(g => {
                string name;
                ErrorHandler.ThrowOnFailure(g.get_CanonicalName(out name));
                return canonicalName.Equals(name, StringComparison.OrdinalIgnoreCase);
            });
            if (group == null) {
                return Enumerable.Empty<string>();
            }

            string keyName;
            if (!ErrorHandler.Succeeded(group.get_KeyOutput(out keyName))) {
                keyName = null;
            }

            try {
                ErrorHandler.ThrowOnFailure(group.get_Outputs(0, null, actual));
            } catch (NotImplementedException) {
                if (CommonUtils.IsValidPath(keyName)) {
                    return Enumerable.Repeat(keyName, 1);
                }
                throw;
            }
            var outputs = new IVsOutput2[actual[0]];
            ErrorHandler.ThrowOnFailure(group.get_Outputs((uint)outputs.Length, outputs, actual));

            string keyResult = null;
            var results = new List<string>();

            foreach (var o in outputs) {
                string name;
                if (keyName != null &&
                    ErrorHandler.Succeeded(o.get_CanonicalName(out name)) &&
                    keyName.Equals(name, StringComparison.OrdinalIgnoreCase)
                ) {
                    keyResult = GetFilenameFromOutput(o);
                } else {
                    results.Add(GetFilenameFromOutput(o));
                }
            }

            if (keyResult != null) {
                results.Insert(0, keyResult);
            }
            return results;
        }
コード例 #13
0
        private static IEnumerable <string> EnumerateOutputs(IVsProjectCfg2 config, string canonicalName)
        {
            var actual = new uint[1];

            ErrorHandler.ThrowOnFailure(config.get_OutputGroups(0, null, actual));
            var groups = new IVsOutputGroup[actual[0]];

            ErrorHandler.ThrowOnFailure(config.get_OutputGroups((uint)groups.Length, groups, actual));

            var group = groups.FirstOrDefault(g =>
            {
                string name;
                ErrorHandler.ThrowOnFailure(g.get_CanonicalName(out name));
                return(canonicalName.Equals(name, StringComparison.OrdinalIgnoreCase));
            });

            if (group == null)
            {
                return(Enumerable.Empty <string>());
            }

            string keyName;

            if (!ErrorHandler.Succeeded(group.get_KeyOutput(out keyName)))
            {
                keyName = null;
            }

            try
            {
                ErrorHandler.ThrowOnFailure(group.get_Outputs(0, null, actual));
            }
            catch (NotImplementedException)
            {
                if (CommonUtils.IsValidPath(keyName))
                {
                    return(Enumerable.Repeat(keyName, 1));
                }
                throw;
            }
            var outputs = new IVsOutput2[actual[0]];

            ErrorHandler.ThrowOnFailure(group.get_Outputs((uint)outputs.Length, outputs, actual));

            string keyResult = null;
            var    results   = new List <string>();

            foreach (var o in outputs)
            {
                string name;
                if (keyName != null &&
                    ErrorHandler.Succeeded(o.get_CanonicalName(out name)) &&
                    keyName.Equals(name, StringComparison.OrdinalIgnoreCase)
                    )
                {
                    keyResult = GetFilenameFromOutput(o);
                }
                else
                {
                    results.Add(GetFilenameFromOutput(o));
                }
            }

            if (keyResult != null)
            {
                results.Insert(0, keyResult);
            }
            return(results);
        }
コード例 #14
0
ファイル: PropertyPage.cs プロジェクト: xoriath/RTVS
        public void SetObjects(uint cObjects, object[] ppunk)
        {
            // If asked to, release our cached selected Project object(s)
            UnconfiguredProject  = null;
            ConfiguredProperties = null;

            if (cObjects == 0)
            {
                // If we have never configured anything (maybe a failure occurred
                // on open so app designer is closing us). In this case do nothing.
                if (ThreadHandling != null)
                {
                    SetObjects(true);
                }
                return;
            }

            if (ppunk.Length < cObjects)
            {
                throw new ArgumentOutOfRangeException(nameof(cObjects));
            }

            List <ProjectProperties> configuredProjectsProperties = new List <ProjectProperties>();

            // Look for an IVsBrowseObject
            for (int i = 0; i < cObjects; ++i)
            {
                IVsBrowseObject browseObj = null;
                browseObj = ppunk[i] as IVsBrowseObject;

                if (browseObj != null)
                {
                    IVsHierarchy hier = null;
                    uint         itemid;
                    int          hr;
                    hr = browseObj.GetProjectItem(out hier, out itemid);
                    Debug.Assert(itemid == VSConstants.VSITEMID_ROOT, "Selected object should be project root node");

                    if (hr == VSConstants.S_OK && itemid == VSConstants.VSITEMID_ROOT)
                    {
                        UnconfiguredProject = hier.GetUnconfiguredProject();

                        // We need to save ThreadHandling because the appdesigner will call SetObjects with null, and then call
                        // Deactivate(). We need to run Async code during Deactivate() which requires ThreadHandling.
                        ThreadHandling = UnconfiguredProject.Services.ExportProvider.GetExportedValue <IThreadHandling>();

                        IVsProjectCfg2 pcg = ppunk[i] as IVsProjectCfg2;
                        if (pcg != null)
                        {
                            string vsConfigName;
                            pcg.get_CanonicalName(out vsConfigName);

                            ThreadHandling.ExecuteSynchronously(async delegate {
                                var provider            = new ConfiguredRProjectExportProvider();
                                var configuredProjProps = await provider.GetExportAsync <ProjectProperties>(UnconfiguredProject, vsConfigName);
                                configuredProjectsProperties.Add(configuredProjProps);
                            });
                        }
                    }
                }

                ConfiguredProperties = configuredProjectsProperties.ToArray();
            }

            SetObjects(false);
        }
コード例 #15
0
 public virtual int get_ProjectCfg(out IVsProjectCfg2 ppIVsProjectCfg2)
 {
     ppIVsProjectCfg2 = (IVsProjectCfg2)this.projectCfg;
     return(VSConstants.S_OK);
 }
コード例 #16
0
        /// <summary>
        /// When building a project in VS, the configuration of referenced projects cannot be determined
        /// by MSBuild or from within an MSBuild task. So we'll get them from the VS project system here.
        /// </summary>
        /// <param name="project">The project where the properties are being defined; also the project
        /// whose references are being examined.</param>
        internal static void DefineProjectReferenceConfigurations(XProjectNode project)
        {
            StringBuilder configList = new StringBuilder();

            IVsSolutionBuildManager solutionBuildManager =
                XHelperMethods.GetService <IVsSolutionBuildManager, SVsSolutionBuildManager>(project.Site);

            List <ProjectReferenceNode> referenceNodes = new List <ProjectReferenceNode>();

            project.FindNodesOfType(referenceNodes);

            foreach (ProjectReferenceNode referenceNode in referenceNodes)
            {
                try
                {
                    IVsHierarchy hierarchy = VsShellUtilities.GetHierarchy(referenceNode.ProjectMgr.Site, referenceNode.ReferencedProjectGuid);

                    string          configuration   = null;
                    IVsProjectCfg2  projectCfg2     = null;
                    IVsProjectCfg[] projectCfgArray = new IVsProjectCfg[1];
                    ThreadHelper.ThrowIfNotOnUIThread();

                    // this can fail for some reason... this code was copied from Wix and probably isn't stable yet.
                    // this routine is called from InvokeMSBuild and we don't want that to fix because of
                    // some bug here, so this code is surrounded by try/catch until we figure this out
                    int hr = solutionBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, projectCfgArray);
                    ErrorHandler.ThrowOnFailure(hr);

                    projectCfg2 = projectCfgArray[0] as IVsProjectCfg2;

                    if (projectCfg2 != null)
                    {
                        hr = projectCfg2.get_DisplayName(out configuration);
                        if (hr != 0)
                        {
                            Marshal.ThrowExceptionForHR(hr);
                        }
                    }

                    if (configuration != null)
                    {
                        if (configList.Length > 0)
                        {
                            configList.Append(';');
                        }

                        configList.Append(referenceNode.ReferencedProjectName);
                        configList.Append('=');
                        configList.Append(configuration);
                    }
                }
                catch (Exception)
                {
                    ;
                }
            }

            if (configList.Length > 0)
            {
                project.BuildProject.SetGlobalProperty("VSProjectConfigurations", configList.ToString());
            }
        }
コード例 #17
0
 public int get_ProjectCfg(out IVsProjectCfg2 ppIVsProjectCfg2)
 {
     ppIVsProjectCfg2 = this.config;
     return((int)HResult.S_OK);
 }
コード例 #18
0
		public virtual int get_ProjectCfg(out IVsProjectCfg2 ppIVsProjectCfg2)
		{
			ppIVsProjectCfg2 = (IVsProjectCfg2)this.projectCfg;
			return VSConstants.S_OK;
		}
コード例 #19
0
        /// <summary>
        /// Gets the variables and directories for the specified project. Variables will be in
        /// the form <c>ProjectName.VariableName</c>.
        /// </summary>
        /// <param name="variables">The <see cref="NameValueCollection"/> to add the variables to.</param>
        /// <param name="hierarchy">The <see cref="IVsHierarchy"/> (project) from which to retrieve the variables.</param>
        private void GetTargetVariables(NameValueCollection variables, IVsHierarchy hierarchy, string projectPrefix)
        {
            try
            {
                int hr = NativeMethods.S_OK;

                // Now we need to get a IVsProjectCfg2 object to get the TargetX variables. We do this
                // by querying the environment for the active configuration of the specified project.
                IVsSolutionBuildManager solutionBuildManager = Package.Instance.GetService(typeof(IVsSolutionBuildManager)) as IVsSolutionBuildManager;
                if (solutionBuildManager == null)
                {
                    Tracer.WriteLine(classType, "GetTargetVariables", Tracer.Level.Warning, "Cannot get an instance of IVsSolutionBuildManager from the environment. Skipping the project's TargetX variables.");
                    return;
                }
                IVsProjectCfg[] projectCfgArray = new IVsProjectCfg[1];
                hr = solutionBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, projectCfgArray);
                if (NativeMethods.Failed(hr))
                {
                    Tracer.WriteLineWarning(classType, "GetTargetVariables", "One of the projects in the solution does not support project configurations. Skipping the project's TargetX variables.");
                    return;
                }
                IVsProjectCfg2 projectCfg2 = projectCfgArray[0] as IVsProjectCfg2;
                if (projectCfg2 == null)
                {
                    Tracer.WriteLine(classType, "GetTargetVariables", Tracer.Level.Warning, "The IVsSolutionBuildManager.FindActiveProjectCfg returned a null object or an object that doesn't support IVsProjectCfg2. Skipping the project's TargetX variables.");
                    return;
                }

                // Get the ConfigurationName and add it to the variables.
                string configurationName;
                NativeMethods.ThrowOnFailure(projectCfg2.get_DisplayName(out configurationName));
                variables.Add(projectPrefix + "ConfigurationName", configurationName);

                // We need to get the Built output group from the list of project output groups.
                IVsOutputGroup outputGroup;
                NativeMethods.ThrowOnFailure(projectCfg2.OpenOutputGroup("Built", out outputGroup));
                if (outputGroup == null)
                {
                    Tracer.WriteLine(classType, "GetTargetVariables", Tracer.Level.Warning, "The project configuration '{0}' does not support the 'Built' output group. Skipping the TargetX variables.", configurationName);
                    return;
                }

                // Get the key output canonical name from the Built output group.
                string keyOutputCanonicalName;
                NativeMethods.ThrowOnFailure(outputGroup.get_KeyOutput(out keyOutputCanonicalName));

                // Search through the outputs until we find the key output. We have to call get_Outputs
                // twice: once to get the number of outputs (we do this by passing in 0 as the number
                // requested), and then once to get the actual outputs.
                uint         numberRequested    = 0;
                IVsOutput2[] outputArray        = new IVsOutput2[numberRequested];
                uint[]       numberFetchedArray = new uint[1];
                NativeMethods.ThrowOnFailure(outputGroup.get_Outputs(numberRequested, outputArray, numberFetchedArray));

                // We should have the number of elements in the output array now, so get them.
                numberRequested = numberFetchedArray[0];
                outputArray     = new IVsOutput2[numberRequested];
                NativeMethods.ThrowOnFailure(outputGroup.get_Outputs(numberRequested, outputArray, numberFetchedArray));
                IVsOutput2 keyOutput = null;
                for (int i = 0; i < numberFetchedArray[0]; i++)
                {
                    if (outputArray.Length <= i)
                    {
                        break;
                    }

                    IVsOutput2 output = outputArray[i];
                    string     outputCanonicalName;
                    NativeMethods.ThrowOnFailure(output.get_CanonicalName(out outputCanonicalName));
                    if (outputCanonicalName == keyOutputCanonicalName)
                    {
                        keyOutput = output;
                        break;
                    }
                }

                // Check to make sure that we found the key output.
                if (keyOutput == null)
                {
                    Tracer.WriteLine(classType, "GetTargetVariables", Tracer.Level.Warning, "We identified the key output from configuration '{0}' as '{1}', but when we iterated through the outputs we couldn't find the key output. Skipping the TargetX variables.", configurationName, keyOutputCanonicalName);
                    return;
                }

                // Now that we have the key output, we can finally create the TargetX variables from
                // the key output's deploy source URL.
                string deploySourceUrl;
                NativeMethods.ThrowOnFailure(keyOutput.get_DeploySourceURL(out deploySourceUrl));

                // By convention, the deploy source URL starts with file:/// for file-based outputs.
                // Strip it off if it's there.
                if (deploySourceUrl.StartsWith("file:///"))
                {
                    deploySourceUrl = deploySourceUrl.Substring("file:///".Length);
                }

                // Parse the TargetX variables from the deploy source URL.
                string targetPath        = deploySourceUrl;
                string targetFileName    = Path.GetFileName(targetPath);
                string targetDosFileName = this.EncodeDosFileName(targetFileName);
                string targetName        = Path.GetFileNameWithoutExtension(targetFileName);
                string targetExt         = PackageUtility.EnsureLeadingChar(Path.GetExtension(targetPath), '.');
                string targetDir         = PackageUtility.StripTrailingChar(Path.GetDirectoryName(targetPath), Path.DirectorySeparatorChar);

                // Add the TargetX variables to the collection.
                variables.Add(projectPrefix + "TargetDir", targetDir);
                variables.Add(projectPrefix + "TargetDosFileName", targetDosFileName);
                variables.Add(projectPrefix + "TargetExt", targetExt);
                variables.Add(projectPrefix + "TargetFileName", targetFileName);
                variables.Add(projectPrefix + "TargetName", targetName);
                variables.Add(projectPrefix + "TargetPath", targetPath);
            }
            catch (Exception e)
            {
                if (ErrorUtility.IsExceptionUnrecoverable(e))
                {
                    throw;
                }

                Tracer.WriteLineWarning(classType, "GetTargetVariables", "The project does not correctly implement all of its required IVsProjectCfg2 interfaces. Skipping the TargetX variables. Exception: {0}", e);
            }
        }