/// <summary> /// This function is the callback used to execute a command when the a menu item is clicked. /// See the Initialize method to see how the menu item is associated to this function using /// the OleMenuCommandService service and the MenuCommand class. /// </summary> private void CSharpAddReferenceCallback(object sender, EventArgs e) { var t4TemplateBase = Resources.ServiceModelTemplate; var project = VSIXUtils.GetSelectedProject(); string projectPath = project.Properties.Item("FullPath").Value.ToString(); int fileNameNumber = 1; //Find a version of the default name that doesn't already exist, //mimicing VS default file name behaviour. while (File.Exists(Path.Combine(projectPath, "ServiceReference" + fileNameNumber + ".tt"))) { fileNameNumber++; } var dialog = new AddServiceStackReference("ServiceReference" + fileNameNumber); dialog.UseCSharpProvider(t4TemplateBase); dialog.ShowDialog(); if (!dialog.AddReferenceSucceeded) { return; } string templateCode = dialog.CodeTemplate; CreateAndAddTemplateToProject(dialog.FileNameTextBox.Text + ".tt", templateCode); }
private void FSharpQueryAndAddMenuItem(object sender, EventArgs eventArgs) { OleMenuCommand command = (OleMenuCommand)sender; var monitorSelection = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection)); Guid guid = VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid; uint contextCookie; int pfActive; monitorSelection.GetCmdUIContextCookie(ref guid, out contextCookie); var result = monitorSelection.IsCmdUIContextActive(contextCookie, out pfActive); var ready = result == VSConstants.S_OK && pfActive > 0; Project project = VSIXUtils.GetSelectedProject(); command.Enabled = ready && project != null && project.Kind != null && //Project is not unloaded !string.Equals(project.Kind, "{67294A52-A4F0-11D2-AA88-00C04F688DDE}", StringComparison.InvariantCultureIgnoreCase); command.Visible = project != null && project.Kind != null && //Project is FSharp project string.Equals(project.Kind, "{F2A71F9B-5D33-465A-A702-920D77279786}", StringComparison.InvariantCultureIgnoreCase); }
private void AddNewDtoFileToProject(string fileName, string templateCode, List <string> nugetPackages = null) { nugetPackages = nugetPackages ?? new List <string>(); var project = VSIXUtils.GetSelectedProject() ?? VSIXUtils.GetSelectObject <ProjectItem>().ContainingProject; // This is a temporary work around for ServiceStack *.Core packages whilst they are separate/in beta. // This is to be removed/updated once the Text, Client and/or Interfaces NuGet packages support NetCore by default. nugetPackages = ApplyNetCoreNuGetPackages(nugetPackages, project); var path = VSIXUtils.GetSelectedProjectPath() ?? VSIXUtils.GetSelectedFolderPath(); string fullPath = Path.Combine(path, fileName); using (var streamWriter = File.CreateText(fullPath)) { streamWriter.Write(templateCode); streamWriter.Flush(); } // HACK avoid VS2015 Update 2 seems to detect file in use semi regularly. Thread.Sleep(20); var newDtoFile = project.ProjectItems.AddFromFile(fullPath); newDtoFile.Open(EnvDTE.Constants.vsViewKindCode); newDtoFile.Save(); foreach (var nugetPackage in nugetPackages) { AddNuGetDependencyIfMissing(project, nugetPackage); } project.Save(); }
private void VbNetQueryAddMenuItem(object sender, EventArgs eventArgs) { var command = (OleMenuCommand)sender; var monitorSelection = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection)); var guid = VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid; uint contextCookie; int pfActive; monitorSelection.GetCmdUIContextCookie(ref guid, out contextCookie); var result = monitorSelection.IsCmdUIContextActive(contextCookie, out pfActive); var ready = result == VSConstants.S_OK && pfActive > 0; var project = VSIXUtils.GetSelectedProject(); bool visible = project != null && project.Kind != null && //Project is not unloaded !string.Equals(project.Kind, VsHelperGuids.ProjectUnloaded, StringComparison.InvariantCultureIgnoreCase) && //Project is VbNet project string.Equals(project.Kind, VsHelperGuids.VbNetProjectKind, StringComparison.InvariantCultureIgnoreCase); bool enabled = visible && ready; command.Visible = visible; command.Enabled = enabled; }
private void AddNewDtoFileToProject(string fileName, string templateCode, List <string> nugetPackages = null) { nugetPackages = nugetPackages ?? new List <string>(); var project = VSIXUtils.GetSelectedProject() ?? VSIXUtils.GetSelectObject <ProjectItem>().ContainingProject; var path = VSIXUtils.GetSelectedProjectPath() ?? VSIXUtils.GetSelectedFolderPath(); string fullPath = Path.Combine(path, fileName); using (var streamWriter = File.CreateText(fullPath)) { streamWriter.Write(templateCode); streamWriter.Flush(); } // HACK avoid VS2015 Update 2 seems to detect file in use semi regularly. Thread.Sleep(20); var newDtoFile = project.ProjectItems.AddFromFile(fullPath); newDtoFile.Open(EnvDTE.Constants.vsViewKindCode); newDtoFile.Save(); foreach (var nugetPackage in nugetPackages) { AddNuGetDependencyIfMissing(project, nugetPackage); } project.Save(); }
private void CreateAndAddTemplateToProject(string fileName, string templateCode) { var project = VSIXUtils.GetSelectedProject(); string projectPath = project.Properties.Item("FullPath").Value.ToString(); string fullPath = Path.Combine(projectPath, fileName); using (var streamWriter = File.CreateText(fullPath)) { streamWriter.Write(templateCode); streamWriter.Flush(); } var t4TemplateProjectItem = project.ProjectItems.AddFromFile(fullPath); t4TemplateProjectItem.Open(EnvDTE.Constants.vsViewKindCode); t4TemplateProjectItem.Save(); AddNuGetDependencyIfMissing(project, "ServiceStack.Client"); AddNuGetDependencyIfMissing(project, "ServiceStack.Text"); project.Save(); }
private void AddNewDtoFileToProject(string fileName, string templateCode, List <string> nugetPackages = null) { nugetPackages = nugetPackages ?? new List <string>(); var project = VSIXUtils.GetSelectedProject() ?? VSIXUtils.GetSelectObject <ProjectItem>().ContainingProject; var path = VSIXUtils.GetSelectedProjectPath() ?? VSIXUtils.GetSelectedFolderPath(); string fullPath = Path.Combine(path, fileName); File.WriteAllText(fullPath, templateCode); try { // HACK avoid VS2015 Update 2 seems to detect file in use semi regularly. Thread.Sleep(50); var newDtoFile = project.ProjectItems.AddFromFile(fullPath); newDtoFile.Open(EnvDteConstants.vsViewKindCode); newDtoFile.Save(); } catch (Exception) {} try { foreach (var nugetPackage in nugetPackages) { AddNuGetDependencyIfMissing(project, nugetPackage); } } catch (Exception) {} try { project.Save(); } catch (Exception) {} }