How To Publish an ASP.NET Website from a Command Line

Syed Aslam Basha here. I am a tester on the Information Security Tools team.

To test the tools which we develop on the team, at times I need to build a website and publish it. I use a simple way of publishing websites from the command line that saves me a LOT of time so thought I would share it.

Launch notepad and copy paste the code below and save it as Publish.cmd file. Run visual studio command prompt (as administrator) and run the publish.cmd.


   1: @ECHO OFF
   2: set WEB_ROOT=C:\inetpub\wwwroot\mytestsite
   3: set PROJECT_ROOT=D:\Source\website 
   5: echo Publishing site %PROJECT_ROOT% to %WEB_ROOT% 
   7: del /S /Q %WEB_ROOT%\*.* || goto Error
   8: rmdir /S /Q %WEB_ROOT%\ || goto Error
   9: aspnet_compiler -p "%PROJECT_ROOT%" /v /commercesite /d "%WEB_ROOT%" || goto Error 
  11: goto Success
  12: :Error
  13: echo Site was not published 
  15: goto End
  17: :Success
  18: echo Site published successfully 
  20: :End

If there aren’t any errors the site will be published successfully as shown below


Publishing site D:\Source\website to c:\inetpub\wwwroot\mytestsite Utility to precompile an ASP.NET application

Copyright (C) Microsoft Corporation. All rights reserved.

Site published successfully


Modify the above script parameters appropriately to publish your site successfully!

- Syed

Comments (0)

Skip to main content