Skip to content

fix nu_msvs #1116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2025
Merged

fix nu_msvs #1116

merged 2 commits into from
May 15, 2025

Conversation

Arthapz
Copy link
Contributor

@Arthapz Arthapz commented May 5, 2025

nu_msvs doesn't work at all on my setup, vswhere return empty string when called from nushell, the only way i made it to work is calling it from powershell

on json parsing side
installationPath is not an array, and vswhere return an array of installations is not correct

e.g

[
  {
    "instanceId": "406fd398",
    "installDate": "2024-04-25T13:16:29Z",
    "installationName": "VisualStudioPreview/17.14.0-pre.5.0+36025.13",
    "installationPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\Preview",
    "installationVersion": "17.14.36025.13",
    "productId": "Microsoft.VisualStudio.Product.BuildTools",
    "productPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\Preview\\Common7\\Tools\\LaunchDevCmd.bat",
    "state": 4294967295,
    "isComplete": true,
    "isLaunchable": true,
    "isPrerelease": true,
    "isRebootRequired": false,
    "displayName": "Visual Studio Build Tools 2022",
    "description": "Visual Studio Build Tools vous permet de générer des applications MSBuild natives et managées sans passer par l'IDE Visual Studio. Il existe des options pour installer les compilateurs et bibliothèques Visual C++, ainsi que la prise en charge d'ATL, de MFC et de C++/CLI.",
    "channelId": "VisualStudio.17.Preview",
    "channelUri": "https://aka.ms/vs/17/pre/channel",
    "enginePath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\resources\\app\\ServiceHub\\Services\\Microsoft.VisualStudio.Setup.Service",
    "installedChannelId": "VisualStudio.17.Preview",
    "installedChannelUri": "https://aka.ms/vs/17/pre/channel",
    "releaseNotes": "https://go.microsoft.com/fwlink/?LinkId=661273#17.14.0-pre.5.0",
    "resolvedInstallationPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\Preview",
    "thirdPartyNotices": "https://go.microsoft.com/fwlink/?LinkId=661288",
    "updateDate": "2025-04-29T20:49:54.8401699Z",
    "catalog": {
      "buildBranch": "d17.14",
      "buildVersion": "17.14.36025.13",
      "id": "VisualStudioPreview/17.14.0-pre.5.0+36025.13",
      "localBuild": "build-lab",
      "manifestName": "VisualStudioPreview",
      "manifestType": "installer",
      "productDisplayVersion": "17.14.0 Preview 5.0",
      "productLine": "Dev17",
      "productLineVersion": "2022",
      "productMilestone": "Preview",
      "productMilestoneIsPreRelease": "True",
      "productName": "Visual Studio",
      "productPatchVersion": "0",
      "productPreReleaseMilestoneSuffix": "5.0",
      "productSemanticVersion": "17.14.0-pre.5.0+36025.13",
      "requiredEngineVersion": "3.14.2074.57458"
    },
    "properties": {
      "campaignId": "",
      "channelManifestId": "VisualStudio.17.Preview/17.14.0-pre.5.0+36025.13",
      "includeRecommended": "0",
      "nickname": "",
      "setupEngineFilePath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\setup.exe"
    }
  }
]

@fdncred
Copy link
Contributor

fdncred commented May 5, 2025

I'd rather not call powershell. This is what I do

let vswhere = $'($env."ProgramFiles(x86)")\Microsoft Visual Studio\Installer\vswhere.exe'
let installPath = ^$vswhere -latest -property installationPath
let vsdevcmd = $'($installPath)\Common7\Tools\vsdevcmd.bat'
let op = run-external $env.comspec "/c" $vsdevcmd "-no_logo" "-startdir=none" "-arch=x64" "-host_arch=x64" "&&" "set"
$op | decode utf8 | lines | parse "{key}={value}" | where key != PWD and key != FILE_PWD and key != CURRENT_FILE | transpose -ird | load-env

$env.EXTERNAL_INCLUDE = if "EXTERNAL_INCLUDE" in $env {($env.EXTERNAL_INCLUDE | split row (char esep) | uniq)}
$env.INCLUDE = if "INCLUDE" in $env {($env.INCLUDE | split row (char esep) | uniq)}
$env.LIB = if "LIB" in $env {($env.LIB | split row (char esep) | uniq)}
$env.LIBPATH = if "LIBPATH" in $env {($env.LIBPATH | split row (char esep) | uniq)}
$env.Path = if "Path" in $env {($env.Path | split row (char esep) | uniq)}
$env.PATHEXT = if "PATHEXT" in $env {($env.PATHEXT | split row (char esep) | uniq)}
$env.PSModulePath = if "PSModulePath" in $env {($env.PSModulePath | split row (char esep) | uniq)}
$env.WindowsLibPath = if "WindowsLibPath" in $env {($env.WindowsLibPath | split row (char esep) | uniq)}
$env.__VSCMD_PREINIT_PATH = if "__VSCMD_PREINIT_PATH" in $env {($env.__VSCMD_PREINIT_PATH | split row (char esep) | uniq)}

@Arthapz
Copy link
Contributor Author

Arthapz commented May 7, 2025

I'd rather not call powershell. This is what I do

let vswhere = $'($env."ProgramFiles(x86)")\Microsoft Visual Studio\Installer\vswhere.exe'
let installPath = ^$vswhere -latest -property installationPath
let vsdevcmd = $'($installPath)\Common7\Tools\vsdevcmd.bat'
let op = run-external $env.comspec "/c" $vsdevcmd "-no_logo" "-startdir=none" "-arch=x64" "-host_arch=x64" "&&" "set"
$op | decode utf8 | lines | parse "{key}={value}" | where key != PWD and key != FILE_PWD and key != CURRENT_FILE | transpose -ird | load-env

$env.EXTERNAL_INCLUDE = if "EXTERNAL_INCLUDE" in $env {($env.EXTERNAL_INCLUDE | split row (char esep) | uniq)}
$env.INCLUDE = if "INCLUDE" in $env {($env.INCLUDE | split row (char esep) | uniq)}
$env.LIB = if "LIB" in $env {($env.LIB | split row (char esep) | uniq)}
$env.LIBPATH = if "LIBPATH" in $env {($env.LIBPATH | split row (char esep) | uniq)}
$env.Path = if "Path" in $env {($env.Path | split row (char esep) | uniq)}
$env.PATHEXT = if "PATHEXT" in $env {($env.PATHEXT | split row (char esep) | uniq)}
$env.PSModulePath = if "PSModulePath" in $env {($env.PSModulePath | split row (char esep) | uniq)}
$env.WindowsLibPath = if "WindowsLibPath" in $env {($env.WindowsLibPath | split row (char esep) | uniq)}
$env.__VSCMD_PREINIT_PATH = if "__VSCMD_PREINIT_PATH" in $env {($env.__VSCMD_PREINIT_PATH | split row (char esep) | uniq)}

same problem, installPath is empty on my setup
{3A58E403-B079-428E-8C80-72DEF680417A}

only powershell instance make it work

@fdncred
Copy link
Contributor

fdncred commented May 7, 2025

My guess is that it's because you're using different parameters in your PR (like -prerelease and -products *)

$'($vswhere_cmd_ps) -prerelease -products * -format json -nocolor -utf8 -sort' 

in nushell, you'd have to have the * in quotes like

$^vswhere_cmd -prerelease -products '*' -format json -nocolor -utf8 -sort'

What happens if you just run ^$vswhere from my code snippet? According to Microsoft's wiki, it should be finding vswhere properly.

Maybe you have an old version? Seems like 1.0.50 may be required?

or maybe I need to change it like it does here? https://github.com/microsoft/vswhere/wiki/Find-VC#batch or https://github.com/microsoft/vswhere/wiki/Start-Developer-Command-Prompt#using-batch

@Arthapz
Copy link
Contributor Author

Arthapz commented May 15, 2025

My guess is that it's because you're using different parameters in your PR (like -prerelease and -products *)

$'($vswhere_cmd_ps) -prerelease -products * -format json -nocolor -utf8 -sort' 

in nushell, you'd have to have the * in quotes like

$^vswhere_cmd -prerelease -products '*' -format json -nocolor -utf8 -sort'

What happens if you just run ^$vswhere from my code snippet? According to Microsoft's wiki, it should be finding vswhere properly.

Maybe you have an old version? Seems like 1.0.50 may be required?

or maybe I need to change it like it does here? https://github.com/microsoft/vswhere/wiki/Find-VC#batch or https://github.com/microsoft/vswhere/wiki/Start-Developer-Command-Prompt#using-batch

you're right, the '*' thing was the issue, i've updated the PR to remove powershell, now it only fixes the json structure

@fdncred
Copy link
Contributor

fdncred commented May 15, 2025

Thanks. This is better than before.

@fdncred fdncred merged commit b2d512f into nushell:main May 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants