Showing posts with label Visual Basic. Show all posts
Showing posts with label Visual Basic. Show all posts

Saturday, April 17, 2010

CodePlex TFS from VS2010

Visual Studio 2010 Professional has a built-in Team Foundation Server (TFS) client. There are some user interface changes on the Add Team Foundation Server screen. When you are connecting to the CodePlex TFS, you need to specify the following information:

  • Name or URL of TFS: tfs<number>.codeplex.com
  • Connection details
    • Path: tfs
    • Port number: 443
    • Protocol: HTTPS

There is no need to specify Project name anywhere on this screen.

Sunday, February 1, 2009

Early and Late Binding

There are numerous definitions for early and late binding. Some are technical, some are theoretical. I will try to define it from both viewpoints.

Variables and expressions can be assigned at compile time or at runtime. Compile time (declaration time) assignment is called:

  • early binding
  • static binding
  • static typing

An example for early binding:

  1: '  Create a variable to hold a new object.
  2: Dim FS As System.IO.FileStream
  3: ' Assign a new object to the variable.
  4: FS = New System.IO.FileStream("C:\tmp.txt", _
  5:     System.IO.FileMode.Open)

Runtime assignment is called dynamic binding or late binding, when the type of the variable or expression is determined by the current (application) conditions. An example for late binding:

  1: ' To use this example, you must have Microsoft Excel installed on your computer.
  2: ' Compile with Option Strict Off to allow late binding.
  3: Sub TestLateBinding()
  4:     Dim xlApp As Object
  5:     Dim xlBook As Object
  6:     Dim xlSheet As Object
  7:     xlApp = CreateObject("Excel.Application")
  8:     ' Late bind an instance of an Excel workbook.
  9:     xlBook = xlApp.Workbooks.Add
 10:     ' Late bind an instance of an Excel worksheet.
 11:     xlSheet = xlBook.Worksheets(1)
 12:     xlSheet.Activate()
 13:     ' Show the application.
 14:     xlSheet.Application.Visible = True
 15:     ' Place some text in the second row of the sheet.
 16:     xlSheet.Cells(2, 2) = "This is column B row 2"
 17: End Sub

Another example for late binding:

  1: Dim MyVariable As Object
  2: MyVariable = "About Visual Basic"
  3: Debug.WriteLine("The variable data type is: " & MyVariable.GetType.ToString)
  4: MyVariable = #6/30/2006#
  5: Debug.WriteLine("The variable data type is: " & MyVariable.GetType.ToString)

The result for the code above:

The variable data type is: System.String
The variable data type is: System.DateTime

As you can see, the variable named MyVariable can represent a System.String and a System.Date in the code above.

Despite of the advantages of late binding, early binding is recommended:

  • Early binding code can be optimized better by the compiler, so it runs (much) faster
  • It is usually easier to read early binding code (known types, etc.)
  • Automatic code completion, Dynamic Help and other advanced IDE features are available only for early binding codes
  • Compiler can type 'compatibility' for early binding variables and expressions
  • Application constants are accessible (e.g. in MS Word)

Some advantages of late binding:

  • Version independence. E.g. in case of MS Word, programming against Word 97 and changing code libraries to Word 2000 can be smooth and automatic.
  • More references can mean more linking and bigger file size (in case of unmanaged code)

There are numerous methods in C# to use late binding. Most of them employs reflection and dynamic compilation. There will be late binding as a language feature from C# 4.0 specification. Late binding will be as simple as the following:

  1: dynamic d = GetDynamicObject();
  2: d.Foo();
Late binding will be achieved by the dynamic keyword.

Friday, May 23, 2008

IIS debugging macro

Usually developers use a single remote server while developing custom SharePoint solution. It means the developer tools and the server are not on the same machine. You can connect to the server after starting the Visual Studio Remote Debugger. Now you can attach debugger to the remote w3wp.exe processes. This process can be very annoying after a while.
It is a macro that will automate this process:
   1:  Imports System
   2:  Imports EnvDTE80
   3:  Imports System.Diagnostics
   4:   
   5:  Public Module AttachToWebServer
   6:   
   7:      Public Sub AttachToWebServer()
   8:   
   9:          Dim AspNetWp As String = "aspnet_wp.exe"
  10:          Dim W3WP As String = "w3wp.exe"
  11:   
  12:          If Not (AttachToProcess(AspNetWp)) Then
  13:              If Not AttachToProcess(W3WP) Then
  14:                  System.Windows.Forms.MessageBox.Show(String.Format("Process {0} or {1} Cannot Be Found", AspNetWp, W3WP), "Attach To Web Server Macro")
  15:              End If
  16:          End If
  17:   
  18:      End Sub
  19:   
  20:      Public Function AttachToProcess(ByVal ProcessName As String) As Boolean
  21:   
  22:          Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
  23:          Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
  24:   
  25:          Dim Processes As EnvDTE.Processes = dbg2.GetProcesses(trans, "DOMAIN\USER@MACHINE")
  26:          Dim Process As EnvDTE.Process
  27:          Dim ProcessFound As Boolean = False
  28:   
  29:          For Each Process In Processes
  30:              If (Process.Name.Substring(Process.Name.LastIndexOf("\") + 1) = ProcessName) Then
  31:                  Process.Attach()
  32:                  ProcessFound = True
  33:              End If
  34:          Next
  35:   
  36:          AttachToProcess = ProcessFound
  37:   
  38:      End Function
  39:   
  40:  End Module

Change the "DOMAIN\USER@MACHINE" to your own ID. The DOMAIN\USER is the debugger user, the MACHINE is the debugging target machine. You can get this ID from Visual Studio Remote Debugger first log line or from a previous connection log line.

This macro is based on Howard van Rooijen macro implementation.


Localhost debugging: change DOMAIN\USER@MACHINE to empty string ("").

Developer (Visual Studio-integrated) server debugging: add WebDev.WebServer.EXE before If Not (AttachToProcess(AspNetWp)) Then like If Not (AttachToProcess("WebDev.WebServer.EXE")) Then

Link: View and download the script on Google Code [.vb]
Link: Attach to Web Server Macro for Visual Studio