dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.15k stars 1.74k forks source link

Resizetizer file access issues on Windows build in Visual Studio #23397

Closed SuperCorks closed 3 months ago

SuperCorks commented 3 months ago

Description

Recently I’ve been encountering this error with Resizetizer on build.

Severity    Code    Description Project File    Line    Suppression State
Error       Access to the path 'C:\Milliman\DEVL\MOBILE\MAUI\Milliman.Benefits\Milliman.Benefits\obj\Debug\net8.0-android\resizetizer\r\drawable\settings.png' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
   at System.IO.File.OpenFile(String path, FileAccess access, SafeFileHandle& handle)
   at System.IO.File.SetLastWriteTimeUtc(String path, DateTime lastWriteTimeUtc)
   at Microsoft.Maui.Resizetizer.ResizetizeImages.ExecuteAsync() in D:\a\_work\1\s\src\SingleProject\Resizetizer\src\ResizetizeImages.cs:line 105
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute() Milliman.Benefits   C:\Users\simon\.nuget\packages\microsoft.maui.resizetizer\8.0.40\buildTransitive\Microsoft.Maui.Resizetizer.After.targets   631 

This error started occuring a few builds after I updated to 17.9.7. I also get this error with 17.10 preview 7.

If I run dotnet build from the terminal alone I still get this error, but if I run dotnet clean before the build works fine. In visual studio the build never works even if I clean before. I tried rolling back to 17.9.6 and I still get the issue. See me reproducing the issue here: https://www.loom.com/share/8b4c17162bb54005a710a191a9e5d07c?sid=aede5d34-10f7-4f3c-ada2-29a17331b2e1

I also tried copying the project in another directory, same issue.

I'm also notiticing this only happens with .png files. Not svgs.

Steps to Reproduce

  1. Open the project attached
  2. Build in Visual Studio test-issue.zip

Link to public reproduction project repository

https://github.com/user-attachments/files/16069520/test-issue.zip

Version with bug

8.0.61 SR6.1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

Remove all png images from the project

Relevant log output

No response

github-actions[bot] commented 3 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

samhouts commented 3 months ago

@dellis1972

dellis1972 commented 3 months ago

@SuperCorks do any of your .png files have the readonly flag set?

SuperCorks commented 3 months ago

@dellis1972 yes. You got it. Thanks this solves the issue for me (partially)!

The project I'm working on is using TFVC, which adds this readonly flag unless you checkout the files for edit. I believe the resizetizer tool should copy the files during the build into the build directory but get rid of that readonly flag in the copied files.

What do you think?

dellis1972 commented 3 months ago

@SuperCorks yup we need to clear the flag. I'll get that sorted. Its something we hit on the andorid sdk a while back. Completely forgot about it when I put in these improvements.

SuperCorks commented 3 months ago

Awesome, thank you!

ninachen03 commented 3 months ago

I can repro this issue on the latest Visual Studio 17.11.0 Preview 2.1 (8.0.61 & 8.0.40) , not repro in build 17.11.0 Preview 2.1 (8.0.3) 17.11.0 Preview 2.1 (8.0.61 & 8.0.40): image 17.11.0 Preview 2.1 (8.0.3) image