+1  A: 

Personally I use buildbot which runs commands for me, I had to create a VBS script which performs the upload for me.

I installed WinSCP to do the ftp work and then just scripted the upload:

Set WshShell = CreateObject("WScript.Shell")
sCmd1 = """C:\Program Files\WinSCP\winscp.com"" <myusername> /command ""option batch on"" ""option confirm off"" ""put " & DefaultPath & strResult & "\" & DefaultFileName & " /Usr/<myuser>/" & updateType & "/" & strResult & "/"" ""exit"""

To pre-compile the website from a command line I do the following, however I do this on the web server rather than before uploading it:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -p "D:\<mycompany>\Backedup\Web Sites\<mysite\Root" -v /
Phil Hannent
My question is about precompiling an ASP.NET web site before putting it on a web server, not moving files around a network.
tomfanning
I edited my answer to help, its not the correct answer but might provide a hint.
Phil Hannent
Thanks, I intend to revisit using aspnet_compiler directly some time this week. I'll update my post with my experiences.
tomfanning
A: 

There's nothing magical about the "Publish..." feature that you couldn't recreate on your own, especially since you are targeting a network file share.

At it's core, all it's doing is copying your files from one place to another. Using NAnt, you can pull this off with a copy task or you can use an exec task to call xcopy If you're using a build tool other than NAnt, I'm sure there is support for similar tasks.

If you want to leave your raw code and debugging information behind, you can exclude files that end with .cs or .pdb. Both NAnt copy and xcopy provide easy ways to do this.

Brad Tutterow
The Publish feature doesn't just copy files around, it pre-compiles the ASP.NET Web Site, putting all the code in .DLLs, and putting placeholders all over the resulting tree where .aspx pages (containing markup) would have been. That's the bit I'm trying to automate, not the "moving files around" bit. The point here is that I don't want the web server to be compiling source code.
tomfanning
Yep, my misunderstanding. I was thinking web application, not web site.
Brad Tutterow
+5  A: 

I think you are looking for the AspNetCompiler task

<Target Name="PublishToIIS" DependsOnTargets="Publish">
    <AspNetCompiler    
            VirtualPath="$(IISVirtualPath)"
            TargetPath="$(IISTargetPath)"
            PhysicalPath="$(MSBuildProjectDirectory)/trunk/InternalAppCS/Web.UI/"
            Force="true"
            Debug="$(IISDebug)"
     />

</Target>
slf
Hmmm, everything seems to lead back to aspnetcompiler in the end - but my understanding is that you need a target IIS with a virtual directory for the site, although this seems a bit ambiguous.I will do some more digging on this later.
tomfanning
You can publish to any remote directory without a virtual directory. I use this for my MVC projects and just set TargetPath to a shared directory on the web server.
Kristoffer L
+3  A: 

I have been using msbuild for exactly what you describe. Have you tried setting the property like this?

 /property:"OutDir=c:\temp\taweb\;WebProjectOutputDir=c:\temp\taweb\"

If it still does not work, let me know and I can send you my bat file, that kicks of the msbuild script, that does the svn get, builds the assembly.info file, deploy the web site, and finally runs a http get on the site home page, just to make sure it built and deployed correctly.

Hope it helps Rihan

Rihan Meij
A: 

Add to your .csproj file:

<Target Name="AfterBuild">
<Message Text="Copying to Deployment Dir:" />
<Copy SourceFiles="@(Content)" DestinationFolder="..\PreCompiledWeb\%(Content.RelativeDir)" />
<CreateItem Include="$(OutputPath)\*">
    <Output TaskParameter="Include" ItemName="Binaries"/>
</CreateItem>
<Copy SourceFiles="@(Binaries)" DestinationFolder="..\PreCompiledWeb\bin" />

Change "..\PreCompiledWeb" for the folder you want to publish to or you can specify a variable something like: $(OutputFolder) which you can pass

then go the folder of your webapplication and do:

msbuild /t:Build

Then you can copy those files wherever you want using xcopy:

xcopy "..\PreCompiledWeb\*.*" "C:\MySite\" /e

That should do it.

+10  A: 

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%28classic%29.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.

AMissico
A: 

This "magic" combination does what you're looking for. )It only took two days to get the right combination for my pronect.) The key is to include the _CopyWebApplication target and the ResolveReferences target.

msbuild "/t:_CopyWebApplication;ResolveReferences;publish" /p:OutDir="C:\inetpub\wwwroot\[appname]\bin\" /p:WebProjectOutputDir="C:\inetpub\wwwroot\[appname]" c:\directory\[appname].csproj    
Brad Bruce
A: 

The error you received (C:\dev\T&A\TAWeb.sln : error MSB4057: The target "_CopyWebApplication" does not exist in the project) is due to two issues. First: the target _CopyWebApplication must be called on a WebApplication project file, not a solution. Second: a website does not have a project file, WebApplications have project files.

The _CopyWebApplication target only applies to publishing a WebApplication project. Use the AspNetCompiler MSBuild task must be used to publish a website.

When you publish a website in visual studio 2008, the second line of output is "Pre-compiling Web Site". The options visual studio displays for publishing a website map directly to options for the AspNetCompiler and Aspnet_compiler.exe.

Though I'm not the first here to say "use AspNet_compiler", I thought describing the reasons why may be helpful. On a side note, I think the AspNet_compiler can be used to publish a webapp but I need to do some more testing.

mcdon