VS2010 Web Publish command line version of File System deploy
Asked Answered
O

6

45

Folks,

In a nutshell, I want to replicate this dialog: alt text

It's a Visual Studio 2010 ASP.Net MVC project. If I execute this command, I get all the files I want, including the transformed web.configs in the "C:\ToDeploy" directory.

I want to replicate this on the command line so I can use it for a QA environment build.

I've seen various articles on how to do this on the command line for Remote Deploys, but I just want to do it for File System deploys.

I know I could replicate this functionality using nAnt tasks or rake scripts, but I want to do it using this mechanism so I'm not repeating myself.

I've investigated this some more, and I've found these links, but none of them solve it cleanly:

Thanks in advance!

Outport answered 27/10, 2010 at 2:24 Comment(0)
O
46

Ok, finally figured this out.

The command line you need is:

msbuild path/to/your/webdirectory/YourWeb.csproj /p:Configuration=Debug;DeployOnBuild=True;PackageAsSingleFile=False

You can change where the project outputs to by adding a property of outdir=c:\wherever\ in the /p: section.

This will create the output at:

path/to/your/webdirectory/obj/Debug/Package/PackageTmp/

You can then copy those files from the above directory using whatever method you'd like.

I've got this all working as a ruby rake task using Albacore. I am trying to get it all done so I can actually put it as a contribution to the project. But if anyone wants the code before that, let me know.

Another wrinkle I found was that it was putting in Tokenized Parameters into the Web.config. If you don't need that feature, make sure you add:

/p:AutoParameterizationWebConfigConnectionStrings=false
Outport answered 28/10, 2010 at 13:27 Comment(4)
Unfortunately, this copies the entire package. I think you'll need to use MS Web Deploy to only copy changed files.Pirbhai
For completness, the OutDir property must end with a trailing slash (MSBuild errors out otherwise). So your suggestion should be outdir=c:\wherever\ .Woorali
Also, instead of /p:DeployOnBuild=True you could just use the Package target: /t:Package. Works for me, plus both PackageAsSingleFile and AutoParameterizationWebConfigConnectionStrings parameters are respected as well.Woorali
@Jakub I updated the answer to reflect the OutDir comment, thanks!Outport
B
11

I thought I'd post a another solution that I found, I've updated this solution to include a log file.

This is similar to Publish a Web Application from the Command Line, but just cleaned up and added log file. also check out original source http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild

Create an MSBuild_publish_site.bat (name it whatever) in the root of your web application project

set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319
set destPath=C:\Publish\MyWebBasedApp\

:: clear existing publish folder
RD /S /Q "%destPath%"

call %msBuildDir%\msbuild.exe  MyWebBasedApp.csproj "/p:Configuration=Debug;PublishDestination=%destPath%;AutoParameterizationWebConfigConnectionStrings=False" /t:PublishToFileSystem /l:FileLogger,Microsoft.Build.Engine;logfile=Manual_MSBuild_Publish_LOG.log

set msBuildDir=
set destPath=

Update your Web Application project file MyWebBasedApp.csproj by adding the following xml under the <Import Project= tag

<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>

this works better for me than other solutions.

Check out the following for more info:

1) http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild

2) Publish a Web Application from the Command Line

3) Build Visual Studio project through the command line

Booby answered 20/12, 2011 at 11:17 Comment(0)
B
1

My solution for CCNET with the Web.config transformation:

<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>
Bouffard answered 8/5, 2013 at 8:36 Comment(0)
M
1

On VS2012 and above, you can refer to existing publish profiles on your project with msbuild 12.0, this would be equivalent to right-click and publish... selecting a publish profile ("MyProfile" on this example):

msbuild C:\myproject\myproject.csproj "/P:DeployOnBuild=True;PublishProfile=MyProfile"
Medeah answered 26/9, 2014 at 19:58 Comment(0)
B
0

I've got a solution for Visual Studio 2012: https://mcmap.net/q/117101/-how-to-publish-web-with-msbuild

However, it works with no Visual Studio installed at all! (see UPDATE). I didn't checked yet whether one can get all needed stuff from Visual Studio Express 2012 for Web installation.

Benjy answered 15/3, 2013 at 5:28 Comment(0)
M
-1

A complete msbuild file with inspiration from CubanX

    <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="Publish">
        <RemoveDir Directories="..\build\Release\Web\"
                     ContinueOnError="true" />        
       <MSBuild Projects="TheWebSite.csproj"
                Targets="ResolveReferences;_CopyWebApplication"
                Properties="Configuration=Release;WebProjectOutputDir=..\build\Release\Web;OutDir=..\build\Release\Web\bin\"
        />  
    </Target>
    <Target
        Name="Build"
        DependsOnTargets="Publish;">
    </Target>   
</Project>

This places the published website in the Web..\build\Release folder

Modlin answered 12/9, 2012 at 11:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.