首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >您可以使用EnvDTE作为预构建事件来执行RunCustomTool吗?

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

Stack Overflow用户
提问于 2010-02-26 21:01:42
回答 2查看 3K关注 0票数 9

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

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

EN

Stack Overflow用户

回答已采纳

发布于 2010-02-27 20:08:05

我想出了一个方法来做到这一点。它不是最优的,但它实际上是有效的。如果你连上了BuildEvents.OnBuildBegin。

将ALT+F11推送到Macro IDE,单击EnvironmenEvents并在下面的代码片段中添加eventhandler。确保将其添加到自动生成的代码节之外。

EnvironmentEvents现在看起来像这样:

代码语言:javascript
运行
复制
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
票数 16
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2341717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档