gpt4 book ai didi

.net - 您可以使用 EnvDTE 作为预构建事件执行 RunCustomTool 吗?

转载 作者:行者123 更新时间:2023-12-01 23:21:39 24 4
gpt4 key购买 nike

我使用的是 T4MVC,并且无法使用预生成事件来运行 TextTransform.exe,因为它依赖于 EnvDTE,并且必须使用 Visual Studio 作为主机来运行。

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

最佳答案

我想出了一个方法来做到这一点。它不是最佳的,但它确实有效。如果您连接到 BuildEvents.OnBuildBegin。

按 ALT+F11 进入Macro IDE,单击EnvironmenEvents并在下面的代码片段中添加事件处理程序。确保将其添加到自动生成的代码部分之外。

EnvironmentEvents 现在看起来像这样:

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

关于.net - 您可以使用 EnvDTE 作为预构建事件执行 RunCustomTool 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2341717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com