Set-MsBuildDevEnvironment does not work if VsSetup is already installed #1575

Closed
opened 2026-01-30 22:30:57 +00:00 by claunia · 2 comments
Owner

Originally created by @adiviness on GitHub (Jun 9, 2019).

Originally assigned to: @DHowett-MSFT on GitHub.

Steps to reproduce

open up powershell, import-module on openconsole.psm1. Run Set-MsBuildDevEnvironment. It'll download VsSetup as a local module and import it. run powershell -noprofile and import openconsole.psm1 again, then run SetMsBuildDevEnvironment. It'll fail to find the path to VsSetup with error:

Get-ChildItem : Cannot find path 'C:\Users\austi\Documents\oss\terminal\tools\2.2.5' because it does not exist.
At C:\Users\austi\Documents\oss\terminal\tools\OpenConsole.psm1:44 char:9
+         Get-ChildItem -Path $versions[0] "$Name.psd1" | Import-Module
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\austi\...nal\tools\2.2.5:String) [Get-ChildItem], ItemNotFound
   Exception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Expected behavior

Setting up build tools should work

Actual behavior

error finding local module.

It looks like a pathing problem on the last line of Set-MsBuildDevEnvironment:

Get-ChildItem -Path $versions[0] "$Name.psd1" | Import-Module

Originally created by @adiviness on GitHub (Jun 9, 2019). Originally assigned to: @DHowett-MSFT on GitHub. <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Steps to reproduce open up powershell, `import-module` on openconsole.psm1. Run `Set-MsBuildDevEnvironment`. It'll download VsSetup as a local module and import it. run `powershell -noprofile` and import openconsole.psm1 again, then run `SetMsBuildDevEnvironment`. It'll fail to find the path to VsSetup with error: ``` Get-ChildItem : Cannot find path 'C:\Users\austi\Documents\oss\terminal\tools\2.2.5' because it does not exist. At C:\Users\austi\Documents\oss\terminal\tools\OpenConsole.psm1:44 char:9 + Get-ChildItem -Path $versions[0] "$Name.psd1" | Import-Module + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\austi\...nal\tools\2.2.5:String) [Get-ChildItem], ItemNotFound Exception + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand ``` # Expected behavior Setting up build tools should work # Actual behavior error finding local module. It looks like a pathing problem on the last line of `Set-MsBuildDevEnvironment`: `Get-ChildItem -Path $versions[0] "$Name.psd1" | Import-Module`
Author
Owner

@Arnatious commented on GitHub (Jun 19, 2019):

$versions = Get-ChildItem "$modules_root\$Name" | Sort-Object
When printed, versions shows the correct directory

λ  Write-Output $versions[0]


    Directory: C:\Users\arnat\Documents\Terminal\.PowershellModules\VSSetup


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        6/11/2019  10:40 PM                2.2.5

It looks like when $versions is passed as an argument to -Path it's converted to a string via $versions[0].ToString(), aka $versions[0].Name

Changing the call to Get-ChildItem -Path $versions[0].FullName "$Name.psd1" | Import-Module causes a different error

Import-Module : The specified module 'VSSetup.psm1' was not loaded because no valid module file was found in any
module directory.
At line:1 char:66
+ ... Item .\.PowershellModules\VSSetup\2.2.5\ VSSetup.psm1 | Import-Module
+                                                             ~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (VSSetup.psm1:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Wrapping that call in (...).FullName as well produces

New-Object : Cannot find type [Microsoft.VisualStudio.Setup.PowerShell.VersionTable]: verify that the assembly
containing this type is loaded.
At C:\Users\arnat\Documents\Terminal\.PowershellModules\VSSetup\2.2.5\VSSetup.psm1:5 char:6
+     (New-Object 'Microsoft.VisualStudio.Setup.PowerShell.VersionTable ...
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
@Arnatious commented on GitHub (Jun 19, 2019): `$versions = Get-ChildItem "$modules_root\$Name" | Sort-Object` When printed, versions shows the correct directory ``` λ Write-Output $versions[0] Directory: C:\Users\arnat\Documents\Terminal\.PowershellModules\VSSetup Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 6/11/2019 10:40 PM 2.2.5 ``` It looks like when $versions is passed as an argument to -Path it's converted to a string via `$versions[0].ToString()`, aka `$versions[0].Name` Changing the call to `Get-ChildItem -Path $versions[0].FullName "$Name.psd1" | Import-Module` causes a different error ``` Import-Module : The specified module 'VSSetup.psm1' was not loaded because no valid module file was found in any module directory. At line:1 char:66 + ... Item .\.PowershellModules\VSSetup\2.2.5\ VSSetup.psm1 | Import-Module + ~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (VSSetup.psm1:String) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand ``` Wrapping that call in `(...).FullName` as well produces ``` New-Object : Cannot find type [Microsoft.VisualStudio.Setup.PowerShell.VersionTable]: verify that the assembly containing this type is loaded. At C:\Users\arnat\Documents\Terminal\.PowershellModules\VSSetup\2.2.5\VSSetup.psm1:5 char:6 + (New-Object 'Microsoft.VisualStudio.Setup.PowerShell.VersionTable ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand ```
Author
Owner

@Arnatious commented on GitHub (Jun 19, 2019):

As a workaround, I manually ran

Install-Module VSSetup
Import-Module VSSetup

At this point, there were no errors running Set-MsbuildDevEnvironment

λ  Set-MsbuildDevEnvironment -v
VERBOSE: Searching for VC++ instances
VERBOSE: Setting up environment variables
@Arnatious commented on GitHub (Jun 19, 2019): As a workaround, I manually ran ``` Install-Module VSSetup Import-Module VSSetup ``` At this point, there were no errors running Set-MsbuildDevEnvironment ``` λ Set-MsbuildDevEnvironment -v VERBOSE: Searching for VC++ instances VERBOSE: Setting up environment variables ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#1575