Add Repository.Version static property

This property returns a string containing the LibGit2Sharp version number, the commit hash it's been built against (if available), the libgit2 commit hash and the processor architecture.
This commit is contained in:
nulltoken 2012-03-31 18:25:19 +02:00
Родитель 412010c931
Коммит 2ca1913099
8 изменённых файлов: 74 добавлений и 5 удалений

Просмотреть файл

@ -9,7 +9,14 @@
<UsingTask AssemblyFile="$(MSBuildProjectDirectory)/Lib/xUnit/xunit.runner.msbuild.dll"
TaskName="Xunit.Runner.MSBuild.xunit" />
<Target Name="Clean">
<!-- Workaround for xbuild -->
<Message Text="Commit SHA = $(CommitSha)" />
<WriteLinesToFile Condition="'$(CommitSha)' != ''"
File="$(RootDir)\LibGit2Sharp\libgit2sharp_hash.txt"
Lines="$(CommitSha)"
Overwrite="true" />
<!-- Workaround for xbuild -->
<Exec Condition=" ('$(OS)' != 'Windows_NT') " Command=" rm -r -f $(DeployFolder) " />
<Exec Condition=" ('$(OS)' != 'Windows_NT') " Command=" rm -r -f $(TestBuildDir) " />

Просмотреть файл

@ -18,8 +18,7 @@ namespace LibGit2Sharp.Core
{
string originalAssemblypath = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
//TODO: When amd64 version of libgit2.dll is available, value this depending of the size of an IntPtr
const string currentArchSubPath = "NativeBinaries/x86";
string currentArchSubPath = "NativeBinaries/" + ProcessorArchitecture;
string path = Path.Combine(Path.GetDirectoryName(originalAssemblypath), currentArchSubPath);
@ -37,6 +36,19 @@ namespace LibGit2Sharp.Core
git_threads_shutdown();
}
public static string ProcessorArchitecture
{
get
{
//TODO: When amd64 version of libgit2.dll is available, uncomment the following lines
//if (IntPtr.Size == 8)
//{
// return "amd64";
//}
return "x86";
}
}
private static bool IsRunningOnLinux()
{
// see http://mono-project.com/FAQ%3a_Technical#Mono_Platforms

Просмотреть файл

@ -132,6 +132,12 @@
<ItemGroup>
<CodeAnalysisDictionary Include="CustomDictionary.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="libgit2_hash.txt" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="libgit2sharp_hash.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>

Просмотреть файл

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Compat;
using LibGit2Sharp.Core.Handles;
@ -22,6 +24,7 @@ namespace LibGit2Sharp
private readonly Lazy<RepositoryInformation> info;
private readonly bool isBare;
private readonly List<SafeHandleBase> handlesToCleanup = new List<SafeHandleBase>();
private static readonly Lazy<string> versionRetriever = new Lazy<string>(RetrieveVersion);
/// <summary>
/// Initializes a new instance of the <see cref = "Repository" /> class.
@ -356,5 +359,42 @@ namespace LibGit2Sharp
{
handlesToCleanup.Add(handleToCleanup);
}
/// <summary>
/// Gets the current LibGit2Sharp version.
/// <para>
/// The format of the version number is as follows:
/// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64)</para>
/// </para>
/// </summary>
public static string Version
{
get { return versionRetriever.Value; }
}
private static string RetrieveVersion()
{
Assembly assembly = typeof(Repository).Assembly;
Version version = assembly.GetName().Version;
string libgit2Hash = ReadContentFromResource(assembly, "libgit2_hash.txt");
string libgit2sharpHash = ReadContentFromResource(assembly, "libgit2sharp_hash.txt");
return string.Format("{0}-{1}-{2} ({3})",
version.ToString(3),
libgit2sharpHash.Substring(0, 7),
libgit2Hash.Substring(0,7),
NativeMethods.ProcessorArchitecture
);
}
private static string ReadContentFromResource(Assembly assembly, string partialResourceName)
{
using (var sr = new StreamReader(assembly.GetManifestResourceStream(string.Format("LibGit2Sharp.{0}", partialResourceName))))
{
return sr.ReadLine();
}
}
}
}

Просмотреть файл

@ -0,0 +1 @@
a17e882fab4e190d5a052cbc9cf6a238a9166a7c

Просмотреть файл

@ -0,0 +1 @@
unknown

Просмотреть файл

@ -3,8 +3,9 @@ SETLOCAL
SET BASEDIR=%~dp0
SET FrameworkVersion=v4.0.30319
SET FrameworkDir=%SystemRoot%\Microsoft.NET\Framework
SET CommitSha=%~1
"%FrameworkDir%\%FrameworkVersion%\msbuild.exe" "%BASEDIR%CI-build.msbuild"
"%FrameworkDir%\%FrameworkVersion%\msbuild.exe" "%BASEDIR%CI-build.msbuild" /property:CommitSha=%CommitSha%
ENDLOCAL

Просмотреть файл

@ -1,6 +1,7 @@
SETLOCAL
SET BASEDIR=%~dp0
SET SRCDIR=%BASEDIR%..\LibGit2Sharp\
SET CommitSha=%~1
REM the nuspec file needs to be next to the csproj, so copy it there during the pack operation
COPY "%BASEDIR%LibGit2Sharp.nuspec" "%SRCDIR%"
@ -9,7 +10,7 @@ PUSHD "%BASEDIR%"
DEL *.nupkg
CMD /c "..\build.libgit2sharp.cmd"
CMD /c "..\build.libgit2sharp.cmd %CommitSha%"
IF %ERRORLEVEL% NEQ 0 GOTO EXIT