Source

SubSpec / SubSpec.msbuild

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    
	<UsingTask
        AssemblyFile="tools\CodePlex.MSBuildTasks.dll"
        TaskName="CodePlex.MSBuildTasks.RegexReplace"/>
    <UsingTask
        AssemblyFile="tools\CodePlex.MSBuildTasks.dll"
        TaskName="CodePlex.MSBuildTasks.Zip"/>

    <!-- Settings -->

    <PropertyGroup>
        <Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
        <TrackFileAccess>false</TrackFileAccess>
    </PropertyGroup>

    <!-- Cascading attempts to find a build number -->

    <PropertyGroup Condition="'$(BuildNumber)' == ''">
        <BuildNumber>$(BUILD_NUMBER)</BuildNumber>
    </PropertyGroup>
    <PropertyGroup Condition="'$(BuildNumber)' == ''">
        <BuildNumber>$(ccnetlabel)</BuildNumber>
    </PropertyGroup>
    <PropertyGroup Condition="'$(BuildNumber)' == ''">
        <BuildNumber>0</BuildNumber>
    </PropertyGroup>
	
	<!--Get the xUnit version we are using, so we can set SubSpecs version number accordingly-->
	
	<PropertyGroup>
		<xUnitPackageDir>$([System.IO.Directory]::GetDirectories('packages', 'xunit.?.*'))</xUnitPackageDir>	
		<xUnitVersion>$([System.Text.RegularExpressions.Regex]::Match($(xUnitPackageDir), `\d.\d.\d`))</xUnitVersion>
	</PropertyGroup>
	
	<Target Name="SetVersionNumber">
		<Message Text="Inferring version number from $(xUnitPackageDir): $(xUnitVersion)" />
		
        <ItemGroup>
            <NuspecFiles Include="*.nuspec" />
        </ItemGroup>
        <RegexReplace
            Pattern='AssemblyVersion\("(\d+\.\d+\.\d+)\.\d+"\)'
            Replacement='AssemblyVersion("$(xUnitVersion).$(BuildNumber)")'
            Files='GlobalAssemblyInfo.cs'/>
        <RegexReplace
            Pattern='&lt;version&gt;(\d+\.\d+\.\d+)\.\d+&lt;/version&gt;'
            Replacement='&lt;version&gt;$(xUnitVersion).$(BuildNumber)&lt;/version&gt;'
            Files='@(NuspecFiles)'/>
        <RegexReplace
            Pattern='version=&quot;(\d+\.\d+\.\d+)\.\d+&quot;'
            Replacement='version=&quot;$(xUnitVersion).$(BuildNumber)&quot;'
            Files='@(NuspecFiles)'/>
    </Target>

    <!-- Build server targets -->

    <Target Name="TeamCity" DependsOnTargets="Clean;SetVersionNumber;Build;Test;Deploy" />
	
    <!-- Individiual targets -->

    <Target Name="Clean">
        <ItemGroup>
            <CleanFileList
                Include="build\*"/>
        </ItemGroup>
        <Delete Files="@(CleanFileList)"/>
        <MSBuild
            Projects="SubSpec.sln"
            Targets="Clean"
            Properties="Configuration=$(Configuration);TrackFileAccess=$(TrackFileAccess)"/>
    </Target>

    <Target Name="Build">
		<MakeDir Directories='build'/>
        <MSBuild
            Projects="SubSpec.sln"
            Targets="Build"
            Properties="Configuration=$(Configuration);TrackFileAccess=$(TrackFileAccess)"/>
	  </Target>

    <ItemGroup>
      <TestProjects Include="*.tests.msbuild"/>
    </ItemGroup>

    <Target Name="Test">
      <MSBuild
        Projects="SubSpec.tests.msbuild;SubSpec.Silverlight.tests.msbuild"
        BuildInParallel="true"
        Properties="Configuration=$(Configuration)"/>
    </Target>
  
    <Target Name="Packages" DependsOnTargets="Build">
		<!-- SubSpec.nuspec -->
        <ItemGroup>
            <DeployableFiles Include="LICENSE.txt"/>
            <DeployableFiles Include="src\*.*"/>
        </ItemGroup>
		
		<MakeDir Directories='build\packaging\content\SubSpec'/>
        <Copy
            SourceFiles="@(DeployableFiles)"
            DestinationFolder='build\packaging\content\SubSpec'/>
        <Exec Command='tools\NuGet.exe pack SubSpec.nuspec -BasePath build\packaging -OutputDirectory build' />
        <RemoveDir Directories='build\packaging'/>
    </Target>

    <Target Name="Zip" DependsOnTargets="Build">
        <ItemGroup>
            <ZipFileList Include="LICENSE.txt"/>
            <ZipFileList Include="src\*.*"/>
        </ItemGroup>
        <Delete Files="build\SubSpec-build-$(BuildNumber).zip"/>
        <Zip
            ZipFileName="build\SubSpec-build-$(BuildNumber).zip"
            Files="@(ZipFileList)"
            StripPath="true"/>
    </Target>
	
	<Target Name="Deploy" DependsOnTargets="Zip;Packages"/>
</Project>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.