Redth / dotnet-maui-check

.NET MAUI Check tool
MIT License
479 stars 79 forks source link

zsh on macOS leads to 'zsh:1: command not found: PACKAGE_SOURCE_NUGET_ORG' #156

Open flennic opened 2 years ago

flennic commented 2 years ago

Hey,

when trying to execute maui-check on macOS (intel) within a zsh, the installation raises the following issue:

⏳ Attempting to fix: .NET SDK - Workloads (6.0.301)
SHELL: /bin/zsh /var/folders/jr/jj_6h9hd76q6kp3szcd3zjjw0000gn/T/tmpzUAKsP.tmp
zsh:1: command not found: PACKAGE_SOURCE_NUGET_ORG
Password:

which is due to the issue that within the *manifest.json files $() (command substitution) is used instead of ${} (parameter substitution) which works in bash but not within zsh, see:

MYDIR=.
ls $(MYDIR)

does not work in zsh, but

MYDIR=.
ls ${MYDIR}

works fine in both.

This is the root cause, however, to show the actual error, here the stack trace when continuing:

Unhandled exception: System.ArgumentException: The path is empty. (Parameter 'path')
   at System.IO.Path.GetFullPath(String path)
   at Microsoft.DotNet.Cli.NuGetPackageDownloader.PackageSourceLocation.ExpandLocalFeed(String[] sourceFeedOverrides)
   at Microsoft.DotNet.Workloads.Workload.Install.WorkloadInstallCommand..ctor(ParseResult parseResult, IReporter reporter, IWorkloadResolver workloadResolver, IInstaller workloadInstaller, INuGetPackageDownloader nugetPackageDownloader, IWorkloadManifestUpdater workloadManifestUpdater, String dotnetDir, String userProfileDir, String tempDirPath, String version, IReadOnlyCollection`1 workloadIds)
   at Microsoft.DotNet.Cli.WorkloadInstallCommandParser.<>c.<ConstructCommand>b__14_0(ParseResult parseResult)
   at Microsoft.DotNet.Cli.ParseResultCommandHandler.Invoke(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()
Fix failed - Workload Install failed: `dotnet workload install --from-rollback-file 
"/var/folders/jr/jj_6h9hd76q6kp3szcd3zjjw0000gn/T/maui-check-cbd22571/workload.json" android ios maccatalyst tvos macos maui --source
"$(PACKAGE_SOURCE_NUGET_ORG)"`
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

🔔 There were one or more problems detected.
Please review the errors and correct them and run maui-check again.

I tried to fix the issue by replacing the parentheses locally with curly braces and hard-coding the file path instead of the given manifest url to enforce the program to read in the new values. However, I run into all sorts of problems, the latest occurring at BootsSolution.cs:32 which fails with

⏳ Attempting to fix: .NET SDK
  Installing .NET SDK 6.0.400-rtm.22371.2...
System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
  at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()                                     
  at Boots.Core.HttpClientWithPolicy.DoDownloadAsync(Uri uri, String tempFile, CancellationToken token)
  at Polly.AsyncPolicy.<>c__DisplayClass40_0.<<ImplementationAsync>b__0>d.MoveNext()                   
  ⚠ Installation failed for .NET SDK 6.0.400-rtm.22371.2.
System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
  at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()                                     
  at Boots.Core.HttpClientWithPolicy.DoDownloadAsync(Uri uri, String tempFile, CancellationToken token)
  at Polly.AsyncPolicy.<>c__DisplayClass40_0.<<ImplementationAsync>b__0>d.MoveNext()                   
Fix failed - Response status code does not indicate success: 404 (Not Found).

❌ Skipped: .NET SDK - Workload Deduplication

❌ Skipped: .NET SDK - Workloads (6.0.400-rtm.22371.2)
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Checkup had Error status: xcode
Checkup had Error status: dotnet

xcode: Found invalid data while decoding.
dotnet: .NET SDK (6.0.400-rtm.22371.2) not installed.
🔔 There were one or more problems detected.
Please review the errors and correct them and run maui-check again.

I already spent some time with the code base and would rather ask for some help before spending more time on a thing I assume should be presumably easy to fix. I am willing to create a PR, but would like to have some feedback on the planned changes and the error shown above.

Regards, flennic

saha1506 commented 2 years ago

Same error here

image
bbenetskyy commented 2 years ago

@flennic I try to run failed command with the PACKAGE_SOURCE_NUGET_ORG value found in this repo:

sudo dotnet workload install android ios maccatalyst tvos macos maui --source "https://api.nuget.org/v3/index.json"

This install for me all that - which was failed

berkayyerdelen commented 2 years ago

any update regarding this topic?

fusionconsulting commented 2 years ago

Any updates? Same issue here.

robbobby commented 2 years ago

Same issue, watching for updates / workarounds on this

dannyyy commented 2 years ago

Same here, seems there is no fix to expect. :(

kylewolford commented 1 year ago

I still get the error, even after running chsh -s /bin/bash to switch my default shell to bash.

nielscup commented 1 year ago

Same issue.

zhangcheng commented 1 year ago

@flennic I try to run failed command with the PACKAGE_SOURCE_NUGET_ORG value found in this repo:

sudo dotnet workload install android ios maccatalyst tvos macos maui --source "https://api.nuget.org/v3/index.json"

This install for me all that - which was failed

The above command doesn't work in my case. Getting the error:

Workload ID android is not recognized.

By checking the maui-check error log, seems that a workload.json file is needed, so I tweaked a bit as:

sudo /usr/local/share/dotnet/dotnet workload install --from-rollback-file "/var/folders/bq/tk6w3xfx7md9tlj7hjrbl8w00000gn/T/maui-check-d9799fb5/workload.json" android ios maccatalyst tvos macos maui --source "https://api.nuget.org/v3/index.json"

of 'coz the temp location for workload.json varies every time.

And now at least it works on me:

...
Installing workload manifest microsoft.net.sdk.android version 32.0.440…
Installing workload manifest microsoft.net.sdk.ios version 16.2.19…
Installing workload manifest microsoft.net.sdk.maccatalyst version 16.2.19…
Installing workload manifest microsoft.net.sdk.tvos version 16.1.257…
Installing workload manifest microsoft.net.sdk.macos version 13.1.19…
Installing workload manifest microsoft.net.sdk.maui version 6.0.419…
...
Garbage collecting for SDK feature band(s) 6.0.400...

Successfully installed workload(s) android ios maccatalyst tvos macos maui.
zhangcheng commented 1 year ago

I still get the error, even after running chsh -s /bin/bash to switch my default shell to bash.

Switching default shell won't work, 'coz the maui-check tool will stick with zsh. Its error is like:

SHELL: /bin/zsh /var/folders/bq/tk6w3xfx7md9tlj7hjrbl8w00000gn/T/tmpxC4Rw6.tmp
zsh:1: command not found: PACKAGE_SOURCE_NUGET_ORG

The content inside /var/folders/bq/tk6w3xfx7md9tlj7hjrbl8w00000gn/T/tmpxC4Rw6.tmp is like:

'/bin/zsh' -c 'sudo /usr/local/share/dotnet/dotnet workload install --from-rollback-file "/var/folders/bq/tk6w3xfx7md9tlj7hjrbl8w00000gn/T/maui-check-d9799fb5/workload.json" android ios maccatalyst tvos macos maui --source "$(PACKAGE_SOURCE_NUGET_ORG)"'

Instead, see whether the trick in my previous comment works for you. @kylewolford

renatosc commented 1 year ago

same issue here.

renatosc commented 1 year ago

Ok, I found the issue.

The code was supposed to replace the placeholder $(PACKAGE_SOURCE_NUGET_ORG) in the manifest with the value of the variable "PACKAGE_SOURCE_NUGET_ORG" that is also defined in the manifest. The are 2 instances of that placeholder in the manifest (under "variableMappers" and "dotnet"->"sdks"), the first replace was ocurring fine but the second was failing due to the type associated to it. The DotNetSdk.cs file is defining PackageSources of type List<string> but that type fails in the check that happens on Check.cs:70/71 if (!prop.CanWrite) continue;

The fix was to have PackageSources defined of type string[] (as it is in the class NuGetFeedVariableMapper.cs where the replace occurs fine).

Here is the PR that fixes that: https://github.com/Redth/dotnet-maui-check/pull/164