getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
604 stars 206 forks source link

[iOS] Path too long for MAUI device connected deploys #2363

Closed espenrl closed 1 year ago

espenrl commented 1 year ago

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

Setup MAUI .NET 7 service release 6 with Sentry and deploy from Visual Studio to a usb connected IPhone.

NOTE: This is a compound issue by Sentry NuGet having files in a deep folder structure and MAUI SDK tooling generating longer paths than needed.

Expected Result

Deployment to go an without error.

Actual Result

Fails with MSB3021 The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Severity Code Description Project File Line Suppression State Error MSB3021 Unable to copy file "C:\Users\xxxx\.nuget\packages\sentry.bindings.cocoa\3.31.0\lib\net6.0-ios16.1\Sentry.Bindings.Cocoa.resources\Sentry.xcframework\ios-arm64_x86_64-simulator\dSYMs\Sentry-iPhoneSimulator.dSYM\Contents\Resources\DWARF\Sentry" to "C:\Users\xxxx\AppData\Local\Temp\Xamarin\HotRestart\Signing\Naturoppdrag.app\out\Payload\Naturoppdrag.app\Naturoppdrag.content\Sentry.Bindings.Cocoa.resources\Sentry.xcframework\ios-arm64_x86_64-simulator\dSYMs\Sentry-iPhoneSimulator.dSYM\Contents\Resources\DWARF\Sentry". The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. Naturoppdrag C:\Program Files\dotnet\packs\Microsoft.iOS.Windows.Sdk\16.4.7054\tools\msbuild\iOS\Xamarin.iOS.HotRestart.targets 273

Product Area

Other

Link

No response

DSN

No response

Version

3.31.0

getsantry[bot] commented 1 year ago

Assigning to @getsentry/support for routing, due by (sfo). ⏲️

espenrl commented 1 year ago

It's reported to Microsoft at https://github.com/xamarin/xamarin-macios/issues/18259

mattjohnsonpint commented 1 year ago

This is related to #1961 - which I applied a workaround for in #2047.

The corresponding Microsoft issue is https://github.com/xamarin/xamarin-macios/issues/16571 - which was going to be patched by a similar approach to my workaround, but they went with a different approach for .NET 8 - see recent comment: https://github.com/xamarin/xamarin-macios/pull/16605#issuecomment-1538605649

I never ran into long file path issues, but I can see how they could occur. I'll investigate if we can update our workaround.

In the meantime, here are a couple of things you might consider:

espenrl commented 1 year ago

I managed to find a workaround by editing C:\Users\xxxx\.nuget\packages\sentry.bindings.cocoa\3.31.0\lib\net6.0-ios16.1\Sentry.Bindings.Cocoa.resources\Sentry.xcframework\Info.plist.

I changed LibraryIdentifier value ios-arm64_x86_64-simulator to simulator and renamed the folder in the same directory accordingly. That makes the path go below the required 260 characters. Barely, but it's enough. I don't really know if this affects Sentry, but at least I can get the app running (Sentry is important in production).

espenrl commented 1 year ago

It doesn't seem that simulator files are even needed for hot restart.

https://github.com/xamarin/xamarin-macios/blob/3bc4dfde9f88c803628439aa98c593557cc355db/msbuild/Xamarin.Shared/Xamarin.Shared.targets#L1768-L1771

espenrl commented 1 year ago

HotRestartPackageResourcesDir logic doesn't run as the files are not zipped inside the NuGet.

image

And now I finally understand why I haven't experienced this problem until now. I recently removed MacCatalyst as a build target.

espenrl commented 1 year ago

In the end the paths are long, and given a longer app name than Naturoppdrag and a longer Windows username than my four characters there is bound to be issues. The app name counts 3 times in the path.

C:\Users\xxxx\AppData\Local\Temp\Xamarin\HotRestart\Signing\Naturoppdrag.app\out\Payload\Naturoppdrag.app\Naturoppdrag.content\Sentry.Bindings.Cocoa.resources\Sentry.xcframework\ios-arm64_x86_64-simulator\dSYMs\Sentry-iPhoneSimulator.dSYM\Contents\Resources\DWARF\Sentry

mattjohnsonpint commented 1 year ago

I'm glad you have a workaround, and thanks for the feedback! I'll keep this issue open so we can find a way to address it internally.

mattjohnsonpint commented 1 year ago

I was able to reproduce this. And you're right - it doesn't have to do with our own hot restart workaround logic.

The easiest actual workaround I can find is to enable log file paths in windows. Change the registry value mentioned, and then restart Visual Studio for it to take effect. I tested with that enabled, and it seems to resolve the problem.

I'll continue to look for a more elegant solution. Ideally, the simulator files would not be included for Hot Restart builds. But I'm not seeing an easy way to exclude them for Hot Restart and still have them available when actually running in a simulator.

mattjohnsonpint commented 1 year ago

I found a way to remove the simulator native resources from the Hot Restart builds. They're not needed there, and removing them avoids the max path issue. The fix is in #2384, and will be included with the next release. Thanks.

espenrl commented 1 year ago

Thanks @mattjohnsonpint

mattjohnsonpint commented 1 year ago

This has been released with our 3.32.0 release. Thanks - and please let us know if you run into any other issues.

GBrienza commented 1 year ago

@mattjohnsonpint Hi there , we are evaluating Sentry as an alternative to AppCenter and we have encountered issue with long path on windows attached to a physical iOS device , so I enabled long path on windows but now I get below, bcse of this we have not been in a position to evaluate any further. Any suggestions?

Windows 11 – Visual Studio 2022 17.6.3 Sentry.Maui Version 3.33.1

Unable to remove directory "C:\Users\gb\AppData\Local\Temp\Xamarin\HotRestart\Signing\ SampleAppSentry.app\out\". Could not find a part of the path 'C:\Users\gb\AppData\Local\Temp\Xamarin\HotRestart\Signing\ SampleAppSentry.app\out\Payload\SampleAppSentry.app\SampleAppSentry.content\Sentry.Bindings.Cocoa.resources\Sentry.xcframework\ios-arm64\dSYMs\Sentry-iPhoneOS.dSYM\Contents\Resources\DWARF'. SampleAppSentry C:\Program Files\dotnet\packs\Microsoft.iOS.Windows.Sdk\16.4.7067\tools\msbuild\iOS\Xamarin.iOS.HotRestart.targets

bitsandfoxes commented 1 year ago

Hey @GBrienza A wild guess: The space as part of the path is intentional?

GBrienza commented 1 year ago

Hi @bitsandfoxes I did not leave any space intentionally.

bitsandfoxes commented 1 year ago

The SampleAppSentry.app seems to have a leading whitespace. Could you try running without just so we can exclude that from the "might be a cause" list? Thanks!

GBrienza commented 1 year ago

@bitsandfoxes
Hi All I did was

  1. Create a new Maui App
  2. Add Sentry.Maui 3.34
  3. modify Maui.Program
  4. Plug the iOS device
  5. Use the .net automatic prov profile
  6. build the app and I get below

Severity Code Description Project File Line Suppression State Error MSB3231 Unable to remove directory "C:\Users\usernamehere\AppData\Local\Temp\Xamarin\HotRestart\Signing\SampleAppSentry.app\out\". Could not find a part of the path 'C:\Users\usernamehere\AppData\Local\Temp\Xamarin\HotRestart\Signing\SampleAppSentry.app\out\Payload\SampleAppSentry.app\SampleAppSentry.content\Sentry.Bindings.Cocoa.resources\Sentry.xcframework\ios-arm64\dSYMs\Sentry-iPhoneOS.dSYM\Contents\Resources\DWARF'. SampleAppSentry C:\Program Files\dotnet\packs\Microsoft.iOS.Windows.Sdk\16.4.7089\tools\msbuild\iOS\Xamarin.iOS.HotRestart.targets 359

Hope is of any help

bruno-garcia commented 1 year ago

Looking at the error message:

Severity Code Description Project File Line Suppression State Error MSB3231 Unable to remove directory "C:\Users\usernamehere\AppData\Local\Temp\Xamarin\HotRestart\Signing\SampleAppSentry.app\out". Could not find a part of the path 'C:\Users\usernamehere\AppData\Local\Temp\Xamarin\HotRestart\Signing\SampleAppSentry.app\out\Payload\SampleAppSentry.app\SampleAppSentry.content\Sentry.Bindings.Cocoa.resources\Sentry.xcframework\ios-arm64\dSYMs\Sentry-iPhoneOS.dSYM\Contents\Resources\DWARF'. SampleAppSentry C:\Program Files\dotnet\packs\Microsoft.iOS.Windows.Sdk\16.4.7089\tools\msbuild\iOS\Xamarin.iOS.HotRestart.targets 359

This seems to me different than the original issue with path too long. Seems like something in the build tried to remove the path C:\Users\usernamehere\AppData\Local\Temp\Xamarin\HotRestart\Signing\SampleAppSentry.app\out\Payload\SampleAppSentry.app\SampleAppSentry.content\Sentry.Bindings.Cocoa.resources\Sentry.xcframework\ios-arm64\dSYMs\Sentry-iPhoneOS.dSYM\Contents\Resources\DWARF but it choked already when it got to ../out because that didn't exist. Probably best to create a new ticket to track that problem. And close this issue again.

jamescrosswell commented 1 year ago

I've opened https://github.com/getsentry/sentry-dotnet/issues/2567. Closing this issue again then.