VS2008 Publishing a Website Replication from the Command Line

I am trying to reproduce the exact functionality of this dialog in Visual Studio 2008 in a build script: alt text http://i41.tinypic.com/1osl1f.png

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

I have Googled around this and quite a few things have come up related to MSBuild, but all this seems to be about the 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 relevant for ASP.NET websites, but I find that I get an error message when I try to create using these 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 04/22/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 am trying to publish (inherited, not my own) does not have .csproj files (where I can import the _CopyWebApplication target from C: \ Program Files (x86) \ MSBuild \ Microsoft \ VisualStudio \ v9 0,0 \ WebApplications \ Microsoft.WebApplication.targets)

Perhaps this is the difference in Visual Studio 2005/2008?

Anyway, I feel like I'm going the wrong way there.

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

Thank you very much

+36
visual-studio-2008 msbuild publish
Apr 22 '09 at 10:58
source share
11 answers

The following command duplicates the website publishing dialog with the default settings.

Team to publish a website with default settings

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

Link

1) See Community Content under the heading "You want to publish a site but you don’t have Visual Studio, then ... at http://msdn.microsoft.com/en-us/library/20yh9f1b(classic).aspx .

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

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

3) After an excerpt from the 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. Compile and deploy your network expression. See the ASP.NET Compilation Tool (Aspnet_compiler.exe) for more information.

4) Following an excerpt from the How To: Pre-provision ASP.NET Web Sites for Deployment at http://msdn.microsoft.com/en-us/library/ms227976.aspx .

If your website is not the Internet Application of Information Services (IIS) and therefore does not have an entry in the IIS metabase, use the following value for the -v switch.

aspnet_compiler -p physicalOrRelativePath -v / targetPath

In this case, the physicalOrRelativePath parameter refers to the fully qualified path to the directory in which the website files are located or the relative path to the current directory. A period (.) Is allowed in the physicalOrRelativePath parameter. -v indicates the root that the compiler will use to resolve references to root applications (for example, with the tilde (~)). When you specify the / value for the -v switch, the compiler will resolve the paths using the physical path as the root.

+38
Oct 28 '09 at 23:24
source share

I think you are looking for an AspNetCompiler task

 <Target Name="PublishToIIS" DependsOnTargets="Publish"> <AspNetCompiler VirtualPath="$(IISVirtualPath)" TargetPath="$(IISTargetPath)" PhysicalPath="$(MSBuildProjectDirectory)/trunk/InternalAppCS/Web.UI/" Force="true" Debug="$(IISDebug)" /> </Target> 
+6
Apr 22 '09 at 11:35
source share

Add to the .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 like: $ (OutputFolder), which you can pass

then go to your web application folder and do:

 msbuild /t:Build 

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

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

That should do it.

+5
Sep 10 '09 at 21:47
source share

This “magic” combination does what you are looking for. ) It took me only two days to get the right combination for my project.) The key should 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 
+5
Oct 08 2018-10-10
source share

Personally, I use buildbot, which runs the commands for me, I had to create a VBS script that does the loading for me.

I installed WinSCP to do ftp work and then just ran the boot script:

 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 precompile the website from the command line, I do the following, however, I do this on the web server, and not before downloading it:

 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -p "D:\<mycompany>\Backedup\Web Sites\<mysite\Root" -v / 
+4
Apr 22 '09 at 11:23
source share

I use msbuild for what you are describing. Have you tried setting the property as follows?

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

If it still doesn't work, let me know and I can send you my bat file, kick the msbuild script that svn get, build the assembly.info file, deploy the website and finally run http on the website’s home page, just to make sure it is built and deployed correctly.

Hope this helps rihan

+4
Apr 29 '09 at 11:29
source share

I struggled with the same error (MSB4057: Target "_CopyWebApplication" does not exist in the project.

Yes. I used a web application project (not a website).

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

One project (working) was created using the new version of Visual Studio. Another (which did not work) was created several years ago and over the years has been updated to the current version that I am working with. The updated project, apparently, did not update with new build goals, as new versions of Visual Studio appeared.

At the bottom of the project file that worked, I found the following:

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

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

The second line of import was NOT in the project that caused the problems.

I just copied the import from the working file and pasted it into a relative location in the broken file and viola!

Although this is not a direct solution to the original problem identified in this thread, I hope this helps some other people who stumbled upon this thread looking for similar problems, only with actual web application projects.

+4
Sep 20
source share

Here's a little PowerShell script that creates a solution and then publishes a web project from it.

MSBuild for .Net 3.5, so if necessary, change to "\ v4.0 \".

 $build = "$env:windir\Microsoft.NET\Framework\v3.5\MSBuild.exe" $SolutionPath = "C:\Projects\AdminWebSite" $SolutionFile = "AdminWebSite.sln" $WebProjectFile = "Admin.Web\Admin.Web.csproj" $OutputPath = "C:\PublishedSites\Hosts\adminweb" & $build "$SolutionPath\$SolutionFile" /t:rebuild & $build "$SolutionPath\$WebProjectFile" "/t:ResolveReferences;_CopyWebApplication;publish" /p:OutDir="$OutputPath\bin\" /p:WebProjectOutputDir="$OutputPath" 

"ResolveReferences" should appear before "_CopyWebApplication", otherwise the dependencies will disappear.

The examples given here are structured as follows:

  • C: \ Project \ AdminWebSite \ AdminWebSite.sln
  • C: \ Project \ AdminWebSite \ Admin.Web \ Admin.Web.csproj
+3
Apr 07 2018-11-11T00:
source share

The error you received (C: \ dev \ T & A \ TAWeb.sln: error MSB4057: target "_CopyWebApplication" does not exist in the project) is caused by two problems. First: the _CopyWebApplication target should be called in the WebApplication project file, not in the solution. Secondly: there is no project file on the website, WebApplications have project files.

The _CopyWebApplication target applies only to publishing a WebApplication project. Using AspNetCompiler The MSBuild task should be used to publish a website.

When you publish a website in visual studio 2008, the second line of output is "Precompile the website." Visual studio options are displayed for publishing a sitemap directly for the AspNetCompiler and Aspnet_compiler.exe options .

Although I'm not the first to say "use AspNet_compiler", I thought about what reasons might be useful. On the other hand, I think AspNet_compiler can be used to publish webapp, but I need to do some more tests.

+2
Oct 27 '10 at 17:26
source share

I am using a bat file using msbuild.exe (.net 3.5, vs 2008) to "publish" my website (vbproj) to a folder.

% msBuildDir% \ MSBuild "D: \ Project1 \ Client \ WebPresentation \ ConsultaOperaciones.vbproj" / T: ResolveReferences; Rebuild / P: BuildingProject = TRUE; OutDir = D: \ Instalaciones \ Ultima \ PublicacionWeb \ OutDir \; WebProjectOutputDir = D: \ Instalaciones \ Ultima \ PublicacionWeb \ WebProjectDir \

+1
Jul 20 '11 at 18:16
source share

There is nothing magical about the Publish ... function that you could not recreate yourself, especially since you are targeting a shared network file.

In it, the kernel, everything that it does, copies your files from one place to another. Using NAnt, you can accomplish this with copy, or you can use the exec task to call xcopy. If you use a build tool other than NAnt, I am sure there is support for such tasks.

If you want to leave your raw code and debug the information behind, you can exclude files that end in .cs or .pdb. Both instances of NAnt and xcopy provide simple ways to do this.

-one
Apr 22 '09 at 11:27
source share



All Articles