Windows Service working directory is windows\system32, so exe.config not found


When running TFSDeployer.exe from the console app, everything works fine. When running the windows service however, it seems the working directory is C:\Windows\system32, resulting in this error:

ERROR: Get-Content : Cannot find path 'C:\Windows\system32\TfsDeployer.exe.config' bec
ERROR: ause it does not exist.

A quick and dirty fix would be to copy the TfsDeployer.exe.config file to the system32 directory, but that's not pretty.
Closed Jul 18, 2012 at 10:28 PM by jstangroome
TFS Deployer now sets the working directory relative to the deployment script path


jstangroome wrote Dec 14, 2011 at 1:11 AM

It is not a recommended practice to rely on the working directory for any PowerShell script whether it is used for TFS Deployer or unrelated to deployment at all.

If a PowerShell script needs to locate resources relative to the path of the script itself then reference the value of $MyInvocation.MyCommand.Path.

I will look into changing the working directory to the TEMP path to prevent accidental side-effects of Remove-Item and other cmdlets.

JamesMiera wrote Jul 18, 2013 at 10:23 PM

Great work on creating this! You've made an incredible contribution.

How does one change the deployment script path? Yes, I use $PSScriptRoot = $MyInvocation.MyCommand.Path | Split-Path in my scripts, but I need to stage some files locally. $PSScriptRoot always resolves to C:\Windows\system32. In other words, I'd like to be able to map the Deployments folder in TFS to a specific folder to relative to a specific folder on the deployment target machine (other than C:\Windows\system32.

Your help is much appreciated!

jstangroome wrote Jul 19, 2013 at 5:24 AM

With which version of TFS Deployer are you experiencing this issue?