Skip to content

PowerShell profile overrides the current working directory #781

@SimonBuckner

Description

@SimonBuckner

Hi,

I am developing a Windows service in Go. I'm using a combination of Air for hot loading and Taskfile as a cross platform alternative to Make. I've been hitting odd errors where all my individual tasks work fine when I launch them using Task task name. However, when I try to launch via Air I get various file not found errors. See the output below.


  __    _   ___
 / /\  | | | |_)
/_/--\ |_| |_| \_ v1.62.0, built with Go go1.24.4

[20:09:58] watching .
[20:09:58] watching cfg
[20:09:58] watching db
[20:09:58] watching hud
[20:09:58] watching hud\api
[20:09:58] watching hud\api\embed
[20:09:58] watching hud\api\pausebutton
[20:09:58] watching hud\components
[20:09:58] watching hud\components\button
[20:09:58] watching hud\components\icon
[20:09:58] watching hud\components\spinner
[20:09:58] watching hud\css
[20:09:58] watching hud\hudstate
[20:09:58] watching hud\pages
[20:09:58] watching hud\stores
[20:09:58] watching hud\utils
[20:09:58] watching importer
[20:09:58] !exclude static
[20:09:58] !exclude tmp
[20:09:58] Proxy server listening on http://localhost:8080
[20:09:58] > task.exe templ
file does not exist
[20:09:59] failed to execute pre_cmd: exit status 1
[20:09:59] building...
[20:09:59] CMD will not recognize non .exe file for execution, path: task build
file does not exist
[20:09:59] failed to build, error: exit status 1
[20:09:59] running...
time=2025-07-13T20:09:59.728+01:00 level=INFO msg=main event=get_working_directory directory=C:\Users\simon\Coding
time=2025-07-13T20:09:59.728+01:00 level=ERROR msg=config state=failed error="open ./cfg/config.toml: The system cannot find the path specified."
2025/07/13 20:09:59 ERROR config state=failed error="failed to load config file - ./cfg/config.toml"
[20:09:59] Process Exit with Code: 1

I've been banging my head on this for a few days and think I understand why. I have the following code in my PowerShell Profile.

Set-Location ~\Coding

If I remove that line from my version 5 profile, I get the following when I run Air via Task.

task: [default] air -c .air_windows.toml

  __    _   ___
 / /\  | | | |_)
/_/--\ |_| |_| \_ v1.62.0, built with Go go1.24.4

[20:18:47] watching .
[20:18:47] watching cfg
[20:18:47] watching db
[20:18:47] watching hud
[20:18:47] watching hud\api
[20:18:47] watching hud\api\embed
[20:18:47] watching hud\api\pausebutton
[20:18:47] watching hud\components
[20:18:47] watching hud\components\button
[20:18:47] watching hud\components\icon
[20:18:47] watching hud\components\spinner
[20:18:47] watching hud\css
[20:18:47] watching hud\hudstate
[20:18:47] watching hud\pages
[20:18:47] watching hud\stores
[20:18:47] watching hud\utils
[20:18:47] watching importer
[20:18:47] !exclude static
[20:18:47] !exclude tmp
[20:18:47] Proxy server listening on http://localhost:8080
[20:18:47] > task.exe templ
task: [templ] templ generate -lazy
(✓) Complete [ updates=12 duration=3.7713ms ]
[20:18:48] > task.exe css
task: [css] tailwindcss -i ./hud/css/input.tcss -o ../static/css/style.css
≈ tailwindcss v4.1.11

Done in 83ms
[20:18:49] building...
[20:18:49] CMD will not recognize non .exe file for execution, path: task build
task: [build] task build_windows
task: [build_windows] go build -o ./tmp/main.exe .
[20:18:49] !exclude .git
[20:18:49] !exclude .git
[20:18:50] running...
time=2025-07-13T20:18:50.582+01:00 level=INFO msg=main event=get_working_directory directory=C:\Users\simon\Coding\mysql-importer

It seems that the Set-Location in the profile is overriding the working directory in the PowerShell V5 sessions launched by Air. This plays havoc with any commands that are run as they are not in the correct directory.

In this instance, it isn't really a problem for me. I live in the V7 shell, not the V5 one. As a work around I can remove that line from my V5 profile.

I'm not sure how you would test for this. Alternatively, are you able to prepend each command run in PowerShell with a 'Set-Location' to the value from the 'root' entry in the config file.

Even if you cannot fix it, I thought I would raise this in case someone else hits this scenario.

Thanks
Simon

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions