static void PackXllBuild(string xllFullPath, bool includePdb) { ResourceHelper.ResourceUpdater ru = new ResourceHelper.ResourceUpdater(xllFullPath); var xllDir = Path.GetDirectoryName(xllFullPath); ru.AddAssembly(Path.Combine(xllDir, "ExcelDna.Loader.dll"), compress: true, multithreading: false, includePdb); ru.AddAssembly(Path.Combine(xllDir, "ExcelDna.Integration.dll"), compress: true, multithreading: false, includePdb); ru.EndUpdate(); }
static void Main(string[] args) { // string testLib = @"C:\Work\ExcelDna\Version\ExcelDna-0.23\Source\ExcelDnaPack\bin\Debug\exceldna.xll"; // ResourceHelper.ResourceLister rl = new ResourceHelper.ResourceLister(testLib); // rl.ListAll(); // //ResourceHelper.ResourceUpdater.Test(testLib); // return; // Force jit-load of ExcelDna.Integration assembly int unused = XlCall.xlAbort; if (args.Length < 1) { Console.Write("No .dna file specified.\r\n\r\n" + usageInfo); return; } string dnaPath = args[0]; string dnaDirectory = Path.GetDirectoryName(dnaPath); // string dnaFileName = Path.GetFileName(dnaPath); string dnaFilePrefix = Path.GetFileNameWithoutExtension(dnaPath); string configPath = Path.ChangeExtension(dnaPath, ".xll.config"); string xllInputPath = Path.Combine(dnaDirectory, dnaFilePrefix + ".xll"); string xllOutputPath = Path.Combine(dnaDirectory, dnaFilePrefix + "-packed.xll"); bool overwrite = false; if (!File.Exists(dnaPath)) { Console.Write("Add-in .dna file " + dnaPath + " not found.\r\n\r\n" + usageInfo); return; } // TODO: Replace with an args-parsing routine. if (args.Length > 1) { for (int i = 1; i < args.Length; i++) { if (args[i].Equals("/O", StringComparison.CurrentCultureIgnoreCase)) { if (i >= args.Length - 1) { // Too few args. Console.Write("Invalid command-line arguments.\r\n\r\n" + usageInfo); return; } xllOutputPath = args[i + 1]; } else if (args[i].Equals("/Y", StringComparison.CurrentCultureIgnoreCase)) { overwrite = true; } } } if (File.Exists(xllOutputPath)) { if (overwrite == false) { Console.Write("Output .xll file " + xllOutputPath + " already exists. Overwrite? [Y/N] "); string response = Console.ReadLine(); if (!response.Equals("Y", StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine("\r\nNot overwriting existing file.\r\nExiting ExcelDnaPack."); return; } } try { File.Delete(xllOutputPath); } catch { Console.Write("Existing output .xll file " + xllOutputPath + "could not be deleted. (Perhaps loaded in Excel?)\r\n\r\nExiting ExcelDnaPack."); return; } } // Find ExcelDna.xll to use. // First try <MyAddin>.xll if (!File.Exists(xllInputPath)) { // CONSIDER: Maybe the next two (old) search locations should be deprecated? // Then try one called ExcelDna.xll next to the .dna file xllInputPath = Path.Combine(dnaDirectory, "ExcelDna.xll"); if (!File.Exists(xllInputPath)) { // Then try one called ExcelDna.xll next to the ExcelDnaPack.exe xllInputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExcelDna.xll"); if (!File.Exists(xllInputPath)) { Console.WriteLine("Base add-in not found.\r\n\r\n" + usageInfo); return; } } } Console.WriteLine("Using base add-in " + xllInputPath); File.Copy(xllInputPath, xllOutputPath, false); ResourceHelper.ResourceUpdater ru = new ResourceHelper.ResourceUpdater(xllOutputPath); // Take out Integration assembly - to be replaced by a compressed copy. // CONSIDER: Maybe use the ExcelDna.Integration that is inside the <MyAddin>.xll ru.RemoveResource("ASSEMBLY", "EXCELDNA.INTEGRATION"); string integrationPath = DnaLibrary.ResolvePath("ExcelDna.Integration.dll", dnaDirectory); string packedName = null; if (integrationPath != null) { packedName = ru.AddAssembly(integrationPath); } if (packedName == null) { Console.WriteLine("ExcelDna.Integration assembly could not be packed. Aborting."); ru.EndUpdate(); File.Delete(xllOutputPath); return; } if (File.Exists(configPath)) { ru.AddConfigFile(File.ReadAllBytes(configPath), "__MAIN__"); // Name here must exactly match name in ExcelDnaLoad.cpp. } byte[] dnaBytes = File.ReadAllBytes(dnaPath); byte[] dnaContentForPacking = PackDnaLibrary(dnaBytes, dnaDirectory, ru); ru.AddDnaFileUncompressed(dnaContentForPacking, "__MAIN__"); // Name here must exactly match name in DnaLibrary.Initialize. ru.EndUpdate(); Console.WriteLine("Completed Packing {0}.", xllOutputPath); #if DEBUG Console.WriteLine("Press any key to exit."); Console.ReadKey(); #endif }
private static int Pack(string[] args) { // string testLib = @"C:\Work\ExcelDna\Version\ExcelDna-0.23\Source\ExcelDnaPack\bin\Debug\exceldna.xll"; // ResourceHelper.ResourceLister rl = new ResourceHelper.ResourceLister(testLib); // rl.ListAll(); // //ResourceHelper.ResourceUpdater.Test(testLib); // return; // Force jit-load of ExcelDna.Integration assembly int unused = XlCall.xlAbort; if (args.Length < 1) { Console.Write("No .dna file specified.\r\n\r\n" + usageInfo); return(1); } // Special path when we're building ExcelDna, to pack Loader and Integration if (args[0] == "PackXllBuild") { string xllFullPath = args[1]; bool includePdb = (args[2] == "Debug"); PackXllBuild(xllFullPath, includePdb); return(0); } string dnaPath = Path.GetFullPath(args[0]); string dnaDirectory = Path.GetDirectoryName(dnaPath); // string dnaFileName = Path.GetFileName(dnaPath); string dnaFilePrefix = Path.GetFileNameWithoutExtension(dnaPath); string configPath = Path.ChangeExtension(dnaPath, ".xll.config"); string xllInputPath = Path.Combine(dnaDirectory, dnaFilePrefix + ".xll"); string xllOutputPath = Path.Combine(dnaDirectory, dnaFilePrefix + "-packed.xll"); bool overwrite = false; bool compress = true; bool multithreading = true; if (!File.Exists(dnaPath)) { Console.Error.Write("ERROR: Add-in .dna file " + dnaPath + " not found.\r\n\r\n" + usageInfo); return(1); } // TODO: Replace with an args-parsing routine. if (args.Length > 1) { for (int i = 1; i < args.Length; i++) { if (args[i].Equals("/O", StringComparison.CurrentCultureIgnoreCase)) { if (i >= args.Length - 1) { // Too few args. Console.Write("Invalid command-line arguments.\r\n\r\n" + usageInfo); return(1); } xllOutputPath = args[i + 1]; } else if (args[i].Equals("/Y", StringComparison.CurrentCultureIgnoreCase)) { overwrite = true; } else if (args[i].Equals("/NoCompression", StringComparison.CurrentCultureIgnoreCase)) { compress = false; } else if (args[i].Equals("/NoMultiThreading", StringComparison.CurrentCultureIgnoreCase)) { multithreading = false; } } } if (File.Exists(xllOutputPath)) { if (overwrite == false) { Console.Write("Output .xll file " + xllOutputPath + " already exists. Overwrite? [Y/N] "); string response = Console.ReadLine(); if (!response.Equals("Y", StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine("\r\nNot overwriting existing file.\r\nExiting ExcelDnaPack."); return(1); } } try { File.Delete(xllOutputPath); } catch { Console.Error.Write("ERROR: Existing output .xll file " + xllOutputPath + "could not be deleted. (Perhaps loaded in Excel?)\r\n\r\nExiting ExcelDnaPack."); return(1); } } string outputDirectory = Path.GetDirectoryName(xllOutputPath); if (outputDirectory == String.Empty) { outputDirectory = "."; // https://github.com/Excel-DNA/ExcelDna/issues/7 } if (!Directory.Exists(outputDirectory)) { try { Directory.CreateDirectory(outputDirectory); } catch (Exception ex) { Console.Error.Write("ERROR: Output directory " + outputDirectory + "could not be created. Error: " + ex.Message + "\r\n\r\nExiting ExcelDnaPack."); return(1); } } // Find ExcelDna.xll to use. // First try <MyAddin>.xll if (!File.Exists(xllInputPath)) { // CONSIDER: Maybe the next two (old) search locations should be deprecated? // Then try one called ExcelDna.xll next to the .dna file xllInputPath = Path.Combine(dnaDirectory, "ExcelDna.xll"); if (!File.Exists(xllInputPath)) { // Then try one called ExcelDna.xll next to the ExcelDnaPack.exe xllInputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExcelDna.xll"); if (!File.Exists(xllInputPath)) { Console.Error.WriteLine("ERROR: Base add-in not found.\r\n\r\n" + usageInfo); return(1); } } } Console.WriteLine("Using base add-in " + xllInputPath); File.Copy(xllInputPath, xllOutputPath, false); ResourceHelper.ResourceUpdater ru = new ResourceHelper.ResourceUpdater(xllOutputPath); if (File.Exists(configPath)) { ru.AddFile(File.ReadAllBytes(configPath), "__MAIN__", ResourceHelper.TypeName.CONFIG, false, multithreading); // Name here must exactly match name in ExcelDnaLoad.cpp. } byte[] dnaBytes = File.ReadAllBytes(dnaPath); byte[] dnaContentForPacking = PackDnaLibrary(dnaBytes, dnaDirectory, ru, compress, multithreading); ru.AddFile(dnaContentForPacking, "__MAIN__", ResourceHelper.TypeName.DNA, false, multithreading); // Name here must exactly match name in DnaLibrary.Initialize. ru.EndUpdate(); Console.WriteLine("Completed Packing {0}.", xllOutputPath); #if DEBUG Console.WriteLine("Press any key to exit."); try { Console.ReadKey(); } catch (InvalidOperationException) // Exception when running pack when building in Visual Studio. { } #endif // All OK - set process exit code to 'Success' return(0); }
static void Main(string[] args) { // string testLib = @"C:\Work\ExcelDna\Version\ExcelDna-0.23\Source\ExcelDnaPack\bin\Debug\exceldna.xll"; // ResourceHelper.ResourceLister rl = new ResourceHelper.ResourceLister(testLib); // rl.ListAll(); // //ResourceHelper.ResourceUpdater.Test(testLib); // return; // Set to an 'Error' exit unless we get to the end. Environment.ExitCode = -1; // Force jit-load of ExcelDna.Integration assembly int unused = XlCall.xlAbort; if (args.Length < 1) { Console.Write("No .dna file specified.\r\n\r\n" + usageInfo); return; } string dnaPath = args[0]; string dnaDirectory = Path.GetDirectoryName(dnaPath); // string dnaFileName = Path.GetFileName(dnaPath); string dnaFilePrefix = Path.GetFileNameWithoutExtension(dnaPath); string configPath = Path.ChangeExtension(dnaPath, ".xll.config"); string xllInputPath = Path.Combine(dnaDirectory, dnaFilePrefix + ".xll"); string xllOutputPath = Path.Combine(dnaDirectory, dnaFilePrefix + "-packed.xll"); bool overwrite = false; if (!File.Exists(dnaPath)) { Console.Write("Add-in .dna file " + dnaPath + " not found.\r\n\r\n" + usageInfo); return; } // TODO: Replace with an args-parsing routine. if (args.Length > 1) { for (int i = 1; i < args.Length; i++) { if (args[i].Equals("/O", StringComparison.CurrentCultureIgnoreCase)) { if (i >= args.Length - 1) { // Too few args. Console.Write("Invalid command-line arguments.\r\n\r\n" + usageInfo); return; } xllOutputPath = args[i + 1]; } else if (args[i].Equals("/Y", StringComparison.CurrentCultureIgnoreCase)) { overwrite = true; } } } if (File.Exists(xllOutputPath)) { if (overwrite == false) { Console.Write("Output .xll file " + xllOutputPath + " already exists. Overwrite? [Y/N] "); string response = Console.ReadLine(); if (!response.Equals("Y", StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine("\r\nNot overwriting existing file.\r\nExiting ExcelDnaPack."); return; } } try { File.Delete(xllOutputPath); } catch { Console.Write("Existing output .xll file " + xllOutputPath + "could not be deleted. (Perhaps loaded in Excel?)\r\n\r\nExiting ExcelDnaPack."); return; } } string outputDirectory = Path.GetDirectoryName(xllOutputPath); if (outputDirectory == String.Empty) { outputDirectory = "."; // https://github.com/Excel-DNA/ExcelDna/issues/7 } if (!Directory.Exists(outputDirectory)) { try { Directory.CreateDirectory(outputDirectory); } catch (Exception ex) { Console.Write("Output directory " + outputDirectory + "could not be created. Error: " + ex.Message + "\r\n\r\nExiting ExcelDnaPack."); return; } } // Find ExcelDna.xll to use. // First try <MyAddin>.xll if (!File.Exists(xllInputPath)) { // CONSIDER: Maybe the next two (old) search locations should be deprecated? // Then try one called ExcelDna.xll next to the .dna file xllInputPath = Path.Combine(dnaDirectory, "ExcelDna.xll"); if (!File.Exists(xllInputPath)) { // Then try one called ExcelDna.xll next to the ExcelDnaPack.exe xllInputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExcelDna.xll"); if (!File.Exists(xllInputPath)) { Console.WriteLine("Base add-in not found.\r\n\r\n" + usageInfo); return; } } } Console.WriteLine("Using base add-in " + xllInputPath); File.Copy(xllInputPath, xllOutputPath, false); ResourceHelper.ResourceUpdater ru = new ResourceHelper.ResourceUpdater(xllOutputPath); // Take out Integration assembly - to be replaced by a compressed copy. // CONSIDER: Maybe use the ExcelDna.Integration that is inside the <MyAddin>.xll ru.RemoveResource("ASSEMBLY", "EXCELDNA.INTEGRATION"); string integrationPath = DnaLibrary.ResolvePath("ExcelDna.Integration.dll", dnaDirectory); string packedName = null; if (integrationPath != null) { packedName = ru.AddAssembly(integrationPath); } if (packedName == null) { Console.WriteLine("ExcelDna.Integration assembly could not be packed. Aborting."); ru.EndUpdate(); File.Delete(xllOutputPath); return; } if (File.Exists(configPath)) { ru.AddConfigFile(File.ReadAllBytes(configPath), "__MAIN__"); // Name here must exactly match name in ExcelDnaLoad.cpp. } byte[] dnaBytes = File.ReadAllBytes(dnaPath); byte[] dnaContentForPacking = PackDnaLibrary(dnaBytes, dnaDirectory, ru); ru.AddDnaFileUncompressed(dnaContentForPacking, "__MAIN__"); // Name here must exactly match name in DnaLibrary.Initialize. ru.EndUpdate(); Console.WriteLine("Completed Packing {0}.", xllOutputPath); #if DEBUG Console.WriteLine("Press any key to exit."); Console.ReadKey(); #endif // All OK - set process exit code to 'Success' Environment.ExitCode = 0; }
static void Pack(string[] args) { // string testLib = @"C:\Work\ExcelDna\Version\ExcelDna-0.23\Source\ExcelDnaPack\bin\Debug\exceldna.xll"; // ResourceHelper.ResourceLister rl = new ResourceHelper.ResourceLister(testLib); // rl.ListAll(); // //ResourceHelper.ResourceUpdater.Test(testLib); // return; // Set to an 'Error' exit unless we get to the end. Environment.ExitCode = 1; // Force jit-load of ExcelDna.Integration assembly int unused = XlCall.xlAbort; if (args.Length < 1) { Console.Write("No .dna file specified.\r\n\r\n" + usageInfo); return; } string dnaPath = args[0]; string dnaDirectory = Path.GetDirectoryName(dnaPath); // string dnaFileName = Path.GetFileName(dnaPath); string dnaFilePrefix = Path.GetFileNameWithoutExtension(dnaPath); string configPath = Path.ChangeExtension(dnaPath, ".xll.config"); string xllInputPath = Path.Combine(dnaDirectory, dnaFilePrefix + ".xll"); string xllOutputPath = Path.Combine(dnaDirectory, dnaFilePrefix + "-packed.xll"); bool overwrite = false; bool compress = true; bool multithreading = true; if (!File.Exists(dnaPath)) { Console.Write("ERROR: Add-in .dna file " + dnaPath + " not found.\r\n\r\n" + usageInfo); return; } // TODO: Replace with an args-parsing routine. if (args.Length > 1) { for (int i = 1; i < args.Length; i++) { if (args[i].Equals("/O", StringComparison.CurrentCultureIgnoreCase)) { if (i >= args.Length - 1) { // Too few args. Console.Write("Invalid command-line arguments.\r\n\r\n" + usageInfo); return; } xllOutputPath = args[i + 1]; } else if (args[i].Equals("/Y", StringComparison.CurrentCultureIgnoreCase)) { overwrite = true; } else if (args[i].Equals("/NoCompression", StringComparison.CurrentCultureIgnoreCase)) { compress = false; } else if (args[i].Equals("/NoMultiThreading", StringComparison.CurrentCultureIgnoreCase)) { multithreading = false; } } } if (File.Exists(xllOutputPath)) { if (overwrite == false) { Console.Write("Output .xll file " + xllOutputPath + " already exists. Overwrite? [Y/N] "); string response = Console.ReadLine(); if (!response.Equals("Y", StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine("\r\nNot overwriting existing file.\r\nExiting ExcelDnaPack."); return; } } try { File.Delete(xllOutputPath); } catch { Console.Write("ERROR: Existing output .xll file " + xllOutputPath + "could not be deleted. (Perhaps loaded in Excel?)\r\n\r\nExiting ExcelDnaPack."); return; } } string outputDirectory = Path.GetDirectoryName(xllOutputPath); if (outputDirectory == String.Empty) { outputDirectory = "."; // https://github.com/Excel-DNA/ExcelDna/issues/7 } if (!Directory.Exists(outputDirectory)) { try { Directory.CreateDirectory(outputDirectory); } catch (Exception ex) { Console.Write("ERROR: Output directory " + outputDirectory + "could not be created. Error: " + ex.Message + "\r\n\r\nExiting ExcelDnaPack."); return; } } // Find ExcelDna.xll to use. // First try <MyAddin>.xll if (!File.Exists(xllInputPath)) { // CONSIDER: Maybe the next two (old) search locations should be deprecated? // Then try one called ExcelDna.xll next to the .dna file xllInputPath = Path.Combine(dnaDirectory, "ExcelDna.xll"); if (!File.Exists(xllInputPath)) { // Then try one called ExcelDna.xll next to the ExcelDnaPack.exe xllInputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExcelDna.xll"); if (!File.Exists(xllInputPath)) { Console.WriteLine("ERROR: Base add-in not found.\r\n\r\n" + usageInfo); return; } } } Console.WriteLine("Using base add-in " + xllInputPath); File.Copy(xllInputPath, xllOutputPath, false); ResourceHelper.ResourceUpdater ru = new ResourceHelper.ResourceUpdater(xllOutputPath); // Take out Integration assembly - to be replaced by a compressed copy. // CONSIDER: Maybe use the ExcelDna.Integration that is inside the <MyAddin>.xll ru.RemoveResource("ASSEMBLY", "EXCELDNA.INTEGRATION"); string integrationPath = DnaLibrary.ResolvePath("ExcelDna.Integration.dll", dnaDirectory); string packedName = null; if (integrationPath != null) { // pdb is not in the nuget package, so chances are we want it if it is present (ExcelDna dev)// pdb is not in the nuget package, so chances are we want it if it is present (ExcelDna dev) // pdb is not in the nuget package, so chances are we want it if it is present (ExcelDna dev)// pdb is not in the nuget package, so chances are we want it if it is present (ExcelDna dev) packedName = ru.AddAssembly(integrationPath, compress, multithreading, true); } if (packedName == null) { Console.WriteLine("ERROR: ExcelDna.Integration assembly could not be packed. ABORTING."); ru.EndUpdate(); File.Delete(xllOutputPath); return; } if (File.Exists(configPath)) { ru.AddFile(File.ReadAllBytes(configPath), "__MAIN__", ResourceHelper.TypeName.CONFIG, false, multithreading); // Name here must exactly match name in ExcelDnaLoad.cpp. } byte[] dnaBytes = File.ReadAllBytes(dnaPath); byte[] dnaContentForPacking = PackDnaLibrary(dnaBytes, dnaDirectory, ru, compress, multithreading); ru.AddFile(dnaContentForPacking, "__MAIN__", ResourceHelper.TypeName.DNA, false, multithreading); // Name here must exactly match name in DnaLibrary.Initialize. ru.EndUpdate(); Console.WriteLine("Completed Packing {0}.", xllOutputPath); #if DEBUG Console.WriteLine("Press any key to exit."); Console.ReadKey(); #endif // All OK - set process exit code to 'Success' Environment.ExitCode = 0; }