0
votes

I'm attempting to create a CodeActivity object that will register a DLL on a remote system during a TFS build. I am successfully impersonating my own user account, which has administrator rights to my machine. (I am trying to register the DLLs on my machine for now.) Note that all the attempts have worked if I run the workflow locally, but not from the build server. Also, if I manually run regsvr32, the DLL will register and unregister correctly.

This is the highly stripped-down code I'm using:

Private DllType As Type 'Type of the DLL being registered is handled elsewhere'
Dim Result As Integer
Result = CInt(DllType.InvokeMember("DllUnregisterServer", BindingFlags.InvokeMethod, Nothing, Activator.CreateInstance(DllType), Nothing))

When I run it, I get this message, the most relevant probably being the inner exception, "Unable to find an entry point named 'DllUnregisterServer' in DLL 'RptBarcodeLabel.dll"

Error = Exception has been thrown by the target of an invocation., stack = at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) at TfsCopyFile.DllRegServer.InternalRegServer(Boolean fUnreg) at TfsCopyFile.DllRegServer.UnRegister() at TfsCopyFile.TfsRegisterDLL.Execute(CodeActivityContext context), inner exception = Unable to find an entry point named 'DllUnregisterServer' in DLL 'RptBarcodeLabel.dll'.

Another method of remotely registering DLLs might work, too - I'm open to suggestions, as long as the process can be fire off during a build from TFS.

1

1 Answers

0
votes

This is the approach I have taken for a similar requirement:

In the TFSBuild.proj, use Exec action to create a .bat file on the fly on the deployment server; the batch file is remotely executed by PsExec. This example creates a batch file to run msiexec, but you can easily change it to register a dll use regsvr32.

<Exec Condition="'$(DeploymentServer)'!=''" Command='echo @echo off >"\\$(DeploymentServer)\C$\Temp\Install.bat"' ContinueOnError="true" />
<Exec Condition="'$(DeploymentServer)'!=''" Command='echo start /wait msiexec /uninstall "{98056358-8984-4554-b0c3-9f2af248a029}" /passive /log "C:\Temp\Uninstall.log" >>"\\$(DeploymentServer)\C$\Temp\Install.bat"' ContinueOnError="true" />
<!-- Kill the psexec service, otherwise it never terminates. -->
<Exec Condition="'$(DeploymentServer)'!=''" Command='echo taskkill /IM PSEXESVC.EXE >>"\\$(DeploymentServer)\C$\Temp\Install.bat"' ContinueOnError="true" />
<Exec Condition="'$(DeploymentServer)'!=''" Command='"C:\Program Files\Sysinternals\psexec" -accepteula \\$(DeploymentServer) -u myuser -p mypassword -w "C:\Temp" "C:\Temp\Install.bat"' ContinueOnError="true" />

If you don't use something like psexec, you can run into problems with permissions etc when trying to execute commands on the remote server.