1: Imports System
2: Imports EnvDTE
3: Imports EnvDTE80
4: Imports EnvDTE90
5: Imports System.Diagnostics
6:
7: Public Module SenthilMacros
8: Public Sub JustAttach()
9: Dim solutionBuild As SolutionBuild = DTE.Solution.SolutionBuild
10: Dim startupProjectName As String = solutionBuild.StartupProjects(0)
11:
12: If String.IsNullOrEmpty(startupProjectName) Then
13: MsgBox("Could not attach because the startup project could not be determined", MsgBoxStyle.Critical, "Failed to Attach")
14: Return
15: End If
16:
17: Dim startupProject As Project = FindProject(startupProjectName.Trim())
18: Dim outputFilePath As String = FindOutputFileForProject(startupProject)
19:
20: If String.IsNullOrEmpty(outputFilePath) Then
21: MsgBox("Could not attach because output file path for the startup project could not be determined", MsgBoxStyle.Critical, "Failed to Attach")
22: Return
23: End If
24:
25: Attach(outputFilePath)
26: End Sub
27: Sub Attach(ByVal file As String)
28: Dim process As EnvDTE.Process
29:
30: For Each process In DTE.Debugger.LocalProcesses
31: If process.Name = file Then
32: process.Attach()
33: Return
34: End If
35: Next
36:
37: MsgBox("Could not attach because " + file + " is not found in the list of running processes", MsgBoxStyle.Critical, "Failed to Attach")
38: End Sub
39:
40: Function FindProject(ByVal projectName As String) As Project
41: Dim project As Project
42: For Each project In DTE.Solution.Projects
43: If project.UniqueName = projectName Then
44: Return project
45: End If
46: Next
47: End Function
48: Function FindOutputFileForProject(ByVal project As Project) As String
49: Dim fileName As String = project.Properties.Item("OutputFileName").Value.ToString()
50: Dim projectPath As String = project.Properties.Item("LocalPath").Value.ToString()
51:
52: Dim config As Configuration = project.ConfigurationManager.ActiveConfiguration
53: Dim buildPath = config.Properties.Item("OutputPath").Value.ToString()
54:
55: If String.IsNullOrEmpty(fileName) Or String.IsNullOrEmpty(projectPath) Then
56: Return ""
57: End If
58:
59: Dim folderPath As String = System.IO.Path.Combine(projectPath, buildPath)
60: Return System.IO.Path.Combine(folderPath, fileName)
61:
62: End Function
63: End Module
64: