Freigeben über


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 
    4:  
    5: echo Publishing site %PROJECT_ROOT% to %WEB_ROOT% 
    6:  
    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 
   10:  
   11: goto Success
   12: :Error
   13: echo Site was not published 
   14:  
   15: goto End
   16:  
   17: :Success
   18: echo Site published successfully 
   19:  
   20: :End

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

C:\Windows\system32>D:\Source\website\publish.cmd

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

C:\Windows\system32>

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

- Syed