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:
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:devT&A>msbuild /t:_CopyWebApplication /property:OutDir=c:temptaweb /prope rty:WebProjectOutputDir=c:temptaweb 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:devT&ATAWeb.sln" on node 0 (_CopyWebApplication target(s)). Building solution configuration "Debug|.NET". C:devT&ATAWeb.sln : error MSB4057: The target "_CopyWebApplication" does not exist in the project. Done Building Project "C:devT&ATAWeb.sln" (_CopyWebApplication target(s)) -- FAILED. Build FAILED. "C:devT&ATAWeb.sln" (_CopyWebApplication target) (1) -> C:devT&ATAWeb.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)MSBuildMicrosoftVisualStudiov9.0WebApplicationsMicrosoft.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
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
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"
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
2 or laterAspnet_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.
physicalOrRelativePath -v /
In this case, the
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.
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>
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:inetpubwwwroot[appname]bin" /p:WebProjectOutputDir="C:inetpubwwwroot[appname]" c:directory[appname].csproj
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="..PreCompiledWebbin" />
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:
Then you can copy those files wherever you want using xcopy:
xcopy "..PreCompiledWeb*.*" "C:MySite" /e
That should do it.
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 FilesWinSCPwinscp.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:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_compiler -p "D:<mycompany>BackedupWeb Sites<mysiteRoot" -v /
I have been using msbuild for exactly what you describe. Have you tried setting the property like this?
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
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)MicrosoftVisualStudiov8.0WebApplicationsMicrosoft.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.
Here’s a little PowerShell script that builds a solution, then publishes a web project from it.
The MSBuild is for .Net 3.5, so change to “v4.0” if needed.
$build = "$env:windirMicrosoft.NETFrameworkv3.5MSBuild.exe" $SolutionPath = "C:ProjectsAdminWebSite" $SolutionFile = "AdminWebSite.sln" $WebProjectFile = "Admin.WebAdmin.Web.csproj" $OutputPath = "C:PublishedSitesHostsadminweb" & $build "$SolutionPath$SolutionFile" /t:rebuild & $build "$SolutionPath$WebProjectFile" "/t:ResolveReferences;_CopyWebApplication;publish" /p:OutDir="$OutputPathbin" /p:WebProjectOutputDir="$OutputPath"
The “ResolveReferences” must come before “_CopyWebApplication” otherwise dependencies go missing.
The example paths given here build to:
The error you received (C:devT&ATAWeb.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.
I use bat file using msbuild.exe (.net 3.5, vs 2008) for “publish” my website (vbproj) in a folder.
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.