public override bool Execute() { var prefixes = BundleResource.SplitResourcePrefixes(ResourcePrefix); var intermediate = Path.Combine(IntermediateOutputPath, ToolName); var bundleResources = new List <ITaskItem> (); foreach (var input in EnumerateInputs()) { var relative = GetBundleRelativeOutputPath(prefixes, input); ITaskItem output; if (!string.IsNullOrEmpty(relative)) { string illegal; if (BundleResource.IsIllegalName(relative, out illegal)) { Log.LogError(null, null, null, input.ItemSpec, 0, 0, 0, 0, "The name '{0}' is reserved and cannot be used.", illegal); continue; } var rpath = Path.Combine(intermediate, relative); output = new TaskItem(rpath); } else { output = new TaskItem(intermediate); } output.SetMetadata("LogicalName", relative); if (NeedsBuilding(input, output)) { Directory.CreateDirectory(Path.GetDirectoryName(output.ItemSpec)); if (ExecuteTool(input, output) == -1) { return(false); } } bundleResources.AddRange(GetCompiledBundleResources(input, output)); } BundleResources = bundleResources.ToArray(); return(!Log.HasLoggedErrors); }
public override bool Execute() { var prefixes = BundleResource.SplitResourcePrefixes(ResourcePrefix); var bundleResources = new List <ITaskItem> (); if (BundleResources != null) { foreach (var item in BundleResources) { var logicalName = BundleResource.GetLogicalName(ProjectDir, prefixes, item, !string.IsNullOrEmpty(SessionId)); // We need a physical path here, ignore the Link element var path = item.GetMetadata("FullPath"); string illegal; if (!File.Exists(path)) { Log.LogError(" Bundle Resource '{0}' not found on disk (should be at '{1}')", logicalName, path); continue; } if (logicalName.StartsWith(".." + Path.DirectorySeparatorChar, StringComparison.Ordinal)) { Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, "The path '{0}' would result in a file outside of the app bundle and cannot be used.", logicalName); continue; } if (logicalName == "Info.plist") { Log.LogWarning(null, null, null, item.ItemSpec, 0, 0, 0, 0, "Info.plist files should have a Build Action of 'None'."); continue; } if (BundleResource.IsIllegalName(logicalName, out illegal)) { Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, "The name '{0}' is reserved and cannot be used.", illegal); continue; } var bundleResource = new TaskItem(item); bundleResource.SetMetadata("LogicalName", logicalName); bool optimize = false; if (CanOptimize(item.ItemSpec)) { var metadata = item.GetMetadata("Optimize"); // fall back to old metadata name if (string.IsNullOrEmpty(metadata)) { metadata = item.GetMetadata("OptimizeImage"); } if (string.IsNullOrEmpty(metadata) || !bool.TryParse(metadata, out optimize)) { switch (Path.GetExtension(item.ItemSpec).ToLowerInvariant()) { case ".plist": case ".strings": optimize = OptimizePropertyLists; break; case ".png": optimize = OptimizePNGs; break; } } } bundleResource.SetMetadata("Optimize", optimize.ToString()); bundleResources.Add(bundleResource); } } BundleResourcesWithLogicalNames = bundleResources.ToArray(); return(!Log.HasLoggedErrors); }
public override bool Execute() { var prefixes = BundleResource.SplitResourcePrefixes(ResourcePrefix); var bundleResources = new List <ITaskItem> (); if (BundleResources != null) { foreach (var item in BundleResources) { // Skip anything with the PublishFolderType metadata, these are copied directly to the ResolvedFileToPublish item group instead. var publishFolderType = item.GetMetadata("PublishFolderType"); if (!string.IsNullOrEmpty(publishFolderType)) { continue; } var logicalName = BundleResource.GetLogicalName(ProjectDir, prefixes, item, !string.IsNullOrEmpty(SessionId)); // We need a physical path here, ignore the Link element var path = item.GetMetadata("FullPath"); string illegal; if (!File.Exists(path)) { Log.LogError(MSBStrings.E0099, logicalName, path); continue; } if (logicalName.StartsWith(".." + Path.DirectorySeparatorChar, StringComparison.Ordinal)) { Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0100, logicalName); continue; } if (logicalName == "Info.plist") { Log.LogWarning(null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0101); continue; } if (BundleResource.IsIllegalName(logicalName, out illegal)) { Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0102, illegal); continue; } var bundleResource = new TaskItem(item); bundleResource.SetMetadata("LogicalName", logicalName); bool optimize = false; if (CanOptimize(item.ItemSpec)) { var metadata = item.GetMetadata("Optimize"); // fall back to old metadata name if (string.IsNullOrEmpty(metadata)) { metadata = item.GetMetadata("OptimizeImage"); } if (string.IsNullOrEmpty(metadata) || !bool.TryParse(metadata, out optimize)) { switch (Path.GetExtension(item.ItemSpec).ToLowerInvariant()) { case ".plist": case ".strings": optimize = OptimizePropertyLists; break; case ".png": optimize = OptimizePNGs; break; } } } bundleResource.SetMetadata("Optimize", optimize.ToString()); bundleResources.Add(bundleResource); } } BundleResourcesWithLogicalNames = bundleResources.ToArray(); return(!Log.HasLoggedErrors); }