private void OnStartupComplete() { try { Log.Write("OnStartupComplete"); _dteEvents.OnStartupComplete -= OnStartupComplete; _dteEvents = null; PackageConfigurator.RemoveBridgeBuildTargetFromMicrosoftCommon(MicrosoftCommonTargetDocument, Locations.MicrosoftCommonTargetFileNamePath); Log.Write("BridgeBuild.targets Removed for x86 Operating System"); if (Environment.Is64BitOperatingSystem) { PackageConfigurator.RemoveBridgeBuildTargetFromMicrosoftCommon(MicrosoftCommonTargetX64Document, Locations.MicrosoftCommonTargetX64FileNamePath); Log.Write("BridgeBuild.targets Removed for x64 Operating System"); } if (PackageConfigurator.IsFramework45Installed) { PackageConfigurator.RemoveBridgeBuildTargetFromMicrosoftCommon(MicrosoftCommonTarget45Document, Locations.MicrosoftCommonTarget45FileNamePath); Log.Write("BridgeBuild.targets Removed for framework 4.5"); } PackageConfigurator.IsLinqBridgeEnabled = true; Log.Write("OnStartupComplete End"); } catch (Exception e) { Log.Write(e, "OnStartupComplete Error..."); } }
public static void ActivateBridgeVsOnSolution(CommandAction action, List <Project> projects, string solutionName, string vsVersion, string vsEdition) { //enable each individual project by mapping the assembly name and location to a registry entry foreach (Project project in projects) { string path = project.Properties.Item("FullPath").Value.ToString(); string outputPath = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString(); string fileName = project.Properties.Item("OutputFileName").Value.ToString(); string projectOutputPath = Path.Combine(path, outputPath, fileName); string assemblyName = project.Properties.Item("AssemblyName").Value.ToString(); ExecuteParams executeParams = new ExecuteParams(action, project.FullName, solutionName, assemblyName, projectOutputPath, vsVersion, vsEdition); Execute(executeParams); } //now create a general solution flag to mark the current solution as activated string keyPath = string.Format(PackageConfigurator.GetRegistryKey(EnabledProjectsRegistryKey, vsVersion, solutionName)); using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyPath, true)) { key?.SetValue(SolutionEnabled, action == CommandAction.Enable ? "True" : "False", RegistryValueKind.String); } string result = action == CommandAction.Enable ? "Bridged" : "Un-Bridged"; string userAction = action == CommandAction.Enable ? "Please rebuild your solution." : string.Empty; string message = $@"Solution {solutionName} has been {result}. {userAction}"; MessageBox.Show(message); }
public LINQBridgeVsExtension(DTE app) { Log.Configure("LINQBridgeVs", "LINQBridgeVsExtension"); _application = app; PackageConfigurator.Configure(_application.Version); }
public void Execute(CommandAction action) { if (SelectedProject == null) { return; } var allProjectReferences = Crawler.FindProjectDependencies(SelectedProject.FullName, SolutionName); var foundProjects = allProjectReferences as IList <Dependency.Project> ?? allProjectReferences.ToList(); var projectReferences = foundProjects.Where(project => project.DependencyType == DependencyType.ProjectReference); // var assemblyReferences = allProjectReferences.Where(project => project.DependencyType == DependencyType.AssemblyReference); var references = projectReferences as IList <Dependency.Project> ?? projectReferences.ToList(); switch (action) { case CommandAction.Enable: const string enableMessage = "Following project dependencies have been found...LINQBridge them? (Recommended)"; PackageConfigurator.EnableProject(SelectedProjectOutputPath, SelectedAssemblyName, SolutionName); var enabledDependencies = new List <string>(); enabledDependencies.Insert(0, SelectedAssemblyName); if (references.Any(project => PackageConfigurator.IsBridgeDisabled(project.AssemblyName, SolutionName))) { var projectDependencies = new ProjectDependencies(references, enableMessage); var dependencies = projectDependencies.ShowDependencies(PackageConfigurator.EnableProject); enabledDependencies.AddRange(dependencies.Select(project => project.AssemblyName)); } MessageBox.Show(string.Format("LINQBridge on {0} has been Enabled...", string.Join(", ", enabledDependencies)), "Success", MessageBoxButtons.OK); break; case CommandAction.Disable: const string disableMessage = "Following project dependencies have been found...Un-LINQBridge them? (Recommended)"; PackageConfigurator.DisableProject(SelectedProjectOutputPath, SelectedAssemblyName, SolutionName); var disableDependencies = new List <string>(); disableDependencies.Insert(0, SelectedAssemblyName); if (references.Any(project => PackageConfigurator.IsBridgeEnabled(project.AssemblyName, SolutionName))) { var projectDependencies = new ProjectDependencies(references, disableMessage); var dependencies = projectDependencies.ShowDependencies(PackageConfigurator.DisableProject); disableDependencies.AddRange(dependencies.Select(project => project.AssemblyName)); } MessageBox.Show(string.Format("LINQBridge on {0} has been Disabled...", string.Join(", ", disableDependencies)), "Success", MessageBoxButtons.OK); break; default: throw new ArgumentOutOfRangeException("action"); } }
private static void DisableProject(string assemblyName, string solutionName, string vsVersion) { string keyPath = string.Format(PackageConfigurator.GetRegistryKey(EnabledProjectsRegistryKey, vsVersion, solutionName)); using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyPath, true)) { key?.DeleteValue(assemblyName, false); key?.DeleteValue($"{assemblyName}_location", false); } }
private static void EnableProject(string assemblyPath, string assemblyName, string solutionName, string vsVersion) { string keyPath = string.Format(PackageConfigurator.GetRegistryKey(EnabledProjectsRegistryKey, vsVersion, solutionName)); using (RegistryKey key = Registry.CurrentUser.CreateSubKey(keyPath)) { key?.SetValue($"{assemblyName}", "True", RegistryValueKind.String); key?.SetValue($"{assemblyName}_location", Path.GetFullPath(assemblyPath), RegistryValueKind.String); } }
public static void ActivateBridgeVsOnSolution(CommandAction action, List <Project> projects, string solutionName, string vsVersion, string vsEdition, string solutionFolder) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); List <BridgeProjectInfo> executeParams = new List <BridgeProjectInfo>(); //enable each individual project by mapping the assembly name and location to a registry entry foreach (Project project in projects) { string path = project.Properties.Item("FullPath").Value.ToString(); string outputPath = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value .ToString(); string fileName = project.Properties.Item("OutputFileName").Value.ToString(); string projectOutputPath = Path.Combine(path, outputPath, fileName); string assemblyName = project.Properties.Item("AssemblyName").Value.ToString(); IEnumerable <string> references = Enumerable.Empty <string>(); if (project.Object is VSProject vsProject && vsProject.References != null) { references = from Reference reference in vsProject.References where reference.Path != null where reference.SourceProject == null //it means it's an assembly reference where !reference.Path.Contains(".NETFramework") && !reference.Path.Contains("Microsoft") //no .net framework assembly select reference.Path; } executeParams.Add(new BridgeProjectInfo(project.FullName, solutionName, assemblyName, projectOutputPath, vsVersion, vsEdition, references.ToList())); } switch (action) { case CommandAction.Enable: CommonRegistryConfigurations.BridgeSolution(solutionName, vsVersion, executeParams); //copy directory build target to the solution folder string target = PackageConfigurator.GetInstallationFolder(vsVersion); File.Copy(Path.Combine(target, "Targets", DirectoryBuildTargets), Path.Combine(solutionFolder, DirectoryBuildTargets), true); break; case CommandAction.Disable: CommonRegistryConfigurations.UnBridgeSolution(solutionName, vsVersion); //delete directory build target File.Delete(Path.Combine(solutionFolder, DirectoryBuildTargets)); break; } string result = action == CommandAction.Enable ? "Bridged" : "Un-Bridged"; string userAction = action == CommandAction.Enable ? "Please rebuild your solution." : string.Empty; string message = $@"Solution {solutionName} has been {result}. {userAction}"; MessageBox.Show(message); }
public static bool IsSolutionEnabled(string solutionName, string vsVersion) { string keyPath = string.Format(PackageConfigurator.GetRegistryKey(EnabledProjectsRegistryKey, vsVersion, solutionName)); using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyPath, false)) { if (key == null) { return(false); } string value = (string)key.GetValue(SolutionEnabled); return(value != null && Convert.ToBoolean(value)); } }
private CommandStates GetStatus(CommandAction action) { CommandStates result = CommandStates.Visible; bool isBridgeVsConfigured = PackageConfigurator.IsBridgeVsConfigured(_application.Version); if (!isBridgeVsConfigured) { return(result); //just show it as visible } bool isSolutionEnabled = BridgeCommand.IsSolutionEnabled(SolutionName, _application.Version); if (isSolutionEnabled && action == CommandAction.Disable || !isSolutionEnabled && action == CommandAction.Enable) { result |= CommandStates.Enabled; } return(result); }
private int GetMultiStatus() { var result = 0; if (SelectedProject == null) { return(result); } if (PackageConfigurator.IsBridgeDisabled(SelectedAssemblyName, SolutionName)) { result |= 1; } if (PackageConfigurator.IsBridgeEnabled(SelectedAssemblyName, SolutionName)) { result |= 2; } return(result); }
private CommandStates GetStatus(CommandAction action) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); CommandStates result = CommandStates.Visible; bool isBridgeVsConfigured = PackageConfigurator.IsBridgeVsConfigured(_application.Version); if (!isBridgeVsConfigured) { return(result); //just show it as visible } string solutionDir = Path.GetDirectoryName(_application.Solution.FileName); string directoryTarget = Path.Combine(solutionDir, "Directory.Build.targets"); bool isSolutionEnabled = File.Exists(directoryTarget); if (isSolutionEnabled && action == CommandAction.Disable || !isSolutionEnabled && action == CommandAction.Enable) { result |= CommandStates.Enabled; } return(result); }
/// <inheritdoc /> /// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { base.Initialize(); _dte = (DTE)GetService(typeof(SDTE)); _dteEvents = _dte.Events.DTEEvents; _dteEvents.OnStartupComplete += _dteEvents_OnStartupComplete; BridgeVsExtension bridge = new BridgeVsExtension(_dte); bool isLinqBridgeVsConfigured = PackageConfigurator.IsBridgeVsConfigured(_dte.Version); // Add our command handlers for menu(commands must exist in the.vsct file) OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null == mcs) { return; } // Create the command for the menu item. CommandID enableCommand = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdEnableBridge); OleMenuCommand menuItemEnable = new OleMenuCommand((s, e) => bridge.Execute(CommandAction.Enable), enableCommand); menuItemEnable.BeforeQueryStatus += (s, e) => bridge.UpdateCommand(menuItemEnable, CommandAction.Enable); CommandID disableCommand = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdDisableBridge); OleMenuCommand menuItemDisable = new OleMenuCommand((s, e) => bridge.Execute(CommandAction.Disable), disableCommand); menuItemDisable.BeforeQueryStatus += (s, e) => bridge.UpdateCommand(menuItemDisable, CommandAction.Disable); CommandID gettingStarted = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdGettingStarted); OleMenuCommand menuItemGettingStarted = new OleMenuCommand((s, e) => System.Diagnostics.Process.Start("https://github.com/codingadventures/LINQBridgeVs#getting-started"), gettingStarted); CommandID sendFeedback = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdFeedback); OleMenuCommand menuItemSendFeedback = new OleMenuCommand((s, e) => System.Diagnostics.Process.Start("https://github.com/codingadventures/LINQBridgeVs/issues"), sendFeedback); mcs.AddCommand(menuItemEnable); mcs.AddCommand(menuItemDisable); mcs.AddCommand(menuItemGettingStarted); mcs.AddCommand(menuItemSendFeedback); //Initialize Object Exporter settings _packageSettings = (PackageSettings)GetDialogPage(typeof(PackageSettings)); try { //if first time user if (isLinqBridgeVsConfigured) { return; } if (!IsElevated) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (Application.ResourceAssembly == null) { // ReSharper disable once HeuristicUnreachableCode Application.ResourceAssembly = typeof(Welcome).Assembly; } _welcomePage = new Welcome(_dte); } else { _installationResult = PackageConfigurator.Install(_dte.Version, _dte.Edition); } } catch (Exception e) { _error = new Error(); _error.Body = $"{e.Message} %0A {e.StackTrace}"; _error.Title = "Error during installation. 1.4.6"; Exception innerException = e.InnerException; while (innerException != null) { _error.Body += $"%0A {innerException.Message} {innerException.StackTrace}"; innerException = innerException.InnerException; } _error.Body = _error.Body.Replace(Environment.NewLine, "%0A"); } }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param> /// <param name="progress">A provider for progress updates.</param> /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // Query service asynchronously from the UI thread var dte = await GetServiceAsync(typeof(DTE)) as DTE; Assumes.Present(dte); BridgeVsExtension bridge = new BridgeVsExtension(dte); // Add our command handlers for menu(commands must exist in the.vsct file) OleMenuCommandService mcs = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; Assumes.Present(mcs); // Create the command for the menu item. CommandID enableCommand = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdEnableBridge); OleMenuCommand menuItemEnable = new OleMenuCommand((s, e) => bridge.Execute(CommandAction.Enable), enableCommand); menuItemEnable.BeforeQueryStatus += (s, e) => bridge.UpdateCommand(menuItemEnable, CommandAction.Enable); CommandID disableCommand = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdDisableBridge); OleMenuCommand menuItemDisable = new OleMenuCommand((s, e) => bridge.Execute(CommandAction.Disable), disableCommand); menuItemDisable.BeforeQueryStatus += (s, e) => bridge.UpdateCommand(menuItemDisable, CommandAction.Disable); CommandID gettingStarted = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdGettingStarted); OleMenuCommand menuItemGettingStarted = new OleMenuCommand((s, e) => System.Diagnostics.Process.Start("https://github.com/codingadventures/LINQBridgeVs#getting-started"), gettingStarted); CommandID sendFeedback = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdFeedback); OleMenuCommand menuItemSendFeedback = new OleMenuCommand((s, e) => System.Diagnostics.Process.Start("https://marketplace.visualstudio.com/items?itemName=codingadventures.linqbridgevs#review-details"), sendFeedback); mcs.AddCommand(menuItemEnable); mcs.AddCommand(menuItemDisable); mcs.AddCommand(menuItemGettingStarted); mcs.AddCommand(menuItemSendFeedback); bool isLinqBridgeVsConfigured = PackageConfigurator.IsBridgeVsConfigured(dte.Version); //if first time user if (isLinqBridgeVsConfigured) { return; } //Initialize Object Exporter settings PackageSettings packageSettings = null; Package: try { packageSettings = (PackageSettings)GetDialogPage(typeof(PackageSettings)); } catch { goto Package; } DialogResult messageResult = MessageBox.Show("Do you want to send anonymous error reports to LINQBridgeVs?", "LINQBridgeVs: Error Tracking", MessageBoxButtons.YesNo, MessageBoxIcon.Question); packageSettings.ErrorTrackingEnabled = messageResult == DialogResult.Yes; packageSettings.SaveSettingsToStorage(); PackageConfigurator.Install(dte.Version, dte.Edition); }
/// <inheritdoc /> /// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { base.Initialize(); _dte = (DTE)GetService(typeof(SDTE)); _dteEvents = _dte.Events.DTEEvents; _dteEvents.OnStartupComplete += _dteEvents_OnStartupComplete; BridgeVsExtension bridge = new BridgeVsExtension(_dte); bool isLinqBridgeVsConfigured = PackageConfigurator.IsBridgeVsConfigured(_dte.Version); // Add our command handlers for menu(commands must exist in the.vsct file) OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null == mcs) { return; } // Create the command for the menu item. CommandID enableCommand = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdEnableBridge); OleMenuCommand menuItemEnable = new OleMenuCommand((s, e) => bridge.Execute(CommandAction.Enable), enableCommand); menuItemEnable.BeforeQueryStatus += (s, e) => bridge.UpdateCommand(menuItemEnable, CommandAction.Enable); CommandID disableCommand = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdDisableBridge); OleMenuCommand menuItemDisable = new OleMenuCommand((s, e) => bridge.Execute(CommandAction.Disable), disableCommand); menuItemDisable.BeforeQueryStatus += (s, e) => bridge.UpdateCommand(menuItemDisable, CommandAction.Disable); CommandID gettingStarted = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdGettingStarted); OleMenuCommand menuItemGettingStarted = new OleMenuCommand((s, e) => System.Diagnostics.Process.Start("https://github.com/codingadventures/LINQBridgeVs#getting-started"), gettingStarted); CommandID sendFeedback = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdFeedback); OleMenuCommand menuItemSendFeedback = new OleMenuCommand((s, e) => System.Diagnostics.Process.Start("https://github.com/codingadventures/LINQBridgeVs/issues"), sendFeedback); mcs.AddCommand(menuItemEnable); mcs.AddCommand(menuItemDisable); mcs.AddCommand(menuItemGettingStarted); mcs.AddCommand(menuItemSendFeedback); try { Log.Configure("LINQBridgeVs", "Extensions"); //if first time user if (isLinqBridgeVsConfigured) { return; } if (!IsElevated) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (Application.ResourceAssembly == null) { // ReSharper disable once HeuristicUnreachableCode Application.ResourceAssembly = typeof(Welcome).Assembly; } _welcomePage = new Welcome(_dte); } else { _installationResult = PackageConfigurator.Install(_dte.Version, _dte.Edition); } } catch (Exception e) { Log.Write(e, "Initialize Error..."); MessageBox.Show("LINQBridgeVs wasn't successfully configured. Please restart Visual Studio"); } }