I am trying to add a resource using the BTSTASK command line and it works fine.
BTSTASK.EXE AddResource -Type:BizTalkAssembly /Source:dllpath /ApplicationName:myapp /Options:GacOnAdd,GacOnImport,GacOnInstall /Overwrite
But when the Biztalk assembly such as pipeline has the been used in some other application it won't work unless the port which uses this pipeline is being removed. If i remove the port from the application which uses this pipeline and then using BTSTASK i can add the resource. How this can be easily handled without removing the port of other dependent application.
You can't. The Artifact, Pipeline in your case, is in use and essentially 'locked'.
"been used in some other application" - You should never share artifacts between Applications. Doing so just created this otherwise unnecessary problem. Create a Pipeline in the local Application/Solution.
Using a tool such as BizTalk Deployment Framework, you can just redepoy the entire app taking typically just a few minutes. Almost the same as deploying single Assembly.