code_junkie

Debugging C# Custom Installer Classes

Nov 12th, 2011
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. System.Diagnostics.Debugger.Break()
  2.  
  3. [TestClass] public class InstallerTest {
  4. [TestMethod]
  5. public void InstallTest() {
  6. // substitute with your installer component here
  7. DataWarehouseInstall installer = new DataWarehouseInstall();
  8.  
  9. string assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  10.  
  11. string installLogFilePath = Path.Combine(assemblyDirectory, "install.log");
  12. installer.Context = new System.Configuration.Install.InstallContext(installLogFilePath, null);
  13.  
  14. // Refactor to set any parameters for your installer here
  15. installer.Context.Parameters.Add("Server", ".");
  16. //installer.Context.Parameters.Add("User", "");
  17. //installer.Context.Parameters.Add("Password", "");
  18. installer.Context.Parameters.Add("DatabaseName", "MyDatabaseInstallMsiTest");
  19. //installer.Context.Parameters.Add("DatabasePath", "");
  20.  
  21. // Our test isn't injecting any save state so we give a default instance for the stateSaver
  22. installer.Install(new Hashtable());
  23. } }
  24.  
  25. using System;
  26. using System.Collections.Generic;
  27. using System.Linq;
  28. using System.Text;
  29. using System.IO;
  30.  
  31. namespace MyCompany.Deployment
  32. {
  33. /// <summary>
  34. /// Enables a quick and easy method of debugging custom actions.
  35. /// </summary>
  36. class LogFile
  37. {
  38. const string FileName = "MyCompany.Deployment.log";
  39. readonly string _filePath;
  40.  
  41. public LogFile(string primaryOutputPath)
  42. {
  43. var dir = Path.GetDirectoryName(primaryOutputPath);
  44. _filePath = Path.Combine(dir, FileName);
  45. }
  46.  
  47. public void Print(Exception ex)
  48. {
  49. File.AppendAllText(_filePath, "Error: " + ex.Message + Environment.NewLine +
  50. "Stack Trace: " + Environment.NewLine + ex.StackTrace + Environment.NewLine);
  51. }
  52.  
  53. public void Print(string format, params object[] args)
  54. {
  55. var text = String.Format(format, args) + Environment.NewLine;
  56.  
  57. File.AppendAllText(_filePath, text);
  58. }
  59.  
  60. public void PrintLine() { Print(""); }
  61. }
  62. }
  63.  
  64. Context.LogMessage("My message");
Add Comment
Please, Sign In to add comment