Reputation: 45809
I've been using the macro from this blog entry for attaching the Visual Studio debugger to an already running instance of the Web Application I'm currently working on. However, if I have more than one instance of the Visual Studio web server running it's pot luck which one it'll attach to.
Is there a way to determine what port is configured in the Web project so I can modify the macro to filter its choice of process to that one?
Further Info
I'm aware that you can set the port number to a static one - I've done just that from the get-go, what I'm trying to determine is how to programatically determine the defined port-number so I can modify the macro (in the linked blog entry) and ensure it connects to the right instance of the Visual Studio web server.
The way I have things running is I have two (or more) instances of Visual Studio running, each of which contains a Solution, which contains a web project and one or more other projects - typically an Installer project), so when I trigger the macro from a given instance of Visual Studio, I want to find the Web Project within that instances loaded solution and determine the port it's running against.
Upvotes: 2
Views: 3750
Reputation: 13709
If that can help you, I have found a link that might actually to the trick.
However, it require DllImport call and a lot of fun.
You can take a look at that article there: http://bytes.com/forum/thread574901.html
Quotes from the actual site:
By calling into iphlpapi.dll using PInvoke interop. Google around for GetExtendedTcpTable and iphlpapi.dll, I'm sure you will find some existing stuff.
Willy.
And one last:
Here are some API-Methods for my purposes:
GetTcpTable()
AllocateAndGetTcpExTableFromStack()
GetExtendedTcpTable()I wrote a small programm that is able to show me all Processes with the belonging TCP-Ports (with AllocateAndGetTcpExTableFromStack()) running under Windows XP.
Now my problem is, that under Windows 2000 I can't use AllocateAndGetTcpExTableFromStack() or GetExtendedTcpTable() so I'm only able to use GetTcpTable() to list all TCP-Ports but without the belonging processes.
Did somebody have the same problem or is there another way (.Net or WMI etc.) to solve my problem?
Thanks in advance,
Werner
Upvotes: 0
Reputation: 710
This code will get you a list of all ports for the projects in the current solution:
Sub GetWebProjectPorts()
Dim ports As String
For Each prj As Project In DTE.Solution.Projects
For Each p As EnvDTE.Property In prj.Properties
If p.Name.Contains("DevelopmentServerPort") Then
If Not String.IsNullOrEmpty(ports) Then
ports += ","
End If
ports += p.Value.ToString()
End If
Next
Next
MsgBox(ports)
End Sub
Upvotes: 2
Reputation: 3213
If you go to the properties for your web project and look under the "Web" tab, you can specify which port the project will always start up on. Then you can click "Enable Edit and Continue" so you don't have to stop debugging and restart continuously.
Upvotes: -1