/// <summary> /// Gets a property from the given output. /// </summary> internal static string GetProperty(this IVsOutput2 output, string name) { if (output == null) { throw new ArgumentNullException("output"); } object pvar; ErrorHandler.ThrowOnFailure(output.get_Property(name, out pvar)); return(pvar as string); }
private static string GetOutputMoniker(object sender) { IVsOutput2 output = sender as IVsOutput2; if (output == null) { return(null); } string moniker; output.get_CanonicalName(out moniker); return(moniker); }
public virtual int get_KeyOutputObject(out IVsOutput2 ppKeyOutput) { if (keyOutput == null) { Refresh(); } ppKeyOutput = keyOutput; if (ppKeyOutput == null) { return(VSConstants.S_FALSE); } return(VSConstants.S_OK); }
private static string GetOutputMoniker(object sender) { ThreadHelper.ThrowIfNotOnUIThread(); IVsOutput2 output = sender as IVsOutput2; if (output == null) { return(null); } string moniker; output.get_CanonicalName(out moniker); return(moniker); }
/// <summary> /// Gets the build output group. /// </summary> internal static string GetRootRelativeUrl(this IVsOutput2 output) { const string filePrefix = "file:///"; if (output == null) { throw new ArgumentNullException("output"); } string url; ErrorHandler.ThrowOnFailure(output.get_RootRelativeURL(out url)); if ((url != null) && (url.StartsWith(filePrefix))) { url = url.Substring(filePrefix.Length); } return(url); }
/// <summary> /// Gets the build output group. /// </summary> internal static string GetDeployUrl(this IVsOutput2 output) { const string filePrefix = "file:///"; if (output == null) { throw new ArgumentNullException("output"); } string deployUrl; ErrorHandler.ThrowOnFailure(output.get_DeploySourceURL(out deployUrl)); if ((deployUrl != null) && (deployUrl.StartsWith(filePrefix))) { deployUrl = deployUrl.Substring(filePrefix.Length); } return(deployUrl); }
public virtual int get_KeyOutputObject(out IVsOutput2 ppKeyOutput) { if (_keyOutput == null) { Refresh(); if (_keyOutput == null) { // horrible hack: we don't really have outputs but the Cider designer insists // that we have an output so it can figure out our output assembly name. So we // lie here, and then lie again to give a path in Output.get_Property _keyOutput = new Output(_project, null); } } ppKeyOutput = _keyOutput; if (ppKeyOutput == null) { return(VSConstants.S_FALSE); } return(VSConstants.S_OK); }
private static string GetFilenameFromOutput(IVsOutput2 output) { object propVal; int hr; try { hr = output.get_Property("OUTPUTLOC", out propVal); } catch (Exception ex) { hr = Marshal.GetHRForException(ex); propVal = null; } var path = propVal as string; if (ErrorHandler.Succeeded(hr) && !string.IsNullOrEmpty(path)) { return(path); } ErrorHandler.ThrowOnFailure(output.get_DeploySourceURL(out path)); return(new Uri(path).LocalPath); }
public override int get_KeyOutputObject(out IVsOutput2 ppKeyOutput) { ppKeyOutput = new DummyOutput(); return VSConstants.S_OK; }
/// <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); } }
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); }
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; }
private static string GetFilenameFromOutput(IVsOutput2 output) { object propVal; int hr; try { hr = output.get_Property("OUTPUTLOC", out propVal); } catch (Exception ex) { hr = Marshal.GetHRForException(ex); propVal = null; } var path = propVal as string; if (ErrorHandler.Succeeded(hr) && !string.IsNullOrEmpty(path)) { return path; } ErrorHandler.ThrowOnFailure(output.get_DeploySourceURL(out path)); return new Uri(path).LocalPath; }
public virtual int get_KeyOutputObject(out IVsOutput2 ppKeyOutput) { if (_keyOutput == null) { Refresh(); if (_keyOutput == null) { // horrible hack: we don't really have outputs but the Cider designer insists // that we have an output so it can figure out our output assembly name. So we // lie here, and then lie again to give a path in Output.get_Property _keyOutput = new Output(_project, null); } } ppKeyOutput = _keyOutput; if (ppKeyOutput == null) return VSConstants.S_FALSE; return VSConstants.S_OK; }
public virtual int get_KeyOutputObject(out IVsOutput2 ppKeyOutput) { if (keyOutput == null) Refresh(); ppKeyOutput = keyOutput; if (ppKeyOutput == null) return VSConstants.S_FALSE; return VSConstants.S_OK; }
public virtual int get_Outputs(uint celt, IVsOutput2[] rgpcfg, uint[] pcActual) { // Ensure that we are refreshed. This is somewhat of a hack that enables project to // project reference scenarios to work. Normally, output groups are populated as part // of build. However, in the project to project reference case, what ends up happening // is that the referencing projects requests the referenced project's output group // before a build is done on the referenced project. // // Furthermore, the project auto toolbox manager requires output groups to be populated // on project reopen as well... // // In the end, this is probably the right thing to do, though -- as it keeps the output // groups always up to date. Refresh(); // See if only the caller only wants to know the count if (celt == 0 || rgpcfg == null) { if (pcActual != null && pcActual.Length > 0) pcActual[0] = (uint)outputs.Count; return VSConstants.S_OK; } // Fill the array with our outputs uint count = 0; foreach (Output output in outputs) { if (rgpcfg.Length > count && celt > count && output != null) { rgpcfg[count] = output; ++count; } } if (pcActual != null && pcActual.Length > 0) pcActual[0] = count; // If the number asked for does not match the number returned, return S_FALSE return (count == celt) ? VSConstants.S_OK : VSConstants.S_FALSE; }
public override int get_KeyOutputObject(out IVsOutput2 ppKeyOutput) { ppKeyOutput = new DummyOutput(); return(VSConstants.S_OK); }