From: Rob M. <ro...@us...> - 2010-01-29 11:40:37
|
Update of /cvsroot/wix/wix3.5/src/ext/VSExtension/wixext In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv18774/src/ext/VSExtension/wixext Modified Files: VSHeatExtension.cs VSProjectHarvester.cs Log Message: JaredR: Added UX/Payload/PayloadGroup to Bundle language schema. Added Parsing for Payload/PayloadGroup(Ref) to Compiler. Added flattening of UX payloads to Linker. Added binding of UX payloads into output in Binder Added "just enough" of burnexe into Binder to start generation of bundle output (stub exe with attached UX container). JaredR: Created BurnWriter to replace SectionWriter and handle PE re-writing in safe code. Modified Binder to use BurnWriter for creating Bundles. Removed SectionWriter. Removed "Allow unsafe code" from Wix.csproj JaredR: Changed Bundle to require one UX element. Added simple Chain/MsiPackage/ExePackage to Bundle language schema. Updated Binder bundle code to generate chain/package information in Burn manifest and ParameterInfo to create a basic chainer. APaloma: Changed heat to use the new MSBuild API when harvesting VS 2010 projects. Fixed WiX projects being detected as non-MSBuildable in VS 2010. Fixed discrepancies between what projects were referenced in the new generated file and which ones heat actually generated authoring for. Fixed problems with missing or wrong project information being defined in project reference variables for VS 2010. Fixed build action not being changable on the property grid in VS 2010. Fixed heat generating Directory/@Name attributes containing "..". JaredR: Changed Bundle Chain to require one package element, and updated a failing unit test to include the now-required element. Refactored Binder.ChainPackageInfo.PackageType to Compiler.ChainPackageType so that hard-coded in order to remove some hard-coded strings. Changed Payload and *Package ID generation to use deterministic CompilerCore.GenerateIdentifier() method. Added end-to-end support for Variables in Bundles. CAraman: fixes for /W4 and static analysis APaloma: Added ability for heat to harvest projects to PayloadGroups. Added better error messages for when heat is unable to build targets in an MSBuild project when harvesting projects. Fixed heat generating Ids with invalid characters when project names contain characters that aren't valid for identifiers. APaloma: Added enforcing of valid identifer characters on ComponentGroup and ComponentGroupRef. MikeHo: Fix issue with DoesShareExist code, fix static analysis errors in IIS7 CAs APaloma: Added property for project references in Votive to completely disable automatic harvesting for a reference. APaloma: SFBUG:2940161 - Fixed heat generating ComponentGroups with duplicate Ids when using the -cg switch. MiCarls: Fix some issues found by static analysis MiCarls: Fix a scenario related to website locators, broken from previous fix RobMen: introduce buxutil.lib, Burn User Experience Utility library. Index: VSHeatExtension.cs =================================================================== RCS file: /cvsroot/wix/wix3.5/src/ext/VSExtension/wixext/VSHeatExtension.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** VSHeatExtension.cs 22 Jan 2010 10:05:13 -0000 1.3 --- VSHeatExtension.cs 29 Jan 2010 11:40:28 -0000 1.4 *************** *** 38,42 **** /// <summary>Generate a Bundle Layout.</summary> ! Layout } --- 38,45 ---- /// <summary>Generate a Bundle Layout.</summary> ! Layout, ! ! /// <summary>Generate a PayloadGroup with Payloads.</summary> ! PayloadGroup } *************** *** 74,78 **** new HeatCommandLineOption("-generate", Environment.NewLine + " specify what elements to generate, one of:" + Environment.NewLine + ! " components, container, layout" + Environment.NewLine + " (default is components)"), new HeatCommandLineOption("-pog", Environment.NewLine + --- 77,81 ---- new HeatCommandLineOption("-generate", Environment.NewLine + " specify what elements to generate, one of:" + Environment.NewLine + ! " components, container, payloadgroup, layout" + Environment.NewLine + " (default is components)"), new HeatCommandLineOption("-pog", Environment.NewLine + *************** *** 126,141 **** } ! string genType = args[i]; switch(genType) { ! case "layout": generateType = GenerateType.Layout; break; ! case "container": generateType = GenerateType.Container; break; ! case "components": generateType = GenerateType.Components; break; default: throw new WixException(VSErrors.InvalidOutputType(genType)); --- 129,147 ---- } ! string genType = args[i].ToUpperInvariant(); switch(genType) { ! case "LAYOUT": generateType = GenerateType.Layout; break; ! case "CONTAINER": generateType = GenerateType.Container; break; ! case "COMPONENTS": generateType = GenerateType.Components; break; + case "PAYLOADGROUP": + generateType = GenerateType.PayloadGroup; + break; default: throw new WixException(VSErrors.InvalidOutputType(genType)); Index: VSProjectHarvester.cs =================================================================== RCS file: /cvsroot/wix/wix3.5/src/ext/VSExtension/wixext/VSProjectHarvester.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** VSProjectHarvester.cs 22 Jan 2010 10:05:13 -0000 1.4 --- VSProjectHarvester.cs 29 Jan 2010 11:40:28 -0000 1.5 *************** *** 27,30 **** --- 27,34 ---- using System.Runtime.InteropServices; using System.Text.RegularExpressions; + using System.Xml; + + using Microsoft.Build.Framework; + using Microsoft.Build.Utilities; // Instead of directly referencing this .NET 2.0 assembly, *************** *** 285,288 **** --- 289,294 ---- } + string sanitizedProjectName = HarvesterCore.GetIdentifierFromName(projectName); + Wix.IParentElement harvestParent; *************** *** 292,296 **** harvestParent = container; ! container.Name = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, projectName, pog.Name); } else if (this.GenerateType == GenerateType.Layout) --- 298,309 ---- harvestParent = container; ! container.Name = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name); ! } ! else if (this.GenerateType == GenerateType.PayloadGroup) ! { ! Wix.PayloadGroup container = new Wix.PayloadGroup(); ! harvestParent = container; ! ! container.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name); } else if (this.GenerateType == GenerateType.Layout) *************** *** 302,310 **** if (this.setUniqueIdentifiers) { ! layoutDirectory.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, projectName, pog.Name); } else { ! layoutDirectory.Id = HarvesterCore.GetIdentifierFromName(String.Format(CultureInfo.InvariantCulture, VSProjectHarvester.DirectoryIdFormat, projectName, pog.Name)); } } --- 315,323 ---- if (this.setUniqueIdentifiers) { ! layoutDirectory.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name); } else { ! layoutDirectory.Id = HarvesterCore.GetIdentifierFromName(String.Format(CultureInfo.InvariantCulture, VSProjectHarvester.DirectoryIdFormat, sanitizedProjectName, pog.Name)); } } *************** *** 320,328 **** else if (this.setUniqueIdentifiers) { ! directoryRef.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, projectName, pog.Name); } else { ! directoryRef.Id = HarvesterCore.GetIdentifierFromName(String.Format(CultureInfo.InvariantCulture, VSProjectHarvester.DirectoryIdFormat, projectName, pog.Name)); } --- 333,341 ---- else if (this.setUniqueIdentifiers) { ! directoryRef.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name); } else { ! directoryRef.Id = HarvesterCore.GetIdentifierFromName(String.Format(CultureInfo.InvariantCulture, VSProjectHarvester.DirectoryIdFormat, sanitizedProjectName, pog.Name)); } *************** *** 353,356 **** --- 366,378 ---- fragmentList.Add(fragment); } + else if (this.GenerateType == GenerateType.PayloadGroup) + { + // harvestParent must be a Container at this point + Wix.PayloadGroup payloadGroup = harvestParent as Wix.PayloadGroup; + + Wix.Fragment fragment = new Wix.Fragment(); + fragment.AddChild(payloadGroup); + fragmentList.Add(fragment); + } else if (this.GenerateType == GenerateType.Layout) { *************** *** 378,382 **** if (this.setUniqueIdentifiers) { ! cg.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, projectName, pog.Name); } else --- 400,404 ---- if (this.setUniqueIdentifiers) { ! cg.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name); } else *************** *** 468,473 **** Wix.IParentElement parentDir = parent; ! // Ignore Containers because they do not have a nested structure. ! if (baseDir != null && !String.Equals(Path.GetDirectoryName(baseDir), fileDir, StringComparison.OrdinalIgnoreCase) && this.GenerateType != GenerateType.Container) { Uri baseUri = new Uri(baseDir); --- 490,496 ---- Wix.IParentElement parentDir = parent; ! // Ignore Containers and PayloadGroups because they do not have a nested structure. ! if (baseDir != null && !String.Equals(Path.GetDirectoryName(baseDir), fileDir, StringComparison.OrdinalIgnoreCase) ! && this.GenerateType != GenerateType.Container && this.GenerateType != GenerateType.PayloadGroup) { Uri baseUri = new Uri(baseDir); *************** *** 491,499 **** } ! if (this.GenerateType == GenerateType.Container) { Wix.Payload payload = new Wix.Payload(); ! HarvestProjectOutputGroupContainerFile(baseDir, projectName, pogName, pogFileSource, filePath, fileName, link, parentDir, payload, seenList); } else if (this.GenerateType == GenerateType.Layout) --- 514,522 ---- } ! if (this.GenerateType == GenerateType.Container || this.GenerateType == GenerateType.PayloadGroup) { Wix.Payload payload = new Wix.Payload(); ! HarvestProjectOutputGroupPayloadFile(baseDir, projectName, pogName, pogFileSource, filePath, fileName, link, parentDir, payload, seenList); } else if (this.GenerateType == GenerateType.Layout) *************** *** 617,621 **** } ! private void HarvestProjectOutputGroupContainerFile(string baseDir, string projectName, string pogName, string pogFileSource, string filePath, string fileName, string link, Wix.IParentElement parentDir, Wix.Payload file, Dictionary<string, bool> seenList) { string varFormat = VariableFormat; --- 640,644 ---- } ! private void HarvestProjectOutputGroupPayloadFile(string baseDir, string projectName, string pogName, string pogFileSource, string filePath, string fileName, string link, Wix.IParentElement parentDir, Wix.Payload file, Dictionary<string, bool> seenList) { string varFormat = VariableFormat; *************** *** 745,748 **** --- 768,776 ---- DirectoryAttributeAccessor subDir = null; + if (String.Equals(firstSubDirName, "..", StringComparison.Ordinal)) + { + return parentDir; + } + Type directoryType; Type directoryRefType; *************** *** 836,864 **** } ! private static MSBuildProject GetMsbuildProject(string projectFile) { ! MSBuildProject project = ConstructMsbuildProject(projectFile); ! ! if ("2.0.0.0" != project.LoadVersion) { ! project.Load(projectFile); ! string version = project.GetDefaultToolsVersion(); ! if ("2.0" == version) { ! project = ConstructMsbuildProject(projectFile, "2.0.0.0"); } } return project; } ! private static MSBuildProject ConstructMsbuildProject(string projectFile) { ! return ConstructMsbuildProject(projectFile, null); } ! private static MSBuildProject ConstructMsbuildProject(string projectFile, string loadVersion) { const string MSBuildEngineAssemblyName = "Microsoft.Build.Engine, Version={0}, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; --- 864,919 ---- } ! private MSBuildProject GetMsbuildProject(string projectFile) { ! XmlDocument document = new XmlDocument(); ! try { ! document.Load(projectFile); ! } ! catch (Exception e) ! { ! throw new WixException(VSErrors.CannotLoadProject(projectFile, e.Message)); ! } ! string version = "3.5"; ! foreach (XmlNode child in document.ChildNodes) ! { ! if (String.Equals(child.Name, "Project", StringComparison.Ordinal) && child.Attributes != null) { ! XmlNode toolsVersionAttribute = child.Attributes["ToolsVersion"]; ! if (toolsVersionAttribute != null) ! { ! version = toolsVersionAttribute.Value; ! this.Core.OnMessage(VSVerboses.FoundToolsVersion(version)); ! } } } + this.Core.OnMessage(VSVerboses.LoadingProject(version)); + + MSBuildProject project; + switch(version) + { + case "2.0": + project = ConstructMsbuild35Project(projectFile, "2.0.0.0"); + break; + case "4.0": + project = ConstructMsbuild40Project(projectFile, this.Core); + break; + default: + project = ConstructMsbuild35Project(projectFile); + break; + } + return project; } ! private static MSBuildProject ConstructMsbuild35Project(string projectFile) { ! return ConstructMsbuild35Project(projectFile, null); } ! private static MSBuildProject ConstructMsbuild35Project(string projectFile, string loadVersion) { const string MSBuildEngineAssemblyName = "Microsoft.Build.Engine, Version={0}, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; *************** *** 892,896 **** try { ! engineType = msbuildAssembly.GetType("Microsoft.Build.BuildEngine.Engine"); if (msbuildAssembly.GetName().Version.Major >= 3) { --- 947,951 ---- try { ! engineType = msbuildAssembly.GetType("Microsoft.Build.BuildEngine.Engine", true); if (msbuildAssembly.GetName().Version.Major >= 3) { *************** *** 905,911 **** } ! buildItemType = msbuildAssembly.GetType("Microsoft.Build.BuildEngine.BuildItem"); ! projectType = msbuildAssembly.GetType("Microsoft.Build.BuildEngine.Project"); project = projectType.GetConstructor(new Type[] { engineType }).Invoke(new object[] { engine }); } --- 960,966 ---- } ! buildItemType = msbuildAssembly.GetType("Microsoft.Build.BuildEngine.BuildItem", true); ! projectType = msbuildAssembly.GetType("Microsoft.Build.BuildEngine.Project", true); project = projectType.GetConstructor(new Type[] { engineType }).Invoke(new object[] { engine }); } *************** *** 917,921 **** !String.Equals(loadVersion, "2.0.0.0", StringComparison.Ordinal)) { ! return ConstructMsbuildProject(projectFile, "2.0.0.0"); } throw new WixException(VSErrors.CannotLoadMSBuildEngine(tie.InnerException.Message)); --- 972,976 ---- !String.Equals(loadVersion, "2.0.0.0", StringComparison.Ordinal)) { ! return ConstructMsbuild35Project(projectFile, "2.0.0.0"); } throw new WixException(VSErrors.CannotLoadMSBuildEngine(tie.InnerException.Message)); *************** *** 926,943 **** } ! return new MSBuildProject(project, projectType, buildItemType, loadVersion); } ! private static bool AreTypesEquivalent(Type a, Type b) { ! return (a == b) || (a.IsAssignableFrom(b) && b.IsAssignableFrom(a)); } ! private class MSBuildProject { Type projectType; Type buildItemType; ! object project; ! string loadVersion; public MSBuildProject(object project, Type projectType, Type buildItemType, string loadVersion) --- 981,1071 ---- } ! return new MSBuild35Project(project, projectType, buildItemType, loadVersion); } ! private static MSBuildProject ConstructMsbuild40Project(string projectFile, HarvesterCore harvesterCore) { ! return ConstructMsbuild40Project(projectFile, harvesterCore, null); } ! private static MSBuildProject ConstructMsbuild40Project(string projectFile, HarvesterCore harvesterCore, string loadVersion) { + const string MSBuildEngineAssemblyName = "Microsoft.Build, Version={0}, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; + Assembly msbuildAssembly = null; + + loadVersion = loadVersion ?? "4.0.0.0"; + + try + { + try + { + msbuildAssembly = Assembly.Load(String.Format(MSBuildEngineAssemblyName, loadVersion)); + } + catch (FileNotFoundException) + { + loadVersion = "4.0.0.0"; + msbuildAssembly = Assembly.Load(String.Format(MSBuildEngineAssemblyName, loadVersion)); + } + } + catch (Exception e) + { + throw new WixException(VSErrors.CannotLoadMSBuildAssembly(e.Message)); + } + Type projectType; Type buildItemType; ! ! Type buildManagerType; ! Type buildParametersType; ! Type buildRequestDataFlagsType; ! Type buildRequestDataType; ! Type hostServicesType; ! Type projectCollectionType; ! Type projectInstanceType; ! ! try ! { ! buildItemType = msbuildAssembly.GetType("Microsoft.Build.Execution.ProjectItemInstance", true); ! projectType = msbuildAssembly.GetType("Microsoft.Build.Evaluation.Project", true); ! ! buildManagerType = msbuildAssembly.GetType("Microsoft.Build.Execution.BuildManager", true); ! buildParametersType = msbuildAssembly.GetType("Microsoft.Build.Execution.BuildParameters", true); ! buildRequestDataFlagsType = msbuildAssembly.GetType("Microsoft.Build.Execution.BuildRequestDataFlags", true); ! buildRequestDataType = msbuildAssembly.GetType("Microsoft.Build.Execution.BuildRequestData", true); ! hostServicesType = msbuildAssembly.GetType("Microsoft.Build.Execution.HostServices", true); ! projectCollectionType = msbuildAssembly.GetType("Microsoft.Build.Evaluation.ProjectCollection", true); ! projectInstanceType = msbuildAssembly.GetType("Microsoft.Build.Execution.ProjectInstance", true); ! } ! catch (TargetInvocationException tie) ! { ! throw new WixException(VSErrors.CannotLoadMSBuildEngine(tie.InnerException.Message)); ! } ! catch (Exception e) ! { ! throw new WixException(VSErrors.CannotLoadMSBuildEngine(e.Message)); ! } ! ! MSBuild40Types types = new MSBuild40Types(); ! types.buildManagerType = buildManagerType; ! types.buildParametersType = buildParametersType; ! types.buildRequestDataFlagsType = buildRequestDataFlagsType; ! types.buildRequestDataType = buildRequestDataType; ! types.hostServicesType = hostServicesType; ! types.projectCollectionType = projectCollectionType; ! types.projectInstanceType = projectInstanceType; ! return new MSBuild40Project(null, projectType, buildItemType, loadVersion, types, harvesterCore); ! } ! ! private static bool AreTypesEquivalent(Type a, Type b) ! { ! return (a == b) || (a.IsAssignableFrom(b) && b.IsAssignableFrom(a)); ! } ! ! private abstract class MSBuildProject ! { ! protected Type projectType; ! protected Type buildItemType; ! protected object project; ! protected string loadVersion; public MSBuildProject(object project, Type projectType, Type buildItemType, string loadVersion) *************** *** 951,959 **** public string LoadVersion { ! get ! { return this.loadVersion; } } ! public bool Build(string projectFileName, string[] targetNames, IDictionary targetOutputs) { try --- 1079,1104 ---- public string LoadVersion { ! get { return this.loadVersion; } } ! public abstract bool Build(string projectFileName, string[] targetNames, IDictionary targetOutputs); ! ! public abstract string GetBuildItemFinalItemSpec(object buildItem); ! ! public abstract IEnumerable GetEvaluatedItemsByName(string itemName); ! ! public abstract string GetEvaluatedProperty(string propertyName); ! ! public abstract void Load(string projectFileName); ! } ! ! private class MSBuild35Project : MSBuildProject ! { ! public MSBuild35Project(object project, Type projectType, Type buildItemType, string loadVersion) ! : base(project, projectType, buildItemType, loadVersion) ! { ! } ! ! public override bool Build(string projectFileName, string[] targetNames, IDictionary targetOutputs) { try *************** *** 962,965 **** --- 1107,1114 ---- return (bool)buildMethod.Invoke(project, new object[] { targetNames, targetOutputs }); } + catch (TargetInvocationException tie) + { + throw new WixException(VSErrors.CannotBuildProject(projectFileName, tie.InnerException.Message)); + } catch (Exception e) { *************** *** 968,972 **** } ! public string GetBuildItemFinalItemSpec(object buildItem) { PropertyInfo includeProperty = this.buildItemType.GetProperty("FinalItemSpec"); --- 1117,1121 ---- } ! public override string GetBuildItemFinalItemSpec(object buildItem) { PropertyInfo includeProperty = this.buildItemType.GetProperty("FinalItemSpec"); *************** *** 974,1011 **** } ! public string GetDefaultToolsVersion() { ! string version = null; try { ! PropertyInfo pi = projectType.GetProperty("DefaultToolsVersion"); ! version = (string)pi.GetValue(this.project, null); } ! catch { ! version = "2.0"; } ! return version; } ! public IEnumerable GetEvaluatedItemsByName(string itemName) { ! MethodInfo getEvaluatedItem = projectType.GetMethod("GetEvaluatedItemsByName", new Type[] { typeof(string) }); ! return (IEnumerable)getEvaluatedItem.Invoke(project, new object[] { itemName }); } ! public string GetEvaluatedProperty(string propertyName) { ! MethodInfo getProperty = projectType.GetMethod("GetEvaluatedProperty", new Type[] { typeof(string) }); ! return (string)getProperty.Invoke(project, new object[] { propertyName }); } ! public void Load(string projectFileName) { try { ! projectType.GetMethod("Load", new Type[] { typeof(string) }).Invoke(project, new object[] { projectFileName }); } catch (TargetInvocationException tie) --- 1123,1293 ---- } ! public override IEnumerable GetEvaluatedItemsByName(string itemName) { ! MethodInfo getEvaluatedItem = projectType.GetMethod("GetEvaluatedItemsByName", new Type[] { typeof(string) }); ! return (IEnumerable)getEvaluatedItem.Invoke(project, new object[] { itemName }); ! } + public override string GetEvaluatedProperty(string propertyName) + { + MethodInfo getProperty = projectType.GetMethod("GetEvaluatedProperty", new Type[] { typeof(string) }); + return (string)getProperty.Invoke(project, new object[] { propertyName }); + } + + public override void Load(string projectFileName) + { try { ! projectType.GetMethod("Load", new Type[] { typeof(string) }).Invoke(project, new object[] { projectFileName }); } ! catch (TargetInvocationException tie) { ! throw new WixException(VSErrors.CannotLoadProject(projectFileName, tie.InnerException.Message)); } + catch (Exception e) + { + throw new WixException(VSErrors.CannotLoadProject(projectFileName, e.Message)); + } + } + } ! private struct MSBuild40Types ! { ! public Type buildManagerType; ! public Type buildParametersType; ! public Type buildRequestDataFlagsType; ! public Type buildRequestDataType; ! public Type hostServicesType; ! public Type projectCollectionType; ! public Type projectInstanceType; ! } ! ! private class MSBuild40Project : MSBuildProject ! { ! private MSBuild40Types types; ! private object projectCollection; ! private object currentProjectInstance; ! private object buildManager; ! private object buildParameters; ! private HarvesterCore harvesterCore; ! ! public MSBuild40Project(object project, Type projectType, Type buildItemType, string loadVersion, MSBuild40Types types, HarvesterCore harvesterCore) ! : base(project, projectType, buildItemType, loadVersion) ! { ! this.types = types; ! this.harvesterCore = harvesterCore; ! ! this.buildParameters = this.types.buildParametersType.GetConstructor(new Type[] { }).Invoke(null); ! ! try ! { ! HarvestLogger logger = new HarvestLogger(); ! logger.HarvesterCore = harvesterCore; ! List<ILogger> loggers = new List<ILogger>(); ! loggers.Add(logger); ! ! // this.buildParameters.Loggers = loggers; ! this.types.buildParametersType.GetProperty("Loggers").SetValue(this.buildParameters, loggers, null); ! } ! catch (TargetInvocationException tie) ! { ! if (this.harvesterCore != null) ! { ! this.harvesterCore.OnMessage(VSWarnings.NoLogger(tie.InnerException.Message)); ! } ! } ! catch (Exception e) ! { ! if (this.harvesterCore != null) ! { ! this.harvesterCore.OnMessage(VSWarnings.NoLogger(e.Message)); ! } ! } ! ! this.buildManager = this.types.buildManagerType.GetConstructor(new Type[] { }).Invoke(null); ! this.projectCollection = this.types.projectCollectionType.GetConstructor(new Type[] { }).Invoke(null); } ! public override bool Build(string projectFileName, string[] targetNames, IDictionary targetOutputs) { ! try ! { ! // this.buildManager.BeginBuild(this.buildParameters); ! this.types.buildManagerType.GetMethod("BeginBuild", new Type[] { this.types.buildParametersType }).Invoke(this.buildManager, new object[] { this.buildParameters }); ! ! // buildRequestData = new BuildRequestData(this.currentProjectInstance, targetNames, null, BuildRequestData.BuildRequestDataFlags.ReplaceExistingProjectInstance); ! ConstructorInfo buildRequestDataCtor = this.types.buildRequestDataType.GetConstructor( ! new Type[] ! { ! this.types.projectInstanceType, typeof(string[]), this.types.hostServicesType, this.types.buildRequestDataFlagsType ! }); ! object buildRequestDataFlags = this.types.buildRequestDataFlagsType.GetField("ReplaceExistingProjectInstance").GetRawConstantValue(); ! object buildRequestData = buildRequestDataCtor.Invoke(new object[] { this.currentProjectInstance, targetNames, null, buildRequestDataFlags }); ! ! // BuildSubmission submission = this.buildManager.PendBuildRequest(buildRequestData); ! object submission = this.types.buildManagerType.GetMethod("PendBuildRequest", new Type[] { this.types.buildRequestDataType }) ! .Invoke(this.buildManager, new object[] { buildRequestData }); ! ! // BuildResult buildResult = submission.Execute(); ! object buildResult = submission.GetType().GetMethod("Execute", new Type[] { }).Invoke(submission, null); ! ! // bool buildSucceeded = buildResult.OverallResult == BuildResult.Success; ! object overallResult = buildResult.GetType().GetProperty("OverallResult").GetValue(buildResult, null); ! bool buildSucceeded = String.Equals(overallResult.ToString(), "Success", StringComparison.Ordinal); ! ! // this.buildManager.EndBuild(); ! this.types.buildManagerType.GetMethod("EndBuild", new Type[] { }).Invoke(this.buildManager, null); ! ! // fill in empty lists for each target so that heat will look at the item group later ! foreach (string target in targetNames) ! { ! targetOutputs.Add(target, new List<object>()); ! } ! ! return buildSucceeded; ! } ! catch (TargetInvocationException tie) ! { ! throw new WixException(VSErrors.CannotBuildProject(projectFileName, tie.InnerException.Message)); ! } ! catch (Exception e) ! { ! throw new WixException(VSErrors.CannotBuildProject(projectFileName, e.Message)); ! } } ! /// <summary> ! /// Gets the evaluated value of an instance of a ProjectItemInstance object. ! /// </summary> ! /// <param name="buildItem">The ProjectItemInstance object</param> ! /// <returns></returns> ! public override string GetBuildItemFinalItemSpec(object buildItem) { ! PropertyInfo includeProperty = this.buildItemType.GetProperty("EvaluatedInclude"); ! return (string)includeProperty.GetValue(buildItem, null); } ! public override IEnumerable GetEvaluatedItemsByName(string itemName) ! { ! MethodInfo getEvaluatedItem = this.types.projectInstanceType.GetMethod("GetItems", new Type[] { typeof(string) }); ! return (IEnumerable)getEvaluatedItem.Invoke(this.currentProjectInstance, new object[] { itemName }); ! } ! ! public override string GetEvaluatedProperty(string propertyName) ! { ! MethodInfo getProperty = this.types.projectInstanceType.GetMethod("GetPropertyValue", new Type[] { typeof(string) }); ! return (string)getProperty.Invoke(this.currentProjectInstance, new object[] { propertyName }); ! } ! ! public override void Load(string projectFileName) { try { ! //this.project = this.projectCollection.LoadProject(projectFileName); ! this.project = this.types.projectCollectionType.GetMethod("LoadProject", new Type[] { typeof(string) }).Invoke(this.projectCollection, new object[] { projectFileName }); ! ! // this.currentProjectInstance = this.project.CreateProjectInstance(); ! MethodInfo createProjectInstanceMethod = projectType.GetMethod("CreateProjectInstance", new Type[] { }); ! this.currentProjectInstance = createProjectInstanceMethod.Invoke(this.project, null); } catch (TargetInvocationException tie) *************** *** 1163,1166 **** --- 1445,1481 ---- } } + + // This logger will derive from the Microsoft.Build.Utilities.Logger class, + // which provides it with getters and setters for Verbosity and Parameters, + // and a default empty Shutdown() implementation. + internal class HarvestLogger : Logger + { + private HarvesterCore harvesterCore; + + public HarvesterCore HarvesterCore + { + get { return this.harvesterCore; } + set { this.harvesterCore = value; } + } + + /// <summary> + /// Initialize is guaranteed to be called by MSBuild at the start of the build + /// before any events are raised. + /// </summary> + public override void Initialize(IEventSource eventSource) + { + eventSource.ErrorRaised += new BuildErrorEventHandler(eventSource_ErrorRaised); + } + + void eventSource_ErrorRaised(object sender, BuildErrorEventArgs e) + { + if (this.harvesterCore != null) + { + // BuildErrorEventArgs adds LineNumber, ColumnNumber, File, amongst other parameters + string line = String.Format(CultureInfo.InvariantCulture, "{0}({1},{2}): {3}", e.File, e.LineNumber, e.ColumnNumber, e.Message); + this.harvesterCore.OnMessage(VSErrors.BuildErrorDuringHarvesting(line)); + } + } + } } } |