Example #1
0
        /// <summary>
        /// Set the configuration property in MSBuild.
        /// This does not get persisted and is used to evaluate msbuild conditions
        /// which are based on the $(Configuration) property.
        /// </summary>
        /// <param name="configKey">Configuration name</param>
        protected internal virtual void SetConfiguration(string configKey)
        {
            if (configKey == null)
                throw new ArgumentNullException("configKey");

            // Can't ask for the active config until the project is opened, so do nothing in that scenario
            if (!projectOpened)
                return;

            // We cannot change properties during the build so if the config
            // we want to se is the current, we do nothing otherwise we fail.
            if (this.BuildInProgress)
            {
                var currentConfigKey = ProjectConfig.TryGetActiveConfigurationAndPlatform(ServiceProvider, this);

                if (ProjectConfig.Eq(currentConfigKey, configKey))
                    return;

                throw new InvalidOperationException("Can't set other configuration during a build in progress.");
            }

            string configName;
            string platformName;
            if (!ProjectConfig.TrySplitConfigurationCanonicalName(configKey, out configName, out platformName))
                configName = configKey;

            bool propertiesChanged = this.buildProject.SetGlobalProperty(ProjectFileConstants.Configuration, configName);

            if (!string.IsNullOrWhiteSpace(platformName))
                propertiesChanged |= this.buildProject.SetGlobalProperty(ProjectFileConstants.Platform, ProjectConfig.ToMSBuildPlatform(platformName));

            //this.buildProject.ReevaluateIfNecessary(); //???

            if (this.currentConfig == null || propertiesChanged)
                this.currentConfig = this.buildProject.CreateProjectInstance();

            if (propertiesChanged || this.designTimeAssemblyResolution == null)
            {
                if (this.designTimeAssemblyResolution == null)
                    this.designTimeAssemblyResolution = new DesignTimeAssemblyResolution();

                this.designTimeAssemblyResolution.Initialize(this);
            }

            this.options = null;
        }
Example #2
0
        /// <summary>
        /// Set the configuration property in MSBuild.
        /// This does not get persisted and is used to evaluate msbuild conditions
        /// which are based on the $(Configuration) property.
        /// </summary>
        /// <param name="config">Configuration name</param>
        protected internal virtual void SetConfiguration(string config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // Can't ask for the active config until the project is opened, so do nothing in that scenario
            if (!projectOpened)
                return;

            // We cannot change properties during the build so if the config
            // we want to se is the current, we do nothing otherwise we fail.
            if (this.BuildInProgress)
            {
                EnvDTE.Project automationObject = this.GetAutomationObject() as EnvDTE.Project;
                string currentConfigName = Utilities.GetActiveConfigurationName(automationObject);
                bool configsAreEqual = String.Compare(currentConfigName, config, StringComparison.OrdinalIgnoreCase) == 0;

                if (configsAreEqual)
                {
                    return;
                }
                throw new InvalidOperationException();
            }

            bool propertiesChanged = this.buildProject.SetGlobalProperty(ProjectFileConstants.Configuration, config);
            if (this.currentConfig == null || propertiesChanged)
            {
                this.currentConfig = this.buildProject.CreateProjectInstance();
            }

            if (propertiesChanged || this.designTimeAssemblyResolution == null)
            {
                if (this.designTimeAssemblyResolution == null)
                {
                    this.designTimeAssemblyResolution = new DesignTimeAssemblyResolution();
                }

                this.designTimeAssemblyResolution.Initialize(this);
            }

            this.options = null;
        }
Example #3
0
        /// <summary>
        /// Set the configuration property in MSBuild.
        /// This does not get persisted and is used to evaluate msbuild conditions
        /// which are based on the $(Configuration) property.
        /// </summary>
        /// <param name="config">Configuration name</param>
        public virtual void SetConfiguration(string config, string platform)
        {
            if (config == null)
                throw new ArgumentNullException("config");
            if (platform == null)
                throw new ArgumentNullException("platform");

            // Can't ask for the active config until the project is opened, so do nothing in that scenario
            if (!projectOpened)
                return;

            // We cannot change properties during the build so if the config
            // we want to set is the current, we do nothing otherwise we fail.
            if (this.BuildInProgress)
            {
                EnvDTE.Project automationObject = this.GetAutomationObject() as EnvDTE.Project;
                string currentConfigName = Utilities.GetActiveConfigurationName(automationObject);
                string currentPlatformName = Utilities.GetActivePlatformName(automationObject);
                bool configsAreEqual =
                    string.Equals(currentConfigName, config, StringComparison.OrdinalIgnoreCase)
                    && string.Equals(currentPlatformName, platform, StringComparison.OrdinalIgnoreCase);

                if (configsAreEqual)
                {
                    return;
                }

                throw new InvalidOperationException("Cannot change configurations during a build.");
            }

            bool propertiesChanged = this.buildProject.SetGlobalProperty(ProjectFileConstants.Configuration, config);
            propertiesChanged |= this.buildProject.SetGlobalProperty(ProjectFileConstants.Platform, ConfigProvider.GetPlatformPropertyFromPlatformName(platform));

            var userBuildProject = UserBuildProject;
            if (userBuildProject != null)
            {
                propertiesChanged |= userBuildProject.SetGlobalProperty(ProjectFileConstants.Configuration, config);
                propertiesChanged |= userBuildProject.SetGlobalProperty(ProjectFileConstants.Platform, ConfigProvider.GetPlatformPropertyFromPlatformName(platform));
            }

            if (this.currentConfig == null || propertiesChanged)
            {
                this.currentConfig = this.buildProject.CreateProjectInstance();
            }

            if (propertiesChanged || (this.designTimeAssemblyResolution == null && !this.designTimeAssemblyResolutionFailed))
            {
                this.designTimeAssemblyResolutionFailed = false;

                if (this.designTimeAssemblyResolution == null)
                {
                    this.designTimeAssemblyResolution = new DesignTimeAssemblyResolution();
                }

                try
                {
                    this.designTimeAssemblyResolution.Initialize(this);
                }
                catch (InvalidOperationException)
                {
                    this.designTimeAssemblyResolution = null;
                    this.designTimeAssemblyResolutionFailed = true;
                }
            }

            this._options = null;
        }