Guest User

SVN/Nant ASP.NET Publishing

a guest
Jan 11th, 2011
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 4.82 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <project name="deploy" default="all">
  3.     <property name="nant.settings.currentframework" value="net-4.0" /> 
  4.     <!-- Any of these can be passed through the command line -->
  5.     <property name="sourceDirectory" value="${project::get-base-directory()}" />
  6.     <property name="publishDirectory" value="${sourceDirectory}\build" />
  7.     <property name="MSBuildPath" value="${framework::get-assembly-directory(framework::get-target-framework())}\msbuild.exe" />
  8.     <!-- The build configuration to use when publishing and transforming the web.config file. This is useful when you have multiple environments for which you create builds -->
  9.     <property name="buildConfiguration" value="Release" />
  10.     <!-- Set these as needed -->
  11.     <property name="svn.username" value="" />
  12.     <property name="svn.password" value="" />
  13.    
  14.     <target name="SvnPrep">
  15.         <property name="svn.dir" value="${publishDirectory}\.svn" />
  16.         <property name="svn.update" value="true" readonly="false" />
  17.         <echo>env.svn.path = svn</echo>
  18.         <echo>svn.dir = ${svn.dir}</echo>
  19.         <mkdir dir="${publishDirectory}" unless="${directory::exists(publishDirectory)}" />
  20.         <!-- Check if there's a .svn dir already. If not: checkout, else: update. -->
  21.         <if test="${not directory::exists(svn.dir)}">
  22.             <exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
  23.                 <arg line='co ${svn.builduri} --username ${svn.username} --password ${svn.password} --non-interactive ./' />
  24.             </exec>
  25.             <property name="svn.update" value="false" readonly="false" />
  26.         </if>
  27.         <if test="${svn.update}">
  28.             <exec program='svn.exe' workingdir="${publishDirectory}\" verbose="true">
  29.                 <arg line='up --username ${svn.username} --password ${svn.password} --non-interactive --force ./' />
  30.             </exec>
  31.         </if>
  32.         <!-- Force any conflicts to be resolved with the most recent code -->
  33.         <exec program='svn.exe' workingdir="${publishDirectory}\" verbose="true">
  34.             <arg line='resolve --accept theirs-full -R ./' />
  35.         </exec>
  36.     </target>  
  37.    
  38.     <target name="DeleteFiles">
  39.         <!-- Delete only the files (retain directory structure) in the directory to which you are going to publish/build. NAnt excludes svn directories by default. -->
  40.         <delete includeemptydirs="false">
  41.             <fileset basedir="${publishDirectory}">
  42.                 <include name="**/*.*" />
  43.             </fileset>
  44.         </delete>
  45.     </target>
  46.     <target name="Publish">
  47.         <!-- I know there's an MSBuild task, I don't know why I didn't use it, but this works. -->
  48.         <!-- Build and publish frontend -->
  49.         <exec program="${MSBuildPath}">
  50.             <arg line='"${sourceDirectory}\YourProject.csproj"' />
  51.             <arg value='"/p:Platform=AnyCPU;Configuration=${buildConfiguration};PublishDestination=${publishDirectory}"' />
  52.             <arg value="/target:PublishToFileSystem" />
  53.         </exec>
  54.         <!-- Transform the correct web.config and copy it to the build folder. PublishToFileSystem doesn't transform the web.config, unfortunately. -->
  55.         <exec program="${MSBuildPath}">
  56.             <arg line='"${sourceDirectory}\YourProject.csproj"' />
  57.             <arg value='"/p:Platform=AnyCPU;Configuration=${buildConfiguration};PublishDestination=${publishDirectory}"' />
  58.             <arg value="/target:TransformWebConfig" />
  59.         </exec>
  60.         <copy file="${sourceDirectory}\YourProject\obj\${buildConfiguration}\TransformWebConfig\transformed\Web.config" tofile="${publishDirectory}\YourProject\web.config" overwrite="true" />    
  61.     </target>
  62.    
  63.     <target name="SvnCommit">      
  64.         <!-- add any new files -->
  65.         <exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
  66.             <arg line='add --force .' />
  67.         </exec>
  68.         <!-- delete any missing files, a modification of this http://stackoverflow.com/questions/1071857/how-do-i-svn-add-all-unversioned-files-to-svn -->
  69.         <!-- When there's nothing to delete it looks like this fails (to NAnt) but it is actually fine, that's why failonerror is false -->    
  70.         <exec program='cmd.exe' workingdir="${publishDirectory}\" verbose="true" failonerror="false"
  71.             commandline='/C for /f "usebackq tokens=2*" %i in (`svn status ^| findstr /r "^\!"`) do svn del "%i %j"' >
  72.         </exec>
  73.         <exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
  74.             <arg line='commit -m "Automated commit from build runner"' />
  75.         </exec>
  76.     </target>
  77.    
  78.     <target name="ShowProperties">
  79.         <script language="C#" prefix="util" >
  80.             <code>
  81.                 <![CDATA[
  82.                 public static void ScriptMain(Project project)
  83.                 {
  84.                     foreach (DictionaryEntry entry in project.Properties)
  85.                     {
  86.                         Console.WriteLine("{0}={1}", entry.Key, entry.Value);
  87.                     }
  88.                 }
  89.                 ]]>
  90.             </code>
  91.         </script>
  92.     </target>
  93.    
  94.     <target name="all">
  95.         <call target="ShowProperties" />
  96.         <call target="SvnPrep" />
  97.             <call target="DeleteFiles" />
  98.         <call target="Publish" />
  99.         <call target="SvnCommit" />
  100.     </target>
  101. </project>
Advertisement
Add Comment
Please, Sign In to add comment