Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I modify what the green start button in visual studio does?

I have a C# project which I am editing in visual studio. When I click the green start button, it builds the project, starts IIS and then opens a browser window.

If I wanted to customise this behaviour, for example to also launch an nginx reverse proxy which sits infront of IIS, how would I do this?

I would also be interested in which pieces of technology are involved in the process between clicking the start button and my browser window opening.

like image 897
Cameron Martin Avatar asked Mar 11 '16 11:03

Cameron Martin


1 Answers

A lot of things happen when you click the "green button". The main are:

  1. If not running - Visual Studio (by default) starts IIS Express - a lite version of the IIS web server
  2. Publishes your project to it
  3. Attaches a debugger
  4. Opens a browser with your project URL

I assume you're only interested in customizing the 4th step. Click on the little downwards arrow next to your "green button" to open the context menu, click Browse With....

An image showing where to find "Browse With".

You can there select from a list of web clients which Visual Studio detected. Click Add..., you'll be presented with a window to add your own client. There you can point Visual Studio to aything - nginx, a custom launcher that you can easily make with C# (Which could, as in your example, start nginx, or perform any kind of action), a PowerShell script, etc.

A picture showing the add window

Note: The last argument passed to the application will be your project URL, any other arguments you add will be prepended before it. If you leave your arguments empty, it will still pass your project URL as the only argument.


A cleaner solution would be to write a Visual Studio plugin, although I don't know much about it - if you decide to go down this route you can begin your research here.

Not sure if this is relevant to you, but you can also select which IIS server Visual Studio should publish your project to. Go to your project Properties > Web, under Servers you can select your target IIS server and project URL.

like image 103
Gediminas Masaitis Avatar answered Sep 25 '22 08:09

Gediminas Masaitis