用 MSBuild 发布 Asp.Net 工程

 方法1:用调用MSBuild执行自定义的MSBuild脚本文件

第一步:创建MSBuild脚本文件,并将其复制到目标工程所在路径。
第二步:用MSBuild执行上述脚本文件。
     [MSBuild.EXE path] /p:PublishProject=[Target project];Configuration=Release;PublishDestination=[Publish destination dir] /t:PublishToFileSystem [MSBuild file]
 
     例:
     MSBuild脚本文件(保存为SampleProject.build):
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" DefaultTargets="PublishToFileSystem"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     <Import Project="${PublishProject}" />
     <Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder">
          <ItemGroup>
               <PublishFile Include="${_PackageTempDir}\**\*.*" />
          </ItemGroup>
          <Copy SourceFile="@(PublishFile)"
                DestinationFiles="@(PublishFile->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')"
                SkipUnchangedFiles="True" />
     </Target>
</Project>
 
命令行执行:
>MSBuild /p:PublishProject=SampleProject.csproj;Configuration=Release;PublishDestination=\\192.168.1.2\SampleProject /t:PublishToFileSystem SampleProject.build
 
方法2:用NAnt或类似工具,先调用MSBuild编译,再复制结果文件到目标发布路径
第一步:调用MSBuild编译目标工程
编译结果所在路径为:
[ASP.NET project dir]/obj/[Debug/Release]/Package/PackageTmp
     第二步:将上一步所得编译结果复制到发布路径
 
     例(NAnt脚本):
<exec program="${MSBuild.EXE}" workingdir="${SampleProjectDir}">
     <arg value="SampleProject.csproj" />
     <arg value="/p:Configuration=Release" />
     <arg value="/clp:ErrorsOnly" />
     <arg value="/t:PipelinePreDeployCopyAllFilesToOneFolder" />
</exec>
<copy todir="${PublishDestination}" overwrite="true">
     <fileset basedir="${SampleProjectTmpPackageDir}">
          <include name="**.*" />
     </fileset>
</copy>
 

 

你可能感兴趣的:(asp.net,release,MSBuild)