Publish a web application from the command line

I have a series of .NET 4-based web applications (WCF and Web) within the same solution, but you need to selectively publish from the command line.

I have tried different things so far, MSBuild, aspnet_compiler, but nothing has worked so far.

I need to be able to specify Project, not a solution, perform any transformations and redirect the output to a folder ... basically imitate the right mouse button, click "Publish" using the file system.

In addition to all this, I would like to leave the projects alone - not add msbuild files everywhere, as this is a specific assembly and is not necessarily related to the project.

The material I tried:

  • Publish an ASP.NET MVC 2 application from the command line and Web.config transformations
  • Equivalent msbuild command to publish from VS2008
+15
build visual-studio-2010 msbuild publish
Aug 16 2018-11-11T00:
source share
4 answers

Save the following script file publishProject.bat

rem publish passed project rem params: %configuration% %destDir% %srcDir% %proj% @echo off SET DestPath=d:\projects\Publish\%2 SET SrcPath=d:\projects\Src\%3\ SET ProjectName=%4 SET Configuration=%1 RD /S /Q "%DestPath%" rem clear existed directory :: build project MSBuild "%SrcPath%%ProjectName%.vbproj" /p:Configuration=%Configuration% :: deploy project ::/t:TransformWebConfig MSBuild "%SrcPath%%ProjectName%.vbproj" /target:_CopyWebApplication /property:OutDir=%DestPath%\ /property:WebProjectOutputDir=%DestPath% /p:Configuration=%Configuration% xcopy "%SrcPath%bin\*.*" "%DestPath%\bin\" /k /y echo ========================================= echo %SrcPath%%3.vbproj is published echo ========================================= 

I am calling it from another batch file

 @echo off rem VS2010. For VS2008 change %VS100COMNTOOLS% to %VS90COMNTOOLS% call "%VS100COMNTOOLS%\vsvars32.bat" SET ex=.\publishProject.bat Release call %ex% KillerWebApp1 KillerWebApp1\KillerWebApp1 KillerWebApp1 call %ex% KillerWebApp2 KillerWebApp2\KillerWebApp2 KillerWebApp2 call %ex% KillerWebApp3 KillerWebApp3\KillerWebApp3 KillerWebApp3 call %ex% KillerWebApp4 KillerWebApp4\KillerWebApp4 KillerWebApp4 

EDIT : The code above works for most cases, but not for everyone. That is, we use another asp.net application and bind it as a virtual folder in IIS. For this situation, VS2008 worked fine with the code above, but VS2010 also copies files from the virtual directory during deployment. The following code also works correctly in VS2010 (a solution was found here )

Add to your project file (* .csproj, * .vbproj)

 <Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder"> <Error Condition="'$(PublishDestination)'==''" Text="The PublishDestination property must be set to the intended publishing destination." /> <MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" /> <ItemGroup> <PublishFiles Include="$(_PackageTempDir)\**\*.*" /> </ItemGroup> <Copy SourceFiles="@(PublishFiles)" DestinationFiles="@(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" /> </Target> 

Change publishProject.bat to:

 rem publish passed project rem params: %configuration% %destDir% %srcDir% %proj% @echo off SET DestPath=d:\projects\Publish\%2 SET SrcPath=d:\projects\Src\%3\ SET ProjectName=%4 SET Configuration=%1 :: clear existed directory RD /S /Q "%DestPath%" :: build and publish project MSBuild "%SrcPath%%ProjectName%.vbproj" "/p:Configuration=%Configuration%;AutoParameterizationWebConfigConnectionStrings=False;PublishDestination=%DestPath%" /t:PublishToFileSystem 
+15
Aug 16 2018-11-11T00:
source share

I know this is an old question, but I just learned something, so I decided that I would share it: although it is 100% true that the target "_CopyWebApplication" exists and works, with .NET 4.0 it was replaced using the " _WPPCopyWebApplication "in Microsoft.Web.Publishing.targets, which supports new features like web.config conversion syntax, etc.

+4
Apr 03 2018-12-12T00:
source share

Have you checked WebDeploy ?

This should do everything you need - it can combine the web application into a deployable file (mostly ZIP), and the server has a β€œengine” that can interpret this deployable package and do all the heavy lifting for you.

Also see Scott Hanselman's Web site deployment made it awesome: if you use XCopy, you do it wrong , the blog post is very useful!

0
Aug 16 2018-11-11T00:
source share

My solution for CCNET with Web.config conversion:

 <tasks> <msbuild> <executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable> <workingDirectory>E:\VersionesCC\Trunk_4\SBatz\Gertakariak_Orokorrak\GertakariakMS\Web</workingDirectory> <projectFile>GertakariakMSWeb2.vbproj</projectFile> <targets>Build</targets> <timeout>600</timeout> <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger> <buildArgs> /noconsolelogger /p:Configuration=Release /v:diag /p:DeployOnBuild=true /p:AutoParameterizationWebConfigConnectionStrings=false /p:DeployTarget=Package /p:_PackageTempDir=E:\Aplicaciones\GertakariakMS2\Web </buildArgs> </msbuild> </tasks> 
0
May 08 '13 at 8:22
source share



All Articles