Azure App Service部署失败:System.Text.Json相关NETSDK1060错误求助
解决思路
针对Azure部署时出现的NETSDK1060错误(无法加载System.Text.Json 8.0.0.4),可以尝试以下步骤:
清理构建缓存并重新生成依赖
本地执行以下命令,彻底清理旧的构建文件和依赖缓存:dotnet clean rd /s /q obj bin # Linux/macOS 替换为 rm -r obj bin dotnet restore同时在Azure部署配置中开启移除目标位置的额外文件选项,避免部署时残留旧依赖文件。
对齐.NET SDK版本
错误日志显示部署环境使用.NET 9 SDK,但你引用的是.NET 8版本的System.Text.Json,可二选一调整:- 将项目目标框架切换为.NET 9,同步更新所有NuGet包到适配.NET 9的版本;
- 在Azure App Service的配置中,设置
DOTNET_VERSION环境变量为8.0.x,强制使用.NET 8 SDK构建。
修复project.assets.json文件
直接删除项目obj目录下的project.assets.json文件,再执行dotnet restore重新生成正确的依赖解析文件。同时检查项目文件中是否存在重复的System.Text.Json引用,或其他依赖包引发的版本冲突。检查Azure运行时配置
进入Azure Portal的App Service配置页面,在常规设置中确认.NET运行时版本与项目目标框架一致;同时确保App Service的操作系统(Windows/Linux)与本地开发环境匹配,避免跨平台依赖问题。添加版本绑定重定向
在项目的.csproj文件中添加以下配置,强制程序加载指定版本的System.Text.Json:<PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>或者在
web.config中手动添加绑定重定向规则:<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-8.0.0.4" newVersion="8.0.0.4" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
内容的提问来源于stack exchange,提问作者Craig
相关产品推荐
相关产品推荐

