MAUI 8.0应用突然无法编译:Resizetizer中图片访问被拒绝
MAUI .NET 8 Android/iOS编译报错:文件访问被拒(Resizetizer相关)
我的MAUI Android/iOS 8.0应用突然无法编译,抛出文件访问被拒的异常,报错的PNG文件名随机变化:
Severity Code Description Project File Line Suppression State Error (active) Access to the path 'C:\...\obj\Debug\net8.0-android\resizetizer\r\drawable\....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() MercatorPenguinMaui (net8.0-android) C:\Nugets\microsoft.maui.resizetizer\8.0.40\buildTransitive\Microsoft.Maui.Resizetizer.After.targets 631
已尝试的排查步骤:
- 多次删除bin和obj文件夹
- 重启电脑
- 删除NuGet缓存目录所有包并重启
- 检查项目中是否存在同名(不含扩展名)图片文件
- 以管理员身份运行Visual Studio
相同代码在其他电脑可正常编译,未修改的旧项目也出现同样问题,使用Visual Studio 17.10.3。
额外解决方法尝试
清理锁定进程
打开任务管理器,结束dotnet.exe、msbuild.exe等可能占用编译目录文件的进程,再重新编译。调整Resizetizer文件共享配置
在项目的.csproj文件中添加以下配置,放宽文件共享权限:<PropertyGroup> <ResizetizerFileShare>ReadWriteDelete</ResizetizerFileShare> </PropertyGroup>禁用增量编译
临时关闭增量编译,在.csproj中添加:<PropertyGroup> <DisableIncrementalBuild>true</DisableIncrementalBuild> </PropertyGroup>编译完成后可恢复设置。
更新MAUI NuGet包
将Microsoft.Maui.Resizetizer及相关MAUI依赖包更新到最新稳定版(如8.0.60+),旧版本可能存在文件锁定bug。排查杀毒软件干扰
临时关闭Windows Defender或第三方杀毒软件的实时保护,尝试编译。若生效,将项目的obj、bin目录加入杀毒软件排除列表。
内容的提问来源于stack exchange,提问作者Paul Durant
相关产品推荐
相关产品推荐

