Skip to content

Commit

Permalink
Version with GitVersionTask
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnoonan committed Nov 13, 2015
1 parent c8c327a commit 4938061
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 47 deletions.
1 change: 1 addition & 0 deletions GitVersionConfig.yaml
@@ -0,0 +1 @@
mode: ContinuousDeployment
9 changes: 9 additions & 0 deletions source/OctopusTools.Tests/OctopusTools.Tests.csproj
Expand Up @@ -13,6 +13,8 @@
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -100,6 +102,13 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="..\packages\GitVersionTask.3.3.0\build\dotnet\GitVersionTask.targets" Condition="Exists('..\packages\GitVersionTask.3.3.0\build\dotnet\GitVersionTask.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\GitVersionTask.3.3.0\build\dotnet\GitVersionTask.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\GitVersionTask.3.3.0\build\dotnet\GitVersionTask.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
1 change: 1 addition & 0 deletions source/OctopusTools.Tests/packages.config
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GitVersionTask" version="3.3.0" targetFramework="net45" developmentDependency="true" />
<package id="log4net" version="2.0.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="NSubstitute" version="1.7.2.0" targetFramework="net45" />
Expand Down
9 changes: 9 additions & 0 deletions source/OctopusTools/OctopusTools.csproj
Expand Up @@ -14,6 +14,8 @@
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
Expand Down Expand Up @@ -201,6 +203,13 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="..\packages\GitVersionTask.3.3.0\build\dotnet\GitVersionTask.targets" Condition="Exists('..\packages\GitVersionTask.3.3.0\build\dotnet\GitVersionTask.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\GitVersionTask.3.3.0\build\dotnet\GitVersionTask.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\GitVersionTask.3.3.0\build\dotnet\GitVersionTask.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
2 changes: 1 addition & 1 deletion source/OctopusTools/Program.cs
Expand Up @@ -21,7 +21,7 @@ public class Program

static int Main(string[] args)
{
Log.Info("Octopus Deploy Command Line Tool, version " + typeof (Program).Assembly.GetFileVersion());
Log.Info("Octopus Deploy Command Line Tool, version " + typeof (Program).Assembly.GetInformationalVersion());
Console.Title = "Octopus Deploy Command Line Tool";
Log.Info(string.Empty);

Expand Down
8 changes: 5 additions & 3 deletions source/OctopusTools/Util/AssemblyExtensions.cs
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;

Expand All @@ -15,8 +16,9 @@ public static string FullLocalPath(this Assembly assembly)
return root;
}

public static string GetFileVersion(this Assembly assembly)
{
return assembly.GetCustomAttributes(true).OfType<AssemblyFileVersionAttribute>().First().Version;
public static string GetInformationalVersion(this Assembly assembly)
{
var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
return fileVersionInfo.ProductVersion;
}
}
1 change: 1 addition & 0 deletions source/OctopusTools/packages.config
Expand Up @@ -2,6 +2,7 @@
<packages>
<package id="Autofac" version="3.5.2" targetFramework="net45" />
<package id="ILRepack" version="2.0.8" targetFramework="net45" />
<package id="GitVersionTask" version="3.3.0" targetFramework="net45" developmentDependency="true" />
<package id="log4net" version="2.0.2" targetFramework="net45" />
<package id="MarkdownSharp" version="1.13.0.0" targetFramework="net45" />
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net45" />
Expand Down
16 changes: 1 addition & 15 deletions source/Solution Items/VersionInfo.cs
@@ -1,15 +1 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.235
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
// Versioned by GitVersionTask
20 changes: 2 additions & 18 deletions tools/Build.proj
Expand Up @@ -47,22 +47,6 @@
<MakeDir Directories="$(Root)\build\Artifacts" Condition="!Exists('$(Root)\build\Artifacts')" />
</Target>

<!--
Versioning
-->
<Target Name="Versioning">
<AssemblyInfo
CodeLanguage="CS"
OutputFile="$(Root)\source\Solution Items\VersionInfo.cs"
AssemblyVersion="$(build_number)"
AssemblyFileVersion="$(build_number)"
/>
<FileUpdate Files="$(Root)\source\OctopusTools\OctopusTools.nuspec"
Regex='version>[0-9]+.[0-9]+.[0-9]+.[0-9]+'
ReplacementText='version>$(build_number)'
/>
</Target>

<!--
Compile
-->
Expand Down Expand Up @@ -93,7 +77,7 @@
</ItemGroup>
<Copy SourceFiles="@(PackagedFiles)" DestinationFolder="$(Root)\build\Temp" />

<Exec Command='"$(NuGetPath)\NuGet.exe" pack "OctopusTools.nuspec" -verbosity detailed' WorkingDirectory='$(Root)\build\Temp' />
<Exec Command='"$(NuGetPath)\NuGet.exe" pack "OctopusTools.nuspec" -version $(build_number) -verbosity detailed' WorkingDirectory='$(Root)\build\Temp' />
<Copy SourceFiles="$(Root)\build\Temp\OctopusTools.$(build_number).nupkg" DestinationFiles="$(Root)\build\Artifacts\OctopusTools.$(build_number).nupkg" />

<ItemGroup>
Expand Down Expand Up @@ -138,5 +122,5 @@
<!--
BuildAndPublish
-->
<Target Name="BuildAndPublish" DependsOnTargets="Versioning;PublishArtifacts;Test;Diagnose" />
<Target Name="BuildAndPublish" DependsOnTargets="PublishArtifacts;Test;Diagnose" />
</Project>
22 changes: 12 additions & 10 deletions tools/Build.psm1
@@ -1,21 +1,23 @@
$msbuild = "MSBuild.exe"

function Create-OctopusToolsRelease ([string]$BuildNumber="0.0.0")
function Create-OctopusToolsRelease
{
<#
.Synopsis
Builds a complete release (compile, test, ILMerge, NuGet package, version stamp)
#>
& $msbuild "Tools\Build.proj" /p:build_number=$BuildNumber /t:BuildAndPublish /v:d
}

function Create-OctopusToolsPackage
{
<#
.Synopsis
Compiles, tests, runs ILMerge
#>
& $msbuild "Tools\Build.proj" /t:BuildAndPackage /v:d
$output = . "Tools\GitVersion\gitversion.exe"

$formattedOutput = $output -join "`n"
Write-Host "Output from gitversion.exe"
Write-Host $formattedOutput

$versionInfo = $formattedOutput | ConvertFrom-Json
$script:package_version = $versionInfo.NuGetVersion
write-host "Package version: $script:package_version"

& $msbuild "Tools\Build.proj" /p:build_number=$package_version /t:BuildAndPublish /v:d
}

Export-ModuleMember -function * -alias *
Binary file added tools/GitVersion/GitVersion.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 4938061

Please sign in to comment.