T4MVC を使用していますが、ビルド前のイベントを使用して TextTransform.exe を実行することはできません。これは EnvDTE に依存しており、Visual Studio をホストとして実行する必要があるためです。
カスタム ツールを 1 回実行すると、実行時にダーティとマークされるため ( AlwaysKeepTemplateDirty = true
)、うまく機能しますが、ソリューションを開くとビルド時に実行されないため、EnvDTE を介してプレビルドイベント?
これを行う方法を考え出しました。最適ではありませんが、実際には機能します。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
これは間違いなく私が解決したい T4MVC の領域の 1 つですが、優れた解決策を見つけることができませんでした。当時、ビルド前のイベントを使用しようと試みましたが、興味深いものはありませんでした。これは、それができないという意味ではありません。
申し訳ありませんが、解決策はありませんが、誰かが何か思いついたら、喜んで T4MVC に統合します。
デビッド