Replicate VS2008 “Publish Web Site” from command line

asp.netmsbuildpublishvisual-studio-2008

I am trying to replicate the exact functionality of this dialogue in Visual Studio 2008 in a build script:
alt text

This is an ASP.NET web site, not a web application.

I have Googled around this and turned up quite a bit of stuff involving MSBuild, but this all seems to concern solutions laid out as ASP.NET Web Applications:

http://www.driebier.net/post/Using-MSBuild-to-deploy-visual-studio-2005-web-applications.aspx
http://blog.donnfelker.com/post/TFS-Build-Not-Publishing-Web-Applications.aspx

This article seems to be relevant to ASP.NET Web Sites, but I find that I'm getting an error when trying to build using those suggestions:

C:\dev\T&A>msbuild /t:_CopyWebApplication /property:OutDir=c:\temp\taweb\ /prope
rty:WebProjectOutputDir=c:\temp\taweb\

Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.3074]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 22/04/2009 11:50:42.
Project "C:\dev\T&A\TAWeb.sln" on node 0 (_CopyWebApplication target(s)).
  Building solution configuration "Debug|.NET".
C:\dev\T&A\TAWeb.sln : error MSB4057: The target "_CopyWebApplication" does not
 exist in the project.
Done Building Project "C:\dev\T&A\TAWeb.sln" (_CopyWebApplication target(s)) --
 FAILED.


Build FAILED.

"C:\dev\T&A\TAWeb.sln" (_CopyWebApplication target) (1) ->
  C:\dev\T&A\TAWeb.sln : error MSB4057: The target "_CopyWebApplication" does n
ot exist in the project.

0 Warning(s)

1 Error(s)

Time Elapsed 00:00:00.06

The solution I'm trying to publish (inherited, not my own) doesn't have .csproj files (where I could import the _CopyWebApplication target from C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets)

Perhaps this is a Visual Studio 2005/2008 difference?

Anyway, I feel that I'm going down the wrong path there.

Essentially I just need to achieve exactly what the above dialogue does, but from the command line.

Thanks very much

Best Answer

The following command duplicates the Publish Web Site dialog with default settings.

Command for Publish Web Site with Default Settings

aspnet_compiler -nologo -v / -p "C:\WebSite1" -u "C:\TargetPath"

Reference

1) See Community Content titled You want Publish a site but you have not Visual Studio then... at http://msdn.microsoft.com/en-us/library/20yh9f1b(classic).aspx.

  • Microsoft Visual Studio 2005 > Visual Studio 2005 Command Prompt
  • Microsoft Visual Studio 2008 > Visual Studio 2008 Command Prompt
  • Microsoft .NET Framework SDK v2.0 > SDK Command Prompt

2) See "ASP.NET Compilation Tool (Aspnet_compiler.exe)" at http://msdn.microsoft.com/en-us/library/ms229863.aspx.

3) Following excerpt from Walkthrough: Deploying an ASP.NET Web Application Using XCOPY at http://msdn.microsoft.com/en-us/library/f735abw9.aspx

As an alternative to using the XCOPY command-line tool, which is supported by all versions of the .NET Framework, you can use the new .NET Framework 2.0 tool located at %SystemRoot%\Microsoft.NET\Framework\version 2 or later\Aspnet_compiler.exe to compile and deploy your Web application. For more information, see ASP.NET Compilation Tool (Aspnet_compiler.exe).

4) Following excerpt from How to: Precompile ASP.NET Web Sites for Deployment at http://msdn.microsoft.com/en-us/library/ms227976.aspx.

If your Web site is not an Internet Information Services (IIS) application and therefore has no entry in the IIS metabase, used the following value for the -v switch.

aspnet_compiler -p physicalOrRelativePath -v / targetPath

In this case, the physicalOrRelativePath parameter refers to the fully qualified directory path in which the Web site files are located, or a path relative to the current directory. The period (.) operator is allowed in the physicalOrRelativePath parameter. The -v switch specifies a root that the compiler will use to resolve application-root references (for example, with the tilde (~) operator). When you specify the value of / for the -v switch the compiler will resolve the paths using the physical path as the root.