// =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="WixBuildMacroCollection"/> class.
        /// </summary>
        /// <param name="project">The project from which to read the properties.</param>
        public WixBuildMacroCollection(WixProjectNode project)
        {
            WixHelperMethods.VerifyNonNullArgument(project, "project");

            // get the global SolutionX properties
            WixBuildMacroCollection.DefineSolutionProperties(project);
            foreach (string globalMacroName in globalMacroNames)
            {
                BuildProperty property = project.BuildEngine.GlobalProperties[globalMacroName];
                if (property == null)
                {
                    this.list.Add(globalMacroName, "*Undefined*");
                }
                else
                {
                    string value = property.FinalValue;
                    this.list.Add(globalMacroName, value);
                }
            }

            // we need to call GetTargetPath first so that TargetDir and TargetPath are resolved correctly
            EnvDTE.Project automationObject = project.GetAutomationObject() as EnvDTE.Project;
            string         configName       = Microsoft.VisualStudio.Package.Utilities.GetActiveConfigurationName(automationObject);
            string         platformName     = Microsoft.VisualStudio.Package.Utilities.GetActivePlatformName(automationObject);

            project.Build(configName, platformName, WixProjectFileConstants.MsBuildTarget.GetTargetPath);

            // get the ProjectX and TargetX variables
            foreach (string macroName in macroNames)
            {
                string value = project.GetProjectProperty(macroName);
                this.list.Add(macroName, value);
            }
        }
示例#2
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="WixBuildMacroCollection"/> class.
        /// </summary>
        /// <param name="project">The project from which to read the properties.</param>
        public WixBuildMacroCollection(WixProjectNode project)
        {
            WixHelperMethods.VerifyNonNullArgument(project, "project");

            // get the global SolutionX properties
            WixBuildMacroCollection.DefineSolutionProperties(project);
            foreach (string globalMacroName in globalMacroNames)
            {
                string property = null;
                project.BuildProject.GlobalProperties.TryGetValue(globalMacroName, out property);
                if (null == property)
                {
                    this.list.Add(globalMacroName, "*Undefined*");
                }
                else
                {
                    this.list.Add(globalMacroName, property);
                }
            }

            // we need to call GetTargetPath first so that TargetDir and TargetPath are resolved correctly
            ConfigCanonicalName configCanonicalName;

            if (!Utilities.TryGetActiveConfigurationAndPlatform(project.Site, project, out configCanonicalName))
            {
                throw new InvalidOperationException();
            }
            Microsoft.VisualStudio.Package.BuildResult res = project.Build(configCanonicalName, WixProjectFileConstants.MsBuildTarget.GetTargetPath);

            // get the ProjectX and TargetX variables
            foreach (string macroName in macroNames)
            {
                string value;
                if (res.ProjectInstance != null)
                {
                    value = res.ProjectInstance.GetPropertyValue(macroName);
                }
                else
                {
                    value = project.GetProjectProperty(macroName);
                }

                this.list.Add(macroName, value);
            }
        }
 /// <summary>
 /// Executes an MSBuild target.
 /// </summary>
 /// <param name="target">Name of the MSBuild target to execute.</param>
 /// <returns>Result from executing the target (success/failure).</returns>
 protected override MSBuildResult InvokeMsBuild(string target)
 {
     WixBuildMacroCollection.DefineSolutionProperties(this);
     WixBuildMacroCollection.DefineProjectReferenceConfigurations(this);
     return(base.InvokeMsBuild(target));
 }