PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.85k stars 373 forks source link

Build script does not find installed Dotnet on Mac (using Brew) #1916

Closed gwerbin closed 1 year ago

gwerbin commented 1 year ago

I installed Dotnet using Brew but the installer doesn't seem to find it. The version listed in Get-Command is 0.0.0, so maybe that's the problem. I think it's unlikely that this is solely a downstream packaging bug, because I also tried with Macports and had the same problem, as well as installing both the Brew "formula" and "cask" versions.

Steps to reproduce

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install --cask powershell dotnet
git clone 'https://github.com/PowerShell/PSScriptAnalyzer'
cd PSScriptAnalyzer
pwsh ./build.ps1

Expected behavior

Installer finds the Brew-installed Dotnet and uses it

Actual behavior

The installer can't find Dotnet, so it downloads and installs a fresh Dotnet runtime in my home directory.

VERBOSE: checking non-Windows /<redacted>/.dotnet/dotnet
WARNING: Could not find dotnet executable
WARNING: Dotnet executable not found
Web request status [Web request completed. (Number of bytes processed: 58824)                                        ]
...  etc

Environment data

> Get-Command -CommandType Application dotnet -ErrorAction SilentlyContinue -All

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     dotnet                                             0.0.0.0    /opt/homebrew/bin/dotnet
> dotnet --list-sdks
7.0.203 [/opt/local/share/dotnet/sdk]
> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.4
PSEdition                      Core
GitCommitId                    7.3.4
OS                             Darwin 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }

# N/A
SydneyhSmith commented 1 year ago

Thanks @gwerbin we require a specific version of dotnet to build PSSA which is why we install it again, we are not using the latest dotnet

SydneyhSmith commented 1 year ago

If you know the version of dotnet you have that may be helpful

gwerbin commented 1 year ago

If you know the version of dotnet you have that may be helpful

Is that something different than this output?

> dotnet --list-sdks
7.0.203 [/opt/local/share/dotnet/sdk]
gwerbin commented 1 year ago

Hi, I hate to be difficult about this, but I don't feel like this question was answered at all. I tried to provide all relevant information, please let me know if there's anything else I should add here. I know very little about Dotnet, so I apologize if I omitted something that should be obvious.

gwerbin commented 1 year ago

Is there something I can do to prevent the bot from closing this?

@SydneyhSmith I saw you re-opened this for me before. Is there any additional information I can provide that would help here?

bergmeister commented 1 year ago

I've found it to not work on Windows as well, suggestion is to install manually, this is just there to work in CI.

gwerbin commented 1 year ago

@bergmeister what does "manually" mean? As above, I'm not a .NET or C# developer and I was just trying to follow instructions. I'll be happy for any pointers to books, guides, etc. that would help me actually use this tool. We have several internal PS1 scripts that I would strongly like to subject to static analysis, having found bugs in the past. We use Shellcheck for the same purpose on Unix shell scripts.