发布从命令行Web应用程序 [英] Publish a Web Application from the Command Line

查看:507
本文介绍了发布从命令行Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列的同一个解决方案中的.NET 4的基于Web的应用程序(WCF和Web),但需要有选择地发布,在命令行。

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

我已经试过各种事情,到目前为止,MSBuild的,aspnet_compiler,但没有什么,到今天为止已经工作。

I've tried various things so far, MSBuild, aspnet_compiler, but nothing, to date has worked.

我需要能够指定项目,而不是解决方案,有任何转换运行,并且可以重定向到一个文件夹输出...基本上模拟天生鼠标右键单击发布选项,使用文件系统。

I need to be able to specify the Project, not the solution, have any transforms run and have the output redirected to a folder...basically mimick the right mouse click 'Publish' option, using the File System.

在除了这一切,我想独自离开项目 - 不增加的MSBuild文件,所有的地方,因为这是一个特定的构建,而不一定与项目相关的

In addition to all of this, I'd like to leave the projects alone - not adding msbuild files all over the place, as this is a specific build, and not necessarily related to the project.

东西,我已经试过:

  • Publish ASP.NET MVC 2 application from command line and Web.config transformations
  • Equivalent msbuild command for Publish from VS2008

推荐答案

保存到下面的脚本到 publishProject.bat 文件

Save to following script to the publishProject.bat file

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

修改
上述code适用于大多数情况下,但不是所有的。即我们使用的另一个ASP .NET应用程序,并将其链接在IIS虚拟文件夹中。对于这种情况VS2008正常工作与code以上,但VS2010还从虚拟目录拷贝文件,同时部署。下面code正常工作也在VS2010(<一个href=\"http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild\">solution在这里找到)

添加到您的项目文件(* .csproj的,* .vbproj)

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>

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

:: clear existed directory
RD /S /Q "%DestPath%"

:: build and publish project
MSBuild "%SrcPath%%ProjectName%.vbproj" "/p:Configuration=%Configuration%;AutoParameterizationWebConfigConnectionStrings=False;PublishDestination=%DestPath%" /t:PublishToFileSystem

这篇关于发布从命令行Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆