Replicate VS2008 "Publish Web Site" from command line

22,717

Solution 1

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.

Solution 2

This "magic" combination does what you're looking for. )It only took two days to get the right combination for my project.) 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    

Solution 3

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>

Solution 4

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

Solution 5

I was struggling with the same error (MSB4057: The target "_CopyWebApplication" does not exist in the project.

Yes. I was using a Web Application Project (not a web site).

I was baffled because I had one project that worked, and one that did not. So I sat down with ExamDiffPro and went to work comparing the project files. What I found was the section of build target includes at the bottom of the project files were different.

One project (that was working) was created using a newer version of Visual Studio. The other one (that was NOT working) was created years ago and has been upgraded over the years, to the current version I am working with. The upgraded project, evidently didn't get upgraded with the new build targets as newer versions of Visual Studio became available.

At the bottom of the project file which was working, I found the following:

<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets" />

The second import line was NOT in the project which was causing problems.

I simply copied the import from the working file, and pasted it in the relative location in the non-working file, and viola!

While this is not a direct solution to the initial problem defined in this thread, I hope this helps some of the other people that stumbled across this thread, looking for similar issues, only with actual Web Application Projects.

Share:
22,717
tomfanning
Author by

tomfanning

Tech enthusiast. Latecomer to Scrum but loving it. Currently working hard on re-platforming SCOOT, an extensively deployed city-scale traffic signal optimisation technique, for life in the cloud in 2018 and beyond.

Updated on March 13, 2020

Comments

  • tomfanning
    tomfanning about 4 years

    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

  • tomfanning
    tomfanning about 15 years
    My question is about precompiling an ASP.NET web site before putting it on a web server, not moving files around a network.
  • tomfanning
    tomfanning about 15 years
    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
    tomfanning about 15 years
    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.
  • Brad Tutterow
    Brad Tutterow about 15 years
    Yep, my misunderstanding. I was thinking web application, not web site.
  • tomfanning
    tomfanning about 15 years
    Thanks, I intend to revisit using aspnet_compiler directly some time this week. I'll update my post with my experiences.
  • Kristoffer L
    Kristoffer L over 14 years
    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.
  • tomfanning
    tomfanning about 13 years
    Appears this is for ASP.NET Web Applications, not ASP.NET Web Sites. The distinction is that Web Site projects do not have a project file, only a solution file. That's why this question is tricky. Thanks anyway though.
  • Iain Ballard
    Iain Ballard about 13 years
    IIRC, Visual Studio creates a temporary "fake" Solution file when it builds/publishes a csproj.
  • w0051977
    w0051977 about 11 years
    @AMissico, do you have to run the aspnet_compiler command manually? (I will upvote your answer). Thanks.
  • tomfanning
    tomfanning almost 8 years
    Sorry for commenting on a 6 year old post, but this appears to relate to Web Applications, not Web Sites. Visual Studio Web Site applications do not have a .csproj file.