nushell / nu_scripts

A place to share Nushell scripts with each other
MIT License
743 stars 227 forks source link

add silent option to nu_msvs #910

Closed sadguitarius closed 3 months ago

sadguitarius commented 3 months ago

I like to activate nu_msvs in my config by default and don't need a message that tells me the command has been run when doing this. This commit adds a --silent option so there's no message displayed when running the command.

fdncred commented 3 months ago

I'm fine with that, thanks! Just FYI - I've noticed that some things may still not right with this script. I haven't put my finger on it yet but sometimes I still can't compile different things but when I run Developer PowerShell for VS 2022 from within Windows Terminal, everything works fine. I'm wondering if there are more env vars that we're missing. It would be cool to be able to diff environments somehow.

sadguitarius commented 3 months ago

Thanks, that was quick! I had my own variation going for a while that was based on this one with a few changes. I think I had the environment variables matching a little better, at least on my setup, but I'm not sure how much it actually mattered since things were compiling fine either way. When I was working on it, I just manually checked what the vcvarsall script did to the environment in PowerShell. I just went back to this script since it's been updated recently. Here's my version, you're welcome to check it and add whatever you want that makes sense.

https://gist.github.com/sadguitarius/df47ca902836d0ff20171c37fcee5e85

fdncred commented 3 months ago

Your comment made me remember that I wrote this that calls vsdevcmd.bat and just sucks in the env vars. It seemed to work better for me but it's not as fancy using vswhere and such.

print "Loading MSVS environment variables"
let op = run-external "cmd" "/c" "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Common7\\Tools\\VsDevCmd.bat" "-startdir=none" "-arch=x64" "-host_arch=x64" "&&" "set"
$op | lines | skip 4 | parse "{key}={value}" | where key != PWD | transpose -ird | load-env

$env.Path = if "Path" in $env {($env.Path | split row (char esep))}
$env.PSModulePath = if "PSModulePath" in $env {($env.PSModulePath | split row (char esep))}
$env.INCLUDE = if "INCLUDE" in $env {($env.INCLUDE | split row (char esep))}
$env.__VSCMD_PREINIT_PATH = if "__VSCMD_PREINIT_PATH" in $env {($env.__VSCMD_PREINIT_PATH | split row (char esep))}
$env.LIBPATH = if "LIBPATH" in $env {($env.LIBPATH | split row (char esep))}
$env.LIB = if "LIB" in $env {($env.LIB | split row (char esep))}
$env.EXTERNAL_INCLUDE = if "EXTERNAL_INCLUDE" in $env {($env.EXTERNAL_INCLUDE | split row (char esep))}
sadguitarius commented 3 months ago

Thanks, I'll check it out!