public ProjectConfig(ProjectNode project, string configuration) { this.project = project; this.configName = configuration; // Because the project can be aggregated by a flavor, we need to make sure // we get the outer most implementation of that interface (hence: project --> IUnknown --> Interface) IntPtr projectUnknown = Marshal.GetIUnknownForObject(this.ProjectMgr); try { IVsProjectFlavorCfgProvider flavorCfgProvider = (IVsProjectFlavorCfgProvider)Marshal.GetTypedObjectForIUnknown(projectUnknown, typeof(IVsProjectFlavorCfgProvider)); ErrorHandler.ThrowOnFailure(flavorCfgProvider.CreateProjectFlavorCfg(this, out flavoredCfg)); if (flavoredCfg == null) { throw new COMException(); } } finally { if (projectUnknown != IntPtr.Zero) { Marshal.Release(projectUnknown); } } // if the flavored object support XML fragment, initialize it IPersistXMLFragment persistXML = flavoredCfg as IPersistXMLFragment; if (null != persistXML) { this.project.LoadXmlFragment(persistXML, this.DisplayName); } }
internal ProjectConfig(ProjectNode project, string configuration) { this.project = project; if (configuration.Contains("|")) // If configuration is in the form "<Configuration>|<Platform>" { string[] configStrArray = configuration.Split('|'); if (2 == configStrArray.Length) { this.configName = configStrArray[0]; this.platformName = configStrArray[1]; } else { throw new Exception(string.Format(CultureInfo.InvariantCulture, "Invalid configuration format: {0}", configuration)); } } else // If configuration is in the form "<Configuration>" { this.configName = configuration; } var flavoredCfgProvider = ProjectMgr.GetOuterInterface <IVsProjectFlavorCfgProvider>(); Utilities.ArgumentNotNull("flavoredCfgProvider", flavoredCfgProvider); ErrorHandler.ThrowOnFailure(flavoredCfgProvider.CreateProjectFlavorCfg(this, out flavoredCfg)); Utilities.ArgumentNotNull("flavoredCfg", flavoredCfg); // if the flavored object support XML fragment, initialize it IPersistXMLFragment persistXML = flavoredCfg as IPersistXMLFragment; if (null != persistXML) { this.project.LoadXmlFragment(persistXML, configName, platformName); } }
public ProjectConfig(ProjectNode project, string configuration, string platform) { if (project == null) { throw new ArgumentNullException("project"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } if (platform == null) { throw new ArgumentNullException("platform"); } if (string.IsNullOrEmpty("configuration")) { throw new ArgumentException("configuration cannot be null or empty"); } if (string.IsNullOrEmpty("platform")) { throw new ArgumentException("platform cannot be null or empty"); } this._project = project; this._configName = configuration; this._platform = platform; // Because the project can be aggregated by a flavor, we need to make sure // we get the outer most implementation of that interface (hence: project --> IUnknown --> Interface) IntPtr projectUnknown = Marshal.GetIUnknownForObject(this.ProjectManager); try { IVsProjectFlavorCfgProvider flavorCfgProvider = (IVsProjectFlavorCfgProvider)Marshal.GetTypedObjectForIUnknown(projectUnknown, typeof(IVsProjectFlavorCfgProvider)); ErrorHandler.ThrowOnFailure(flavorCfgProvider.CreateProjectFlavorCfg(this, out flavoredCfg)); if (flavoredCfg == null) { ErrorHandler.ThrowOnFailure(VSConstants.E_FAIL); } } finally { if (projectUnknown != IntPtr.Zero) { Marshal.Release(projectUnknown); } } // if the flavored object support XML fragment, initialize it IPersistXMLFragment persistXML = flavoredCfg as IPersistXMLFragment; if (null != persistXML) { this._project.LoadXmlFragment(persistXML, this.DisplayName); } }
public ProjectConfig(ProjectNode project, string configuration) { this.project = project; // !EFW - Bug in VS2015 or an incompatibility with the older MPF project system. This can get // passed an invalid configuration value such as "Debug|Any CPU". As a workaround, trim off the // invalid part. if (!String.IsNullOrWhiteSpace(configuration) && configuration.IndexOf('|') != -1) { this.configName = configuration.Substring(0, configuration.IndexOf('|')); } else { this.configName = configuration; } // Because the project can be aggregated by a flavor, we need to make sure // we get the outer most implementation of that interface (hence: project --> IUnknown --> Interface) IntPtr projectUnknown = Marshal.GetIUnknownForObject(this.ProjectMgr); try { IVsProjectFlavorCfgProvider flavorCfgProvider = (IVsProjectFlavorCfgProvider)Marshal.GetTypedObjectForIUnknown(projectUnknown, typeof(IVsProjectFlavorCfgProvider)); ErrorHandler.ThrowOnFailure(flavorCfgProvider.CreateProjectFlavorCfg(this, out flavoredCfg)); if (flavoredCfg == null) { throw new COMException(); } } finally { if (projectUnknown != IntPtr.Zero) { Marshal.Release(projectUnknown); } } // if the flavored object support XML fragment, initialize it IPersistXMLFragment persistXML = flavoredCfg as IPersistXMLFragment; if (null != persistXML) { this.project.LoadXmlFragment(persistXML, this.DisplayName); } }
internal ProjectConfig(ProjectNode project, string configuration) { this.project = project; this.configName = configuration; var flavoredCfgProvider = ProjectMgr.GetOuterInterface <IVsProjectFlavorCfgProvider>(); Utilities.ArgumentNotNull("flavoredCfgProvider", flavoredCfgProvider); ErrorHandler.ThrowOnFailure(flavoredCfgProvider.CreateProjectFlavorCfg(this, out flavoredCfg)); Utilities.ArgumentNotNull("flavoredCfg", flavoredCfg); // if the flavored object support XML fragment, initialize it IPersistXMLFragment persistXML = flavoredCfg as IPersistXMLFragment; if (null != persistXML) { this.project.LoadXmlFragment(persistXML, configName); } }
/// <summary> /// Initialize an object with an XML fragment. /// </summary> /// <param name="iPersistXMLFragment">Object that support being initialized with an XML fragment</param> /// <param name="configName">Name of the configuration being initialized, null if it is the project</param> protected internal void LoadXmlFragment(IPersistXMLFragment persistXmlFragment, string configName) { if (persistXmlFragment == null) { throw new ArgumentNullException("persistXmlFragment"); } if (xmlFragments == null) { // Retrieve the xml fragments from MSBuild xmlFragments = new XmlDocument(); string fragments = GetProjectExtensions()[ProjectFileConstants.VisualStudio]; fragments = String.Format(CultureInfo.InvariantCulture, "<root>{0}</root>", fragments); xmlFragments.LoadXml(fragments); } // We need to loop through all the flavors string flavorsGuid; ErrorHandler.ThrowOnFailure(((IVsAggregatableProject)this).GetAggregateProjectTypeGuids(out flavorsGuid)); foreach (Guid flavor in Utilities.GuidsArrayFromSemicolonDelimitedStringOfGuids(flavorsGuid)) { // Look for a matching fragment string flavorGuidString = flavor.ToString("B"); string fragment = null; XmlNode node = null; foreach (XmlNode child in xmlFragments.FirstChild.ChildNodes) { if (child.Attributes.Count > 0) { string guid = String.Empty; string configuration = String.Empty; if (child.Attributes[ProjectFileConstants.Guid] != null) guid = child.Attributes[ProjectFileConstants.Guid].Value; if (child.Attributes[ProjectFileConstants.Configuration] != null) configuration = child.Attributes[ProjectFileConstants.Configuration].Value; if (String.Compare(child.Name, ProjectFileConstants.FlavorProperties, StringComparison.OrdinalIgnoreCase) == 0 && String.Compare(guid, flavorGuidString, StringComparison.OrdinalIgnoreCase) == 0 && ((String.IsNullOrEmpty(configName) && String.IsNullOrEmpty(configuration)) || (String.Compare(configuration, configName, StringComparison.OrdinalIgnoreCase) == 0))) { // we found the matching fragment fragment = child.InnerXml; node = child; break; } } } Guid flavorGuid = flavor; if (String.IsNullOrEmpty(fragment)) { // the fragment was not found so init with default values ErrorHandler.ThrowOnFailure(persistXmlFragment.InitNew(ref flavorGuid, (uint)_PersistStorageType.PST_PROJECT_FILE)); // While we don't yet support user files, our flavors might, so we will store that in the project file until then // TODO: Refactor this code when we support user files ErrorHandler.ThrowOnFailure(persistXmlFragment.InitNew(ref flavorGuid, (uint)_PersistStorageType.PST_USER_FILE)); } else { ErrorHandler.ThrowOnFailure(persistXmlFragment.Load(ref flavorGuid, (uint)_PersistStorageType.PST_PROJECT_FILE, fragment)); // While we don't yet support user files, our flavors might, so we will store that in the project file until then // TODO: Refactor this code when we support user files if (node.NextSibling != null && node.NextSibling.Attributes[ProjectFileConstants.User] != null) ErrorHandler.ThrowOnFailure(persistXmlFragment.Load(ref flavorGuid, (uint)_PersistStorageType.PST_USER_FILE, node.NextSibling.InnerXml)); } } }