How to convert a Class Library project to a Web Application project?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In most .NET solutions, you do not literally "convert" a class library into a web application by flipping one project property. A class library and a web application have different SDKs, entry points, build outputs, and runtime expectations, so the practical path is usually to create a web project and move or reference the reusable code from the library.
Why These Project Types Are Different
A class library is designed to compile reusable code into an assembly that another application can load. A web application is an executable host with:
- an entry point
- hosting configuration
- request pipeline setup
- web-specific dependencies
That means a web application needs files and configuration a library project simply does not have.
The Recommended Approach
The cleanest workflow is:
- keep shared logic in the class library
- create a new web application project
- reference the library from the web project
- move only the web-facing code into the web project
For example, create a new ASP.NET Core project:
Now the web app can use the existing library code:
And the library might contain:
This keeps responsibilities clear instead of forcing web concerns into the library.
If You Must Change the Existing Project
Sometimes you want the existing project folder to become the web app. In SDK-style projects, that generally means editing the project file so it uses the web SDK and then adding the missing web host files.
A library project file often starts like:
A minimal web project instead uses:
You would also need a Program.cs, web dependencies, and possibly appsettings.json, controllers, or Razor files depending on the application type.
That is why this is more of a project restructuring than a direct conversion.
When to Keep the Library Separate
Keeping the library separate is usually better when:
- multiple apps share the logic
- you want cleaner testing boundaries
- the domain logic should not depend on ASP.NET types
- you may later host the same code in workers, APIs, or desktop tools
This separation also improves architecture. The web project becomes the delivery mechanism, while the library holds reusable business logic.
Common Pitfalls
The most common mistake is trying to add controllers, views, and web configuration directly into a class library without changing the project type or creating a host application.
Another issue is moving too much code into the web project and losing reusability. If your existing library already contains useful domain logic, keep it there and reference it.
Developers also sometimes forget that old ASP.NET Framework project systems and newer SDK-style .NET projects behave differently. Advice for one project style does not always map cleanly to the other.
Finally, a web app is not just a renamed output type. It needs hosting, configuration, startup logic, and deployment assumptions that a class library never had.
Summary
- A class library is not usually converted directly into a web app with one setting change.
- The practical solution is often to create a web project and reference the library.
- If you do repurpose the project, switch to the web SDK and add the required host files.
- Keep reusable business logic in the library when possible.
- Treat the change as project restructuring, not just project renaming.

