Подтвердить что ты не робот

Запуск пользовательского инструмента для всего решения

Есть ли способ "Запустить пользовательский инструмент" для всего решения?

Почему? Пользовательский инструмент находится в разработке, и когда изменения сделаны, мне нужно обновить все элементы, которые его используют, чтобы убедиться, что ничего не сломается.

4b9b3361

Ответ 1

Поскольку для этого мне нужен был ответ, и я должен был сделать это сам, вот решение для "Run Custom Tool".

Если вам просто нужно снова запустить все ваши шаблоны T4, тогда, поскольку VS2012 содержит Transform all T4 в меню Build.

Для VS2017 они удалили макросы, поэтому следуйте https://msdn.microsoft.com/en-us/library/cc138589.aspx и создайте плагин с вашим пунктом меню. Например. Назовите команду RefreshAllResxFiles и вставьте этот файл (набор команд по умолчанию не включает DLL для VSLangProj, поэтому просто найдите соответствующий пакет в NuGet):

internal sealed class RefreshAllResxFiles
{
  public const int CommandId = 0x0100;
  public static readonly Guid CommandSet = new Guid(copy the guid from guidRefreshAllResxFilesPackageCmdSet from the vsct file);
  private readonly Package _package;
  private readonly DTE2 _dte;

  /// <summary>
  /// Initializes a new instance of the <see cref="RefreshAllResxFiles"/> class.
  /// Adds our command handlers for menu (commands must exist in the command table file)
  /// </summary>
  /// <param name="package">Owner package, not null.</param>
  private RefreshAllResxFiles(Package package)
  {
     _package = package ?? throw new ArgumentNullException(nameof(package));

     var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
     if (commandService != null)
     {
        var menuCommandId = new CommandID(CommandSet, CommandId);
        var menuItem = new MenuCommand(MenuItemCallback, menuCommandId);
        commandService.AddCommand(menuItem);
     }
     _dte = ServiceProvider.GetService(typeof(DTE)) as DTE2;
  }

  public static RefreshAllResxFiles Instance { get; private set; }
  private IServiceProvider ServiceProvider => _package;

  public static void Initialize(Package package)
  {
     Instance = new RefreshAllResxFiles(package);
  }

  /// <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>
  private void MenuItemCallback(object sender, EventArgs e)
  {
     foreach (Project project in _dte.Solution.Projects)
        IterateProjectFiles(project.ProjectItems);
  }

  private void IterateProjectFiles(ProjectItems projectProjectItems)
  {
     foreach (ProjectItem file in projectProjectItems)
     {
        var o = file.Object as VSProjectItem;
        if (o != null)
           ProcessFile(o);
        if (file.SubProject?.ProjectItems != null)
           IterateProjectFiles(file.SubProject.ProjectItems);
        if (file.ProjectItems != null)
           IterateProjectFiles(file.ProjectItems);
     }

  }

  private void ProcessFile(VSProjectItem file)
  {
     if (file.ProjectItem.Name.EndsWith(".resx"))
     {
        file.RunCustomTool();
        Log(file.ProjectItem.Name);
     }
  }
  public const string VsWindowKindOutput = "{34E76E81-EE4A-11D0-AE2E-00A0C90FFFC3}";

  private void Log(string fileName)
  {
     var output = _dte.Windows.Item(VsWindowKindOutput);
     var pane = ((OutputWindow)output.Object).OutputWindowPanes.Item("Debug");
     pane.Activate();
     pane.OutputString(fileName);
     pane.OutputString(Environment.NewLine);
  }
}

И старое решение для макроса:

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports VSLangProj
Imports System.Diagnostics

Public Module RecordingModule
    Sub IterateFiles()
        Dim solution As Solution = DTE.Solution
        For Each prj As Project In solution.Projects
            IterateProjectFiles(prj.ProjectItems)
        Next
    End Sub

    Private Sub IterateProjectFiles(ByVal prjItms As ProjectItems)
        For Each file As ProjectItem In prjItms
            If file.Object IsNot Nothing AndAlso TypeOf file.Object Is VSProjectItem Then
                AddHeaderToItem(file.Object)
            End If
            If file.SubProject IsNot Nothing AndAlso file.SubProject.ProjectItems IsNot Nothing AndAlso file.SubProject.ProjectItems.Count > 0 Then
                IterateProjectFiles(file.SubProject.ProjectItems)
            End If
            If file.ProjectItems IsNot Nothing AndAlso file.ProjectItems.Count > 0 Then
                IterateProjectFiles(file.ProjectItems)
            End If
        Next
    End Sub

    Private Sub AddHeaderToItem(ByVal file As VSProjectItem)
        If file.ProjectItem.Name.EndsWith(".resx") Then
            file.RunCustomTool()
            Log(file.ProjectItem.Name)
        End If
    End Sub
    Private Sub Write(ByVal name As String, ByVal message As String)
        Dim output As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
        Dim window As OutputWindow = output.Object
        Dim pane As OutputWindowPane = window.OutputWindowPanes.Item(name)
        pane.Activate()
        pane.OutputString(message)
        pane.OutputString(Environment.NewLine)
    End Sub
    Private Sub Log(ByVal message As String, ByVal ParamArray args() As Object)
        Write("Debug", String.Format(message, args))
    End Sub

    Private Sub Log(ByVal message As String)
        Write("Debug", message)
    End Sub

End Module

Ответ 2

В Visual Studio 2010 на панели значков навигатора решений есть кнопка, которая будет запускать все шаблоны t4 в решении.

В Visual Studio 2012 отобразите панель инструментов "Построить". На этой панели инструментов есть кнопка, которая будет запускать все шаблоны t4 в решении.

Ответ 3

Вы можете выполнить все шаблоны T4 в решении в Visual Studio 2010. Щелкните правой кнопкой мыши верхнюю панель на панели инструментов и включите панель инструментов "Создать". Это добавит панель инструментов со следующим:

  • Выбор сборки
  • Решение для сборки
  • Преобразование всех шаблонов T4
  • Отмена

"Преобразование всех шаблонов T4" должно предоставить вам то, что вы хотите.

Ответ 4

Для тех, кто начал использовать решение, предоставленное в других ответах, но обнаруживает, что выполнение всех шаблонов в решении занимает слишком много времени - и если подмножество шаблонов будет достаточно - тогда можно запустить несколько шаблонов используя следующие шаги.

  • Выберите шаблоны, которые вы хотите запустить в обозревателе решений в Visual Studio. Обратите внимание, что это фактические файлы, которые вы должны выбрать - , а не папка, содержащая их.
  • Щелкните правой кнопкой мыши на одном из выбранных файлов шаблонов и выберите Run Custom Tool в контекстном меню.