5

I set some post-build commands in Visual Studio 2017 that should allow me to run a program that I currently have in System32 (wsl.exe). However, Visual Studio doesn't see the program.

I tried to set the command to dir C:\Windows\System32\ to see all the files it could list, and in fact it doesn't list over a 1'000 files out of the around 4'600 files I have there, including the wsl.exe file I'm trying to run. The number of files show up correctly when running the same command in the command prompt.

I've tried to run whoami as the post-build command, and it returns the same user as if I run the same command in the command prompt.

Am I missing something?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Peter
  • 121
  • 7
  • 1
    What does this have to do with Visual Studio? `wsl` is the *Windows Subsystem for Linux*. It's not just any executable. You *can* run it from any folder though, as it's in the path. Just type `wsl`. – Panagiotis Kanavos Sep 10 '18 at 08:20
  • This has to do with Visual Studio because it cannot see the `wsl` file at all when executing the `dir` command with it. I know I can run it from any folder, and because it was throwing the error `"wsl is not recognized as an internal or external command, operable program or batch file."` I've tried more steps and came to the conclusion that running `dir` in the post-build commands, it didn't show all the files in the directory. All of this while I can see the file correctly using the Windows command prompt – Peter Sep 10 '18 at 08:23
  • 1) no repro. I can see it and call it just fine 2) It has nothing to do with VS. `dir` is a command-line command. You are asking why you can't see some files in System32, without specifying what those files are. 3) What `wsl`? Does it even exist? Is it installed? Are you trying to start a Unix shell from your post-build step? – Panagiotis Kanavos Sep 10 '18 at 08:25
  • About your number 2): then how come running the `dir`command in VS does not show the wsl.exe file, while running `ls -al /mnt/c/Windows/System32` in WSL shows it, and in command prompt running `dir C:\Windows\System32\` shows it as well. For your number 3): I've clarified that in the post saying that indeed **I currently have in System32 (wsl.exe)**, so yes, it does exist. – Peter Sep 10 '18 at 08:29
  • possible duplicate of [Kicking off a WSL bash-based build from Visual Studio 2015](https://stackoverflow.com/q/38231537/995714) – phuclv Sep 10 '18 at 09:14

1 Answers1

8

Visual Studio itself is 32-bit application. As such, the OS shims the application behavior to a different view of the Windows and System32 folders. i.e c:\Windows\System32 in the application is actually the c:\Windows\SysWow64 folder for 32-bit apps. That explains why it can't see the wsl.exe binary... Not sure what the workaround is... looking into this...

selbie
  • 100,020
  • 15
  • 103
  • 173
  • `wsl` is the Windows Subsystem for Linux. It's not missing either, running `dir wsl.exe` inside System32 works, assuming the feature is installed of course. In any case the OP shouldn't put anything in System32. – Panagiotis Kanavos Sep 10 '18 at 08:22
  • Not "putting anything in System32". WSL was automatically installed there using the Programs and Features in the Control Panel. Still, will try, @selbie – Peter Sep 10 '18 at 08:25
  • @PeterAS17 you haven't explained what you are trying to do. Or what `WSL` you refer to. I can start WSL, the Windows Subsystem for Linux, just fine by typing `wsl` in *any* console. I can see it just fine with `dir` after changing the current directory to `C:\Windows\System32`. I can also see it with `dir c:\Windows\system32\wsl.exe`. – Panagiotis Kanavos Sep 10 '18 at 08:27
  • @PanagiotisKanavos to clarify the output on each side: VS shows "File not found" using the `dir c:\Windows\system32\wsl.exe`. Command prompt shows the file: `06.09.2018 15:02 114 688 wsl.exe` – Peter Sep 10 '18 at 08:31
  • 1
    @PeterAS17 your *real* question was how to run a Linux build step. This is already answered [in this duplicate question](https://stackoverflow.com/questions/38231537/kicking-off-a-wsl-bash-based-build-from-visual-studio-2015) – Panagiotis Kanavos Sep 10 '18 at 08:36
  • @selbie You're absolutely right... I didn't pay attention to the fact that VS was a 32-bit application and ignored the fact that it pointed to the SysWow64 folder. Copying and pasting the needed files for the post-build command seems to have done the job for now. Gotta search for a better workaround if any. Thanks! – Peter Sep 10 '18 at 08:36
  • 4
    [File System Redirector](https://learn.microsoft.com/en-us/windows/desktop/winprog64/file-system-redirector): "32-bit applications can access the native system directory by substituting %windir%\Sysnative for %windir%\System32. WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access." – Damien_The_Unbeliever Sep 10 '18 at 08:36