コード例 #1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            foreach (Project proj in VsHelper.GetSelectedCsharpProjects())
            {
                if (!ConfigProcessing.ConfigExistsForProject(proj))
                {
                    string configPath = ScriptGenAssemblyCache.GetForProj(proj)?.GetConfigFilepath(proj.FullName);
                    if (string.IsNullOrEmpty(configPath))
                    {
                        VsShellUtilities.ShowMessageBox(
                            ServiceProvider,
                            "Failed to find target configuration file path.  It is possible you need to update the Nuget Package.",
                            "Add Config Failed",
                            OLEMSGICON.OLEMSGICON_CRITICAL,
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                        return;
                    }


                    if (!File.Exists(configPath))
                    {
                        ScriptGenAssemblyCache.GetForProj(proj).CreateNewConfigFile(configPath);
                    }
                    proj.ProjectItems.AddFromFile(configPath);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// This function is the callback used to execute the command when the menu item is clicked.
 /// See the constructor to see how the menu item is associated with this function using
 /// OleMenuCommandService service and MenuCommand class.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event args.</param>
 private void MenuItemCallback(object sender, EventArgs e)
 {
     foreach (Project proj in VsHelper.GetSelectedItemsOfType <Project>())
     {
         if (!VsHelper.IsSolutionItemsFolder(proj) &&
             !ConfigProcessing.ConfigExistsForProject(proj))
         {
             ConfigProcessing.CreateForProject(proj);
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Before query for Adding a config file to the solution
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_BeforeQueryStatus(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            OleMenuCommand button = (OleMenuCommand)sender;

            button.Visible = false;
            button.Enabled = false;

            foreach (Project proj in VsHelper.GetSelectedCsharpProjects())
            {
                button.Visible = true;                  // At least one project is selected...
                if (!ConfigProcessing.ConfigExistsForProject(proj) && VsHelper.IsPackageInstalled(proj))
                {
                    button.Enabled = true;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            Workspace currentWorkspace = VsHelper.Current.GetCurrentWorkspace();

            foreach (EnvDTE.Project proj in VsHelper.GetSelectedCsharpProjects())
            {
                if (ConfigProcessing.ConfigExistsForProject(proj))
                {
                    var result = Imports.ScriptGenAssemblyCache.GetForProj(proj).GenerateScripts(currentWorkspace, proj.FullName, true);
                    // Show a message box to prove we were here
                    if (!result.Success)
                    {
                        VsShellUtilities.ShowMessageBox(
                            ServiceProvider,
                            result.ErrorMessage,
                            "Script Generation Failed",
                            OLEMSGICON.OLEMSGICON_CRITICAL,
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }
                }
            }
        }