You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux(Ubuntu22.04)下ASP.NET Core WebAPI项目dotnet命令执行异常求助

解决思路
  • 清理本地NuGet缓存:执行dotnet nuget locals all --clear,清除所有本地NuGet缓存后,重新运行dotnet restore命令。
  • 强制指定NuGet源恢复:在restore时明确指定官方源,执行dotnet restore --source https://api.nuget.org/v3/index.json,或者创建项目时直接指定源:dotnet new webapi -o NewApi --nuget-source https://api.nuget.org/v3/index.json。
  • 检查并修复Web API模板:卸载现有Web API模板后重新安装,依次执行:
    dotnet new uninstall Microsoft.AspNetCore.Web.Api.Templates
    dotnet new install Microsoft.AspNetCore.Web.Api.Templates::8.0.*
    
  • 排查SSL证书与代理问题:
    • 更新系统根证书:执行sudo apt update && sudo apt install ca-certificates -y && sudo update-ca-certificates
    • 临时禁用SocketsHttpHandler:添加环境变量后再执行restore,export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0 && dotnet restore
  • 检查项目目录权限:确保当前用户拥有项目目录的读写权限,执行chown -R $USER:$USER /home/john/project-folder/webapp
  • 查看项目csproj配置差异:对比控制台项目和Web API项目的csproj文件,确认是否存在特殊的包源配置或依赖项,移除可能导致异常的自定义配置。

内容的提问来源于stack exchange,提问作者Matheus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 10:32:06