您可以使用EnvDTE作为预构建事件来使用RunCustomTool吗?

时间:2022-08-07 23:07:15

I am using T4MVC, and I can't use a pre-build event to run TextTransform.exe as it relies on EnvDTE, and must be run with Visual Studio as host.

我使用的是T4MVC,我不能使用预构建事件来运行TextTransform。exe依赖于EnvDTE,必须以Visual Studio作为主机运行。

If I have run custom tool once, it works nicely because it marks itself dirty when its executed (AlwaysKeepTemplateDirty = true), but when you open the solution, it doesn't run on build, so I was wondering if you could run t4 via EnvDTE as a pre-build event?

如果我有一次运行自定义工具,它可以很好地工作,因为它在执行时标记了自己(AlwaysKeepTemplateDirty = true),但是当您打开解决方案时,它不会在构建中运行,所以我想知道您是否可以通过EnvDTE作为预构建事件运行t4 ?

2 个解决方案

#1


16  

I figured out a way to do this. Its not optimal, but it actually works. If you hookup to the BuildEvents.OnBuildBegin.

我想出了一个办法。它不是最优的,但它确实有效。如果你搭上了大楼,马上开始。

You push ALT+F11 to get to the Macro IDE, click EnvironmenEvents and add the eventhandler in the below code snippet . Make sure that its added outside the autogenerated code section.

您将ALT+F11推入宏IDE,单击“环境事件”,并在下面的代码片段中添加eventhandler。确保其添加在自动生成的代码段之外。

The EnvironmentEvents now looks like this:

现在的环境是这样的:

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

Public Module EnvironmentEvents

    Public Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
        If Scope = vsBuildScope.vsBuildScopeSolution Or Scope = vsBuildScope.vsBuildScopeProject Then
            Dim projectItem As ProjectItem = DTE.Solution.FindProjectItem("T4MVC.tt")
            If Not projectItem Is Nothing Then
                If Not projectItem.IsOpen Then
                    projectItem.Open()
                End If
                projectItem.Save()
            End If
        End If
    End Sub

#Region "Automatically generated code, do not modify"
'Automatically generated code, do not modify
'Event Sources Begin
 <System.ContextStaticAttribute()> Public WithEvents DTEEvents As EnvDTE.DTEEvents
 <System.ContextStaticAttribute()> Public WithEvents DocumentEvents As EnvDTE.DocumentEvents
 <System.ContextStaticAttribute()> Public WithEvents WindowEvents As EnvDTE.WindowEvents
 <System.ContextStaticAttribute()> Public WithEvents TaskListEvents As EnvDTE.TaskListEvents
 <System.ContextStaticAttribute()> Public WithEvents FindEvents As EnvDTE.FindEvents
 <System.ContextStaticAttribute()> Public WithEvents OutputWindowEvents As EnvDTE.OutputWindowEvents
 <System.ContextStaticAttribute()> Public WithEvents SelectionEvents As EnvDTE.SelectionEvents
 <System.ContextStaticAttribute()> Public WithEvents BuildEvents As EnvDTE.BuildEvents
 <System.ContextStaticAttribute()> Public WithEvents SolutionEvents As EnvDTE.SolutionEvents
 <System.ContextStaticAttribute()> Public WithEvents SolutionItemsEvents As EnvDTE.ProjectItemsEvents
 <System.ContextStaticAttribute()> Public WithEvents MiscFilesEvents As EnvDTE.ProjectItemsEvents
 <System.ContextStaticAttribute()> Public WithEvents DebuggerEvents As EnvDTE.DebuggerEvents
 <System.ContextStaticAttribute()> Public WithEvents ProjectsEvents As EnvDTE.ProjectsEvents
 <System.ContextStaticAttribute()> Public WithEvents TextDocumentKeyPressEvents As EnvDTE80.TextDocumentKeyPressEvents
 <System.ContextStaticAttribute()> Public WithEvents CodeModelEvents As EnvDTE80.CodeModelEvents
 <System.ContextStaticAttribute()> Public WithEvents DebuggerProcessEvents As EnvDTE80.DebuggerProcessEvents
 <System.ContextStaticAttribute()> Public WithEvents DebuggerExpressionEvaluationEvents As EnvDTE80.DebuggerExpressionEvaluationEvents
'Event Sources End
'End of automatically generated code
#End Region

End Module

#2


1  

This is definitely one of the areas of T4MVC that I'd like to solve, but haven't been able to find a great solution to. I did make some attempt at the time to use a pre-build event but didn't get anywhere interesting. Which doesn't mean it can't be done.

这绝对是我想要解决的T4MVC领域之一,但还没有找到一个很好的解决方案。我确实尝试过使用预构建事件,但没有得到任何有趣的结果。但这并不意味着它不可能实现。

Sorry, I don't have a solution for you, but if someone comes up with something, I'd be happy to integrate it into T4MVC.

对不起,我没有解决方案,但是如果有人提出了什么问题,我很乐意将它集成到T4MVC中。

David

大卫

#1


16  

I figured out a way to do this. Its not optimal, but it actually works. If you hookup to the BuildEvents.OnBuildBegin.

我想出了一个办法。它不是最优的,但它确实有效。如果你搭上了大楼,马上开始。

You push ALT+F11 to get to the Macro IDE, click EnvironmenEvents and add the eventhandler in the below code snippet . Make sure that its added outside the autogenerated code section.

您将ALT+F11推入宏IDE,单击“环境事件”,并在下面的代码片段中添加eventhandler。确保其添加在自动生成的代码段之外。

The EnvironmentEvents now looks like this:

现在的环境是这样的:

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

Public Module EnvironmentEvents

    Public Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
        If Scope = vsBuildScope.vsBuildScopeSolution Or Scope = vsBuildScope.vsBuildScopeProject Then
            Dim projectItem As ProjectItem = DTE.Solution.FindProjectItem("T4MVC.tt")
            If Not projectItem Is Nothing Then
                If Not projectItem.IsOpen Then
                    projectItem.Open()
                End If
                projectItem.Save()
            End If
        End If
    End Sub

#Region "Automatically generated code, do not modify"
'Automatically generated code, do not modify
'Event Sources Begin
 <System.ContextStaticAttribute()> Public WithEvents DTEEvents As EnvDTE.DTEEvents
 <System.ContextStaticAttribute()> Public WithEvents DocumentEvents As EnvDTE.DocumentEvents
 <System.ContextStaticAttribute()> Public WithEvents WindowEvents As EnvDTE.WindowEvents
 <System.ContextStaticAttribute()> Public WithEvents TaskListEvents As EnvDTE.TaskListEvents
 <System.ContextStaticAttribute()> Public WithEvents FindEvents As EnvDTE.FindEvents
 <System.ContextStaticAttribute()> Public WithEvents OutputWindowEvents As EnvDTE.OutputWindowEvents
 <System.ContextStaticAttribute()> Public WithEvents SelectionEvents As EnvDTE.SelectionEvents
 <System.ContextStaticAttribute()> Public WithEvents BuildEvents As EnvDTE.BuildEvents
 <System.ContextStaticAttribute()> Public WithEvents SolutionEvents As EnvDTE.SolutionEvents
 <System.ContextStaticAttribute()> Public WithEvents SolutionItemsEvents As EnvDTE.ProjectItemsEvents
 <System.ContextStaticAttribute()> Public WithEvents MiscFilesEvents As EnvDTE.ProjectItemsEvents
 <System.ContextStaticAttribute()> Public WithEvents DebuggerEvents As EnvDTE.DebuggerEvents
 <System.ContextStaticAttribute()> Public WithEvents ProjectsEvents As EnvDTE.ProjectsEvents
 <System.ContextStaticAttribute()> Public WithEvents TextDocumentKeyPressEvents As EnvDTE80.TextDocumentKeyPressEvents
 <System.ContextStaticAttribute()> Public WithEvents CodeModelEvents As EnvDTE80.CodeModelEvents
 <System.ContextStaticAttribute()> Public WithEvents DebuggerProcessEvents As EnvDTE80.DebuggerProcessEvents
 <System.ContextStaticAttribute()> Public WithEvents DebuggerExpressionEvaluationEvents As EnvDTE80.DebuggerExpressionEvaluationEvents
'Event Sources End
'End of automatically generated code
#End Region

End Module

#2


1  

This is definitely one of the areas of T4MVC that I'd like to solve, but haven't been able to find a great solution to. I did make some attempt at the time to use a pre-build event but didn't get anywhere interesting. Which doesn't mean it can't be done.

这绝对是我想要解决的T4MVC领域之一,但还没有找到一个很好的解决方案。我确实尝试过使用预构建事件,但没有得到任何有趣的结果。但这并不意味着它不可能实现。

Sorry, I don't have a solution for you, but if someone comes up with something, I'd be happy to integrate it into T4MVC.

对不起,我没有解决方案,但是如果有人提出了什么问题,我很乐意将它集成到T4MVC中。

David

大卫