Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using Microsoft.Win32;
  6.  
  7. namespace InstallToVS
  8. {
  9. public class FileUnblocker
  10. {
  11. [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
  12. [return: MarshalAs(UnmanagedType.Bool)]
  13. private static extern bool DeleteFile(string name);
  14.  
  15. public bool Unblock(string fileName)
  16. {
  17. return DeleteFile(fileName + ":Zone.Identifier");
  18. }
  19. }
  20. class Program
  21. {
  22. private const string DllName1 = "TRUDUtilsD365.dll";
  23. private const string DllName2 = "TRUDUtilsD365.pdb";
  24. private const string AddinFolder = "AddinExtensions";
  25.  
  26. static void Main(string[] args)
  27. {
  28. try
  29. {
  30. FileUnblocker unblocker = new FileUnblocker();
  31. string extensionFolderName = FindExtensionFolder();
  32. Console.WriteLine($"VS extension folder: {extensionFolderName}");
  33. string sourcePath = Path.Combine(Environment.CurrentDirectory, DllName1);
  34. unblocker.Unblock(sourcePath);
  35. string targetPath = Path.Combine(extensionFolderName, DllName1);
  36. File.Copy(sourcePath, targetPath, true);
  37.  
  38. sourcePath = Path.Combine(Environment.CurrentDirectory, DllName2);
  39. unblocker.Unblock(sourcePath);
  40. targetPath = Path.Combine(extensionFolderName, DllName2);
  41. File.Copy(sourcePath, targetPath, true);
  42.  
  43. Console.WriteLine("Setup finished! Close and enjoy!");
  44.  
  45. }
  46. catch (Exception ee)
  47. {
  48. Console.Error.WriteLine(ee);
  49. Console.Error.WriteLine("Seems that an issue prevented me from doing my job :(");
  50. }
  51.  
  52. Console.ReadLine();
  53. }
  54. private static string FindExtensionFolder()
  55. {
  56. /*
  57. using (var extensionsRegKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\14.0\ExtensionManager\EnabledExtensions"))
  58. {
  59. string path = "";
  60. if (extensionsRegKey != null)
  61. {
  62. string axToolsKeyName = extensionsRegKey.GetValueNames()
  63. .FirstOrDefault(name => name.StartsWith("DynamicsRainierVSTools"));
  64. if (axToolsKeyName != null)
  65. {
  66. path = (string) extensionsRegKey.GetValue(axToolsKeyName);
  67. }
  68. }
  69. */
  70. string path = "";
  71. RegistryKey d365Key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\14.0_Config\AutomationProperties\Dynamics 365");
  72. if (d365Key != null)
  73. {
  74. string package = (string) d365Key.GetValue("Package");
  75.  
  76. RegistryKey pathKey =
  77. Registry.CurrentUser.OpenSubKey(
  78. $@"SOFTWARE\Microsoft\VisualStudio\14.0_Config\BindingPaths\{package}");
  79. if (pathKey != null)
  80. {
  81. path = pathKey.GetValueNames()[0];
  82. }
  83. }
  84.  
  85. if (string.IsNullOrEmpty(path))
  86. {
  87. throw new ApplicationException("Could not find D365FO tools in Windows registry.");
  88. }
  89. return Path.Combine(path, AddinFolder);
  90. //}
  91.  
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement