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

macOS运行现有ASP.NET项目报错:ApplicationHost.cs文件未找到

Fixing "ApplicationHost.cs not found" Error for ASP.NET on macOS

Hey there! As someone who’s navigated the cross-platform ASP.NET waters, let me break down what’s going on here and how to fix it.

Why You’re Seeing This Error

First off, let’s clarify: the traditional ASP.NET framework (the one that uses System.Web) is deeply tied to Windows and IIS. The ApplicationHost class you’re missing is part of IIS’s hosting infrastructure—something that simply doesn’t exist natively on macOS. Even if you’ve heard ASP.NET can run on macOS, that’s referring to ASP.NET Core (the modern, cross-platform version), not the old System.Web-based ASP.NET.

Your Solution Options

Here are the most practical paths forward:

This is the long-term, cross-platform-friendly fix. ASP.NET Core is designed to run on Windows, macOS, and Linux seamlessly. To get started:

  • Create a new ASP.NET Core project matching your app type (MVC, Web API, etc.) using dotnet new commands in Terminal.
  • Gradually migrate your existing code:
    • Move controller logic, views, and business logic over (most C# code will work with minor tweaks).
    • Replace System.Web-specific APIs: use IHttpContextAccessor instead of static HttpContext, swap HTTP modules for middleware, and use configuration providers instead of web.config settings.
  • Test incrementally to catch any compatibility gaps early.

2. Run the App in a Windows Environment on macOS

If migrating isn’t feasible right now, you can run your existing Windows-only ASP.NET app using:

  • Windows Virtual Machine: Use tools like Parallels Desktop or VMware Fusion to run a Windows instance on your Mac. Install IIS and Visual Studio (or Visual Studio Code with the right extensions) there to run your app as you would on a native Windows machine.
  • Windows Docker Container: Set up a Windows Docker container on macOS (note: this requires Docker Desktop with Windows container support enabled). Package your ASP.NET app into a container image that runs IIS, then spin up the container locally.

3. Double-Check Project Integrity (Long Shot)

If you mistakenly thought this was an ASP.NET Core project, try these quick fixes to rule out corrupted files:

  • Run dotnet clean followed by dotnet restore in your project directory to clean and re-download dependencies.
  • Verify that your project file (.csproj) doesn’t have unintended references to System.Web unless you’re intentionally targeting Windows-only frameworks.

Remember, the old System.Web ASP.NET just isn’t built for macOS—so migrating to Core or using a Windows environment are your only reliable options here.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:34:07