Search code examples
visual-studio-2010visual-studio-2012hosts-filepost-build-eventbuild-events

Update hosts file on post-build event Visual Studio 2012


I have a VS2012 project. To make it run I need a hosts file entry eg. 127.0.0.1 local.mywebsite.com

The problem is I want to make it as easy as possible for new developers to simply get the project from TFS and run it without any extra steps.

Is it possible for me to execute a post-build event which can add that entry to my hosts file if that entry doesn't exist already?


Solution

  • Answering my own question:

    1. Visual Studio-->Open Nuget Console and run this command : Install-Package MSBuild.Extension.Pack
    2. Visual Studio-->Right Click-->Unload your Project (.csproj)
    3. Afer unloading you can now Right Click-->Edit .csproj
    4. Scroll down all the way and paste these lines before the ending "Project" tag -->http://pastebin.com/eEJXDrmi
    5. Save .csproj and right click -->reload project

    You are good to go !!!! Now, when you build your project it will update your hosts files if that entry exists, and will create the entry if it doesn't exist. Pretty Cool stuff !