skip to Main Content

I am trying to do something that I would have thought was fairly standard – serve a static website on the localhost from Visual Studio. I am using:

  • Microsoft Visual Studio Community 2019
  • Version 16.11.34

I have a very simple website (at the moment)

│   index.html
│   README.md
│
├───Content
│   │   site.css
│   │
│   └───images
│           logo.png
│
└───Scripts
        site.js

I can open this directory in Visual Studio and edit the files OK but no associated sln (solution) file is created.

The run button has ‘Select Startup Item’ next to it but I do not see anyway of selecting anything or configuring IIS to run this.

Now I could set up, say, a NodeJS or MVC application with no problem but I do not want to do this – I just want to be able to serve static files on localhost from Visual Studio, as this would be very convenient.

My motivation for this is that I want to share HTML, CSS and JavaScript files with a colleague who has Visual Studio installed but no experience of server-side programming, so that we can develop a front-end website together. Some things can obviously just be run directly from the browser but I will also want to do things with JavaScript that require the site being run on localhost (e.g. API calls, loading test JSON files etc.)

I can run nginx on my own machine but for some reason things this is not running properly on my colleague’s machine – hence wanting to this using IIS in Visual Studio. I would have imagined this would be easy to do but can see no way of accomplishing it! Is this even possible?

I have seen some similar (but very old) questions on Stack Overflow, such as this but the answers do not work on my version of VS.

2

Answers


  1. Your static web page is not a project that can be run directly. Normally, IIS Express is mainly used for web application development. If you need to use IIS Express to run your website, you can try creating a simple project suitable for web development, such as an ASP.NET Core web application.

    By creating an empty web project and adding your static website files to it, you can take advantage of Visual Studio’s project management and debugging features to more easily manage and debug your website.

    Related Link: Serve Static Files In ASP.NET Core Using Visual Studio 2017.

    Login or Signup to reply.
  2. An alternative answer.

    Visual Studio was designed primarily for enterprise developers for their design/code/test/debug workflow. Thus, you find all project types give the developers something to debug with,

    • ASP.NET Core projects, where VS hooks up to IIS worker processes to enable backend debugging.
    • JavaScript projects, where VS hooks up to Node.js processes or the browsers to enable JS debugging.

    Your scenario, however, isn’t something a typical enterprise developer works on. Thus, VS doesn’t have a specific project type for it.

    You’d better take a look at VS Code, an editor for all audience. Extensions like mine integrate IIS Express with it, so that you can host static files more easily.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search