private static void LoadExtensions(SimplifiedCompiler compiler, Messaging messaging, ITaskItem[] extensions) { foreach (ITaskItem extension in extensions) { string className = extension.GetMetadata("Class"); string data = extension.GetMetadata("Data"); // First, try the HintPath. string resolvedPath = extension.GetMetadata("HintPath"); if (String.IsNullOrEmpty(resolvedPath) || !File.Exists(resolvedPath)) { // Try the item as a DLL. resolvedPath = extension.ItemSpec; if (Path.GetExtension(resolvedPath).Length == 0) { resolvedPath += ".dll"; } if (!File.Exists(resolvedPath)) { // Finally a file on disk wasn't found, so just set it to the extension name passed in. resolvedPath = extension.ItemSpec; } } try { string extensionName = resolvedPath; if (!String.IsNullOrEmpty(className)) { extensionName = String.Concat(className, ", ", extensionName); } // Load the extension and feed it its arguments if any were provided. CompilerExtension compilerExtension = CompilerExtension.Load(extensionName); compilerExtension.Messages += messaging.MessageDelegate; compilerExtension.Data = data; // If the compiler file manager hasn't been set yet, set it to the extension's file manager. if (compiler.FileManager == null) { compiler.FileManager = compilerExtension.FileManager; } compiler.AddExtension(compilerExtension); } catch (CompilerException e) { messaging.OnError(null, "{1}", e.Message); } } }
private static void LoadPackageSources(SimplifiedCompiler compiler, IEnumerable <ITaskItem> filePaths) { foreach (ITaskItem filePath in filePaths) { string fileExtension = Path.GetExtension(filePath.ItemSpec); if (String.Equals(".swx", fileExtension, StringComparison.OrdinalIgnoreCase) || String.Equals(".swr", fileExtension, StringComparison.OrdinalIgnoreCase)) { compiler.AddSourceFile(filePath.ItemSpec); } else { string group = filePath.GetMetadata("Group"); string targetPath = filePath.GetMetadata("TargetPath"); compiler.AddFile(group, filePath.ItemSpec, targetPath); } } }
private bool Run(Messaging messaging) { if (this.SourcePaths.Length == 0) { messaging.OnError(null, "No inputs specified. Specify at least one file."); } if (String.IsNullOrEmpty(this.Type)) { if (this.OutputPath == null) { messaging.OnError(this, "Package type cannot be inferred from output path. Explicitly specify PackageType in your MSBuild project or -type from the swc.exe command-line. Valid options are: appx, msi, vsix, or wixlib"); } else { this.Type = Path.GetExtension(this.OutputPath.ItemSpec); } } else if (this.OutputPath == null && this.SourcePaths.Length > 0) { string outputPath = Path.ChangeExtension(this.SourcePaths[0].ItemSpec, this.Type.ToLowerInvariant()); this.OutputPath = new FilePathTaskItem(outputPath); } PackageArchitecture architecture = PackageArchitecture.Unknown; if (String.IsNullOrEmpty(this.Architecture)) { messaging.OnError(this, "A package architecture must specified. Set the PackageArchitecture in your MSBuild project or -arch from the swc.exe command-line. Valid options are: arm, x64, x86 or neutral"); } else if (!SimplifiedWixCompiler.TryConvertPackageArchitecture(this.Architecture, out architecture)) { messaging.OnError(this, "Unknown architecture specified: {0}. Valid options are: arm, x64, x86 or neutral", this.Architecture); } List <CultureInfo> locales = new List <CultureInfo>(); if (this.Languages != null) { foreach (string language in this.Languages) { try { CultureInfo locale; int lcid = 0; if (Int32.TryParse(language, out lcid)) { locale = new CultureInfo(lcid); } else { locale = new CultureInfo(language); } locales.Add(locale); } catch (CultureNotFoundException) { messaging.OnError(this, "Unknown language: {0}", language); } } } PackageType type = PackageType.Unknown; if (String.IsNullOrEmpty(this.Type)) { messaging.OnError(this, "A package type must specified. Use the PackageType in your MSBuild project or -type from the swc.exe command-line. Valid options are: appx, msi, vsix or wixlib"); } else if (!SimplifiedWixCompiler.TryConvertPackageType(this.Type, out type)) { messaging.OnError(this, "Unknown package type specified: {0}. Valid options are: appx, msi, vsix or wixlib", this.Type); } if (type == PackageType.Appx && locales.Count == 0) { messaging.OnError(this, "AppX packages do not support language neutral packages. At least one language to be specified. Use the PackageLanguages property in your MSBuild project or -lang from the swc.exe command-line."); } if (!messaging.Errored) { SimplifiedCompiler compiler = new SimplifiedCompiler(); compiler.Messages += messaging.MessageDelegate; if (this.SearchPaths != null) { foreach (ITaskItem searchPath in this.SearchPaths) { compiler.SearchPaths.Add(searchPath.ItemSpec); } } if (this.PreprocessorDefines != null) { foreach (string define in this.PreprocessorDefines) { string[] defineSplit = define.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries); compiler.PreprocessorDefines.Add(defineSplit[0], defineSplit.Length > 1 ? defineSplit[1] : null); } } // Load the extensions. if (this.Extensions != null) { SimplifiedWixCompiler.LoadExtensions(compiler, messaging, this.Extensions); } // Finally, load the sources and compile! if (!messaging.Errored) { SimplifiedWixCompiler.LoadPackageSources(compiler, this.SourcePaths); compiler.Compile(type, architecture, locales.ToArray(), this.OutputPath.ItemSpec); } } return(!messaging.Errored); }