示例#1
0
        public virtual int OpenProjectCfg(string projectCfgCanonicalName, out IVsProjectCfg projectCfg)
        {

            Debug.Assert(projectCfgCanonicalName != null, "Cannot open project configuration for a null configuration");
            
            projectCfg = null;
            
            // Be robust in release
            if (projectCfgCanonicalName == null)
            {
                return NativeMethods.E_INVALIDARG;
            }
            

            Debug.Assert(this.Project != null && this.Project.MSBuildProject != null);

            string[] configs = this.Project.MSBuildProject.GetConditionedPropertyValues("Configuration");


            foreach (string config in configs)
            {
                if (String.Compare(config, projectCfgCanonicalName, true, CultureInfo.CurrentUICulture) == 0)
                {
                    projectCfg = new ProjectConfig(this.Project, config);
                    return NativeMethods.S_OK;
                }
            }
            
            return NativeMethods.E_INVALIDARG;
        }
示例#2
0
 public void GetCfgOfName(string name, string platName, out IVsCfg cfg) { 
   CCITracing.TraceCall();
   cfg = null;
   foreach (XmlElement e in this.projectManager.StateElement.SelectNodes("Build/Settings/Config")) {
     if (name == e.GetAttribute("Name")) {
       cfg = new ProjectConfig(this.projectManager, e);
       break;
     }
   }
 }
示例#3
0
文件: output.cs 项目: Jeremiahf/wix3
        /// <summary>
        /// Constructor for IVSOutput2 implementation
        /// </summary>
        /// <param name="projectManager">Project that produce this output</param>
        /// <param name="configuration">Configuration that produce this output</param>
        /// <param name="outputAssembly">MSBuild generated item corresponding to the output assembly (by default, these would be of type MainAssembly</param>
        public Output(ProjectNode projectManager, ProjectConfig configuration, ProjectElement outputAssembly)
        {
            if (projectManager == null)
                throw new ArgumentNullException("projectManager");
            if (configuration == null)
                throw new ArgumentNullException("configuration");
            if (outputAssembly == null)
                throw new ArgumentNullException("outputAssembly");

            project = projectManager;
            projectCfg = configuration;
            output = outputAssembly;
        }
示例#4
0
		/// <summary>
		/// Constructor for IVSOutputGroup2 implementation
		/// </summary>
		/// <param name="outputName">Name of the output group. See VS_OUTPUTGROUP_CNAME_Build in vsshell.idl for the list of standard values</param>
		/// <param name="msBuildTargetName">MSBuild target name</param>
		/// <param name="projectManager">Project that produce this output</param>
		/// <param name="configuration">Configuration that produce this output</param>
		public OutputGroup(string outputName, string msBuildTargetName, ProjectNode projectManager, ProjectConfig configuration)
		{
			if (outputName == null)
				throw new ArgumentNullException("outputName");
			if (msBuildTargetName == null)
				throw new ArgumentNullException("outputName");
			if (projectManager == null)
				throw new ArgumentNullException("projectManager");
			if (configuration == null)
				throw new ArgumentNullException("configuration");

			name = outputName;
			targetName = msBuildTargetName;
			project = projectManager;
			projectCfg = configuration;
		}
        /// <summary>
        /// The environment calls this to set the currently selected objects that the property page should show.
        /// </summary>
        /// <param name="count">The count of elements in <paramref name="punk"/>.</param>
        /// <param name="punk">An array of <b>IUnknown</b> objects to show in the property page.</param>
        /// <remarks>
        /// We are supposed to cache these objects until we get another call with <paramref name="count"/> = 0.
        /// Also, the environment is supposed to call this before calling <see cref="IPropertyPage2.Activate"/>,
        /// but like all things when interacting with Visual Studio, don't trust that and code defensively.
        /// </remarks>
        void IPropertyPage.SetObjects(uint count, object[] punk)
        {
            if (count == 0)
            {
                if (this.project != null)
                {
                    this.project.OutputTypeChanged -= this.HandleOutputTypeChanged;
                    this.project = null;
                }

                return;
            }

            if (punk[0] is ProjectConfig)
            {
                List<ProjectConfig> configs = new List<ProjectConfig>();

                for (int i = 0; i < count; i++)
                {
                    ProjectConfig config = (ProjectConfig)punk[i];

                    if (this.project == null)
                    {
                        this.project = config.ProjectMgr as WixProjectNode;
                        this.project.OutputTypeChanged += this.HandleOutputTypeChanged;
                    }

                    configs.Add(config);
                }

                this.projectConfigs = configs.ToArray();
            }
            else if (punk[0] is NodeProperties)
            {
                if (this.project == null)
                {
                    this.project = (punk[0] as NodeProperties).Node.ProjectMgr as WixProjectNode;
                    this.project.OutputTypeChanged += this.HandleOutputTypeChanged;
                }

                Dictionary<string, ProjectConfig> configsMap = new Dictionary<string, ProjectConfig>();

                for (int i = 0; i < count; i++)
                {
                    NodeProperties property = (NodeProperties)punk[i];
                    IVsCfgProvider provider;
                    ErrorHandler.ThrowOnFailure(property.Node.ProjectMgr.GetCfgProvider(out provider));
                    uint[] expected = new uint[1];
                    ErrorHandler.ThrowOnFailure(provider.GetCfgs(0, null, expected, null));
                    if (expected[0] > 0)
                    {
                        ProjectConfig[] configs = new ProjectConfig[expected[0]];
                        uint[] actual = new uint[1];
                        int hr = provider.GetCfgs(expected[0], configs, actual, null);
                        if (hr != 0)
                        {
                            Marshal.ThrowExceptionForHR(hr);
                        }

                        foreach (ProjectConfig config in configs)
                        {
                            if (!configsMap.ContainsKey(config.ConfigName))
                            {
                                configsMap.Add(config.ConfigName, config);
                            }
                        }
                    }
                }

                if (configsMap.Count > 0)
                {
                    if (this.projectConfigs == null)
                    {
                        this.projectConfigs = new ProjectConfig[configsMap.Keys.Count];
                    }

                    configsMap.Values.CopyTo(this.projectConfigs, 0);
                }
            }

            if (this.active && this.project != null)
            {
                this.PropertyPagePanel.BindProperties();
                this.IsDirty = false;
            }
        }
        /// <summary>
        /// Sets the value of the property.
        /// </summary>
        /// <param name="value">Property value to set.</param>
        /// <param name="configs">Optional list of configurations to set the property in;
        /// defaults to the project current configuration</param>
        /// <remarks>
        /// Before calling this method, the caller must ensure that the value is valid according to
        /// the <see cref="PropertyValidator"/> class, and that the project file is writable.
        /// In most cases the caller should also ensure that the new value is different from the
        /// existing value, to avoid dirtying the project file unnecessarily.
        /// </remarks>
        public void SetValue(string value, IList<ProjectConfig> configs)
        {
            WixHelperMethods.VerifyNonNullArgument(value, "value");

            value = value.Trim();

            PropertyPosition position = this.EndOfProjectFile ?
                PropertyPosition.UseExistingOrCreateAfterLastImport : PropertyPosition.UseExistingOrCreateAfterLastPropertyGroup;

            Project buildProject = this.project.BuildProject;
            if (this.PerUser)
            {
                if (this.project.UserBuildProject == null)
                {
                    this.project.CreateUserBuildProject();
                }

                buildProject = this.project.UserBuildProject;
            }

            value = this.Escape(value);

            if (this.PerConfig)
            {
                if (configs == null || configs.Count == 0)
                {
                    configs = new ProjectConfig[] { this.project.CurrentConfig };
                }

                foreach (ProjectConfig config in configs)
                {
                    buildProject.SetProperty(this.propertyName, value, config.Condition, position);
                }
            }
            else
            {
                buildProject.SetProperty(this.propertyName, value, null, position);
            }

            this.project.InvalidatePropertyCache();
            this.project.SetProjectFileDirty(true);
        }
示例#7
0
文件: outputgroup.cs 项目: fyisa/wix3
        /// <summary>
        /// Constructor for IVSOutputGroup2 implementation
        /// </summary>
        /// <param name="outputName">Name of the output group. See VS_OUTPUTGROUP_CNAME_Build in vsshell.idl for the list of standard values</param>
        /// <param name="msBuildTargetName">MSBuild target name</param>
        /// <param name="projectManager">Project that produce this output</param>
        /// <param name="configuration">Configuration that produce this output</param>
        public OutputGroup(string outputName, string msBuildTargetName, ProjectNode projectManager, ProjectConfig configuration)
        {
            if (outputName == null)
            {
                throw new ArgumentNullException("outputName");
            }
            if (msBuildTargetName == null)
            {
                throw new ArgumentNullException("outputName");
            }
            if (projectManager == null)
            {
                throw new ArgumentNullException("projectManager");
            }
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            name       = outputName;
            targetName = msBuildTargetName;
            project    = projectManager;
            projectCfg = configuration;
        }
示例#8
0
        /// <include file='doc\Project.uex' path='docs/doc[@for="ImageNames.OpenProjectCfg"]/*' />
        public virtual int OpenProjectCfg(string name, out  IVsProjectCfg cfg)
        {
            cfg = null;
            string[] configurations = this.projFile.GetConditionedPropertyValues("Configuration");
            foreach(string config in configurations)
            {
                if (String.Compare(name, config, true, CultureInfo.InvariantCulture) == 0)
                {
                    cfg = new ProjectConfig(this, config);
                    break;
                }
            }

            return cfg == null ? NativeMethods.E_INVALIDARG : NativeMethods.S_OK;
        }
示例#9
0
        /// <include file='doc\ConfigProvider.uex' path='docs/doc[@for="ConfigProvider.GetCfgOfName"]/*' />
        public virtual int GetCfgOfName(string name, string platName, out IVsCfg cfg)
        {
            cfg = null;
            cfg = new ProjectConfig(this.Project, name);

            return NativeMethods.S_OK;
        }
示例#10
0
        /// <include file='doc\ConfigProvider.uex' path='docs/doc[@for="ConfigProvider.GetCfgs"]/*' />
        public virtual int GetCfgs(uint celt, IVsCfg[] a, uint[] actual, uint[] flags)
        {
            if (flags != null)
                flags[0] = 0;

            int i = 0;
            string[] configList = this.Project.MSBuildProject.GetConditionedPropertyValues("Configuration");

            if (a != null)
            {
                foreach (string configName in configList)
                {
                    a[i] = new ProjectConfig(this.Project, configName);

                    i++;
                    if (i == celt)
                        break;
                }
            }
            else
                i = configList.Length;

            if (actual != null)
                actual[0] = (uint)i;

            return NativeMethods.S_OK;
        }
示例#11
0
        public virtual void SetObjects(uint count, object[] punk)
        {
            if (count > 0)
            {
                if (punk[0] is ProjectConfig)
                {
                    ArrayList configs = new ArrayList();

                    for (int i = 0; i < count; i++)
                    {
                        ProjectConfig config = (ProjectConfig)punk[i];

                        if (this.project == null)
                        {
                            this.project = config.ProjectMgr;
                        }

                        configs.Add(config);
                    }

                    this.projectConfigs = (ProjectConfig[])configs.ToArray(typeof(ProjectConfig));
                }
                else if (punk[0] is NodeProperties)
                {
                    if (this.project == null)
                    {
                        this.project = (punk[0] as NodeProperties).Node.ProjectMgr;
                    }

                    Dictionary <string, ProjectConfig> configsMap = new Dictionary <string, ProjectConfig>();

                    for (int i = 0; i < count; i++)
                    {
                        NodeProperties property = (NodeProperties)punk[i];
                        IVsCfgProvider provider;
                        ErrorHandler.ThrowOnFailure(property.Node.ProjectMgr.GetCfgProvider(out provider));
                        uint[] expected = new uint[1];
                        ErrorHandler.ThrowOnFailure(provider.GetCfgs(0, null, expected, null));
                        if (expected[0] > 0)
                        {
                            ProjectConfig[] configs = new ProjectConfig[expected[0]];
                            uint[]          actual  = new uint[1];
                            provider.GetCfgs(expected[0], configs, actual, null);

                            foreach (ProjectConfig config in configs)
                            {
                                if (!configsMap.ContainsKey(config.ConfigName))
                                {
                                    configsMap.Add(config.ConfigName, config);
                                }
                            }
                        }
                    }

                    if (configsMap.Count > 0)
                    {
                        if (this.projectConfigs == null)
                        {
                            this.projectConfigs = new ProjectConfig[configsMap.Keys.Count];
                        }
                        configsMap.Values.CopyTo(this.projectConfigs, 0);
                    }
                }
            }
            else
            {
                this.project = null;
            }

            if (this.active && this.project != null)
            {
                UpdateObjects();
            }
        }
示例#12
0
        protected virtual ProjectConfig CreateProjectConfiguration(string configName)
        {
            // if we already created it, return the cached one
            if (configurationsList.ContainsKey(configName))
                return configurationsList[configName];

            ProjectConfig requestedConfiguration = new ProjectConfig(this.project, configName);
            configurationsList.Add(configName, requestedConfiguration);

            return requestedConfiguration;
        }
示例#13
0
 public ProjectConfigProperties(ProjectConfig projectConfig)
 {
     this.projectConfig = projectConfig;
 }
示例#14
0
 public BuildableProjectConfig(ProjectConfig config)
 {
     this.config = config;
 }
示例#15
0
 /// <include file='doc\Project.uex' path='docs/doc[@for="ImageNames.OpenProjectCfg"]/*' />
 public virtual int OpenProjectCfg(string name, out  IVsProjectCfg cfg){
   cfg = null;
   foreach (XmlElement e in this.projFile.SelectNodes("//Build/Settings/Config")){
     if (name == e.GetAttribute("Name")){
       cfg = new ProjectConfig(this, e);
       break;
     }
   }
   return 0;
 }
示例#16
0
 /// <include file='doc\ConfigProvider.uex' path='docs/doc[@for="ConfigProvider.GetCfgOfName"]/*' />
 public int GetCfgOfName(string name, string platName, out IVsCfg cfg){
   cfg = null;
   foreach (XmlElement e in this.Project.StateElement.SelectNodes("Build/Settings/Config")){
     if (name == e.GetAttribute("Name")){
       cfg = new ProjectConfig(this.Project, e);
       break;
     }
   }
   return 0;
 }
示例#17
0
 /// <include file='doc\ConfigProvider.uex' path='docs/doc[@for="ConfigProvider.GetCfgs"]/*' />
 public int GetCfgs(uint celt, IVsCfg[] a, uint[] actual, uint[] flags){
   if (flags != null) flags[0] = 0;
   int i = 0;
   foreach (XmlElement e in this.Project.StateElement.SelectNodes("Build/Settings/Config")){
       if (a != null)
           a[i] = new ProjectConfig(this.Project, e);
       i++;
       if (i == celt)
           break;
   }
   if (actual != null) actual[0] = (uint)i;
   return 0;
 }
示例#18
0
 public BuildableProjectConfig(ProjectConfig config)
 {
     this.config = config;
 }
示例#19
0
 public void GetCfgs(uint celt, IVsCfg[] a, uint[] actual, uint[] flags) {
   CCITracing.TraceCall();
   if (flags != null) flags[0] = 0;
   int i = 0;
   foreach (XmlElement e in this.projectManager.StateElement.SelectNodes("Build/Settings/Config")) {
     if (a != null) 
       a[i] = new ProjectConfig(this.projectManager, e); 
     i++; 
     if (i == celt)
       break;
   }
   if (actual != null) actual[0] = (uint)i;
 }
示例#20
0
        public virtual void SetObjects(uint count, object[] punk)
        {
            if (count > 0)
            {
                if (punk[0] is ProjectConfig)
                {
                    ArrayList configs = new ArrayList();

                    for (int i = 0; i < count; i++)
                    {
                        ProjectConfig config = (ProjectConfig)punk[i];

                        if (this.project == null)
                        {
                            this.project = config.ProjectMgr;
                        }

                        configs.Add(config);
                    }

                    this.projectConfigs = (ProjectConfig[])configs.ToArray(typeof(ProjectConfig));
                }
                else if (punk[0] is NodeProperties)
                {
                    if (this.project == null)
                    {
                        this.project = (punk[0] as NodeProperties).Node.ProjectMgr;
                    }

                    Dictionary<string, ProjectConfig> configsMap = new Dictionary<string, ProjectConfig>();

                    for (int i = 0; i < count; i++)
                    {
                        NodeProperties property = (NodeProperties)punk[i];
                        IVsCfgProvider provider;
                        ErrorHandler.ThrowOnFailure(property.Node.ProjectMgr.GetCfgProvider(out provider));
                        uint[] expected = new uint[1];
                        ErrorHandler.ThrowOnFailure(provider.GetCfgs(0, null, expected, null));
                        if (expected[0] > 0)
                        {
                            ProjectConfig[] configs = new ProjectConfig[expected[0]];
                            uint[] actual = new uint[1];
                            provider.GetCfgs(expected[0], configs, actual, null);

                            foreach (ProjectConfig config in configs)
                            {
                                if (!configsMap.ContainsKey(config.ConfigName))
                                {
                                    configsMap.Add(config.ConfigName, config);
                                }
                            }
                        }
                    }

                    if (configsMap.Count > 0)
                    {
                        if (this.projectConfigs == null)
                        {
                            this.projectConfigs = new ProjectConfig[configsMap.Keys.Count];
                        }
                        configsMap.Values.CopyTo(this.projectConfigs, 0);
                    }
                }
            }
            else
            {
                this.project = null;
            }

            if (this.active && this.project != null)
            {
                UpdateObjects();
            }
        }
        /// <summary>
        /// Sets the value of the property.
        /// </summary>
        /// <param name="value">Property value to set.</param>
        /// <param name="configs">Optional list of configurations to set the property in;
        /// defaults to the project current configuration</param>
        /// <remarks>
        /// Before calling this method, the caller must ensure that the value is valid according to
        /// the <see cref="PropertyValidator"/> class, and that the project file is writable.
        /// In most cases the caller should also ensure that the new value is different from the
        /// existing value, to avoid dirtying the project file unnecessarily.
        /// </remarks>
        public void SetValue(string value, IList<ProjectConfig> configs)
        {
            WixHelperMethods.VerifyNonNullArgument(value, "value");

            value = value.Trim();

            MSBuild.Project buildProject = this.project.BuildProject;
            if (this.PerUser)
            {
                if (this.project.UserBuildProject == null)
                {
                    this.project.CreateUserBuildProject();
                }

                buildProject = this.project.UserBuildProject;
            }

            value = this.Escape(value);

            if (this.PerConfig)
            {
                if (configs == null || configs.Count == 0)
                {
                    configs = new ProjectConfig[] { this.project.CurrentConfig };
                }

                foreach (ProjectConfig config in configs)
                {
                    bool set = false;

                    // First see if there's an existing property group that matches our condition
                    foreach (ProjectPropertyGroupElement propGroup in buildProject.Xml.PropertyGroups)
                    {
                        // if there is, set it within that group
                        if (String.Equals(propGroup.Condition, config.Condition, StringComparison.Ordinal))
                        {
                            propGroup.SetProperty(this.propertyName, value);
                            set = true;
                            break;
                        }
                    }

                    // If not, add a new property group for the condition and set the property within it
                    if (!set)
                    {
                        ProjectPropertyGroupElement newPropGroup = buildProject.Xml.AddPropertyGroup();
                        newPropGroup.Condition = config.Condition;
                        newPropGroup.SetProperty(this.propertyName, value);
                        set = true;
                    }

                    buildProject.ReevaluateIfNecessary();
                }
            }
            else
            {
                if (this.EndOfProjectFile)
                {
                    List<ProjectPropertyGroupElement> propertyGroupsToDelete = new List<ProjectPropertyGroupElement>();

                    // First see if there's an existing property group with our property
                    foreach (ProjectPropertyGroupElement propGroup in buildProject.Xml.PropertyGroups)
                    {
                        List<ProjectPropertyElement> propertiesToDelete = new List<ProjectPropertyElement>();
                        if(!String.IsNullOrEmpty(propGroup.Condition))
                        {
                            continue;
                        }

                        foreach(ProjectPropertyElement property in propGroup.Properties)
                        {
                            // if there is, remove it so the new value is at the end of the file
                            if (String.IsNullOrEmpty(property.Condition) && String.Equals(property.Name, this.propertyName, StringComparison.OrdinalIgnoreCase))
                            {
                                propertiesToDelete.Add(property);
                            }
                        }

                        foreach (ProjectPropertyElement property in propertiesToDelete)
                        {
                            propGroup.RemoveChild(property);
                        }

                        if (propGroup.Count == 0)
                        {
                            propertyGroupsToDelete.Add(propGroup);
                        }
                    }

                    foreach (ProjectPropertyGroupElement propGroup in propertyGroupsToDelete)
                    {
                        buildProject.Xml.RemoveChild(propGroup);
                    }

                    ProjectPropertyGroupElement newPropGroup = buildProject.Xml.CreatePropertyGroupElement();
                    buildProject.Xml.AppendChild(newPropGroup);
                    newPropGroup.SetProperty(this.propertyName, value);
                }
                else
                {
                    buildProject.SetProperty(this.propertyName, value);
                }
            }

            this.project.InvalidatePropertyCache();
            this.project.SetProjectFileDirty(true);
        }
        private string GetValue(bool finalValue, IList<ProjectConfig> configs, bool booleanValue)
        {
            MSBuild.Project buildProject = this.PerUser ? this.project.UserBuildProject : this.project.BuildProject;
            if (buildProject == null)
            {
                return null;
            }

            string value;
            if (this.PerConfig)
            {
                if (configs == null || configs.Count == 0)
                {
                    configs = new ProjectConfig[] { this.project.CurrentConfig };
                }

                value = this.GetPerConfigValue(buildProject, finalValue, configs, booleanValue);
            }
            else
            {
                MSBuild.ProjectProperty buildProperty = buildProject.GetProperty(this.propertyName);
                value = this.GetBuildPropertyValue(buildProperty, finalValue);
                if (booleanValue && String.IsNullOrEmpty(value))
                {
                    value = Boolean.FalseString;
                }
            }

            return value;
        }
示例#23
0
 public ProjectConfigProperties(ProjectConfig projectConfig)
 {
     this.projectConfig = projectConfig;
 }