VS2010 Web Publish command line version of File System deploy

强颜欢笑 提交于 2019-11-28 16:11:50

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
zulucoda

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

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>

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"
Ivan Samygin

I've got a solution for Visual Studio 2012: https://stackoverflow.com/a/15387814/2164198

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!