diff --git a/build.cake b/build.cake
index 93a3b2ac36..2182c6fc78 100644
--- a/build.cake
+++ b/build.cake
@@ -238,6 +238,24 @@ Task("Copy-Files")
MSBuildSettings = parameters.MSBuildSettings
});
+ DotNetCorePublish("./src/GitVersionTask/GitVersionTask.csproj", new DotNetCorePublishSettings
+ {
+ Framework = parameters.FullFxVersion,
+ NoBuild = true,
+ NoRestore = true,
+ Configuration = parameters.Configuration,
+ MSBuildSettings = parameters.MSBuildSettings
+ });
+
+ // .NET Core
+ DotNetCorePublish("./src/GitVersionTask/GitVersionTask.csproj", new DotNetCorePublishSettings
+ {
+ Framework = parameters.CoreFxVersion,
+ NoBuild = true,
+ NoRestore = true,
+ Configuration = parameters.Configuration,
+ MSBuildSettings = parameters.MSBuildSettings
+ });
var ilMergeDir = parameters.Paths.Directories.ArtifactsBinFullFxILMerge;
var portableDir = parameters.Paths.Directories.ArtifactsBinFullFxPortable.Combine("tools");
var cmdlineDir = parameters.Paths.Directories.ArtifactsBinFullFxCmdline.Combine("tools");
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index a49ae73fe3..fc53ff1116 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -14,7 +14,7 @@
- 0.25.0-preview-0033
+ 0.26.0
2019.1.1
6.1.1
diff --git a/src/Docker/net472/linux/debian-9/Dockerfile b/src/Docker/net472/linux/debian-9/Dockerfile
index fe3ded82a8..fe2779cb31 100644
--- a/src/Docker/net472/linux/debian-9/Dockerfile
+++ b/src/Docker/net472/linux/debian-9/Dockerfile
@@ -2,10 +2,6 @@ FROM mono:5.14
LABEL maintainers="GitTools Maintainers"
ARG contentFolder
-RUN sed -i '/jessie-updates/d' /etc/apt/sources.list && apt-get update && \
- apt-get install -y libgit2-dev && \
- ln -s /usr/lib/x86_64-linux-gnu/libgit2.so /lib/x86_64-linux-gnu/libgit2-15e1193.so
-
WORKDIR /app
COPY $contentFolder/ ./
diff --git a/src/Docker/netcoreapp2.1/linux/centos-7/Dockerfile b/src/Docker/netcoreapp2.1/linux/centos-7/Dockerfile
index 232b07ac9c..2851e09fc0 100644
--- a/src/Docker/netcoreapp2.1/linux/centos-7/Dockerfile
+++ b/src/Docker/netcoreapp2.1/linux/centos-7/Dockerfile
@@ -1,7 +1,7 @@
FROM centos:7
LABEL maintainers="GitTools Maintainers"
-ENV DOTNET_VERSION='2.1'
+ENV DOTNET_VERSION='2.1'
ARG contentFolder
# https://dotnet.microsoft.com/download/linux-package-manager/rhel/sdk-current
@@ -9,13 +9,11 @@ RUN rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-pro
&& yum update cache
# if you need SDK use dotnet-sdk-$DOTNET_VERSION
-RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 unzip libgit2-devel.x86_64 \
+RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 \
&& yum clean all \
&& rm -rf /tmp/*
-RUN ln -s /usr/lib64/libgit2.so /usr/lib64/libgit2-15e1193.so
-
WORKDIR /app
COPY $contentFolder/ ./
-ENTRYPOINT ["dotnet", "GitVersion.dll"]
\ No newline at end of file
+ENTRYPOINT ["dotnet", "GitVersion.dll"]
diff --git a/src/Docker/netcoreapp2.1/linux/debian-9/Dockerfile b/src/Docker/netcoreapp2.1/linux/debian-9/Dockerfile
index b9c29dbec3..f71693f154 100644
--- a/src/Docker/netcoreapp2.1/linux/debian-9/Dockerfile
+++ b/src/Docker/netcoreapp2.1/linux/debian-9/Dockerfile
@@ -2,10 +2,6 @@ FROM mcr.microsoft.com/dotnet/core/runtime:2.1
LABEL maintainers="GitTools Maintainers"
ARG contentFolder
-RUN apt-get update && \
- apt-get install -y libgit2-dev && \
- ln -s /usr/lib/x86_64-linux-gnu/libgit2.so /lib/x86_64-linux-gnu/libgit2-15e1193.so
-
WORKDIR /app
COPY $contentFolder/ ./
diff --git a/src/Docker/netcoreapp2.1/linux/fedora-27/Dockerfile b/src/Docker/netcoreapp2.1/linux/fedora-27/Dockerfile
index c97acb7606..ad12a1fca2 100644
--- a/src/Docker/netcoreapp2.1/linux/fedora-27/Dockerfile
+++ b/src/Docker/netcoreapp2.1/linux/fedora-27/Dockerfile
@@ -1,20 +1,18 @@
FROM fedora:27
LABEL maintainers="GitTools Maintainers"
-ENV DOTNET_VERSION='2.1'
+ENV DOTNET_VERSION='2.1'
ARG contentFolder
# https://dotnet.microsoft.com/download/linux-package-manager/rhel/sdk-current
-RUN rpm -Uvh https://packages.microsoft.com/config/fedora/27/packages-microsoft-prod.rpm
+RUN rpm -Uvh https://packages.microsoft.com/config/fedora/27/packages-microsoft-prod.rpm
# if you need SDK use dotnet-sdk-$DOTNET_VERSION
-RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 unzip libgit2-devel.x86_64 \
+RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64\
&& yum clean all \
&& rm -rf /tmp/*
-RUN ln -s /usr/lib64/libgit2.so /usr/lib64/libgit2-15e1193.so
-
WORKDIR /app
COPY $contentFolder/ ./
-ENTRYPOINT ["dotnet", "GitVersion.dll"]
\ No newline at end of file
+ENTRYPOINT ["dotnet", "GitVersion.dll"]
diff --git a/src/Docker/netcoreapp2.2/linux/centos-7/Dockerfile b/src/Docker/netcoreapp2.2/linux/centos-7/Dockerfile
index 361051cafa..eb2928cd24 100644
--- a/src/Docker/netcoreapp2.2/linux/centos-7/Dockerfile
+++ b/src/Docker/netcoreapp2.2/linux/centos-7/Dockerfile
@@ -9,12 +9,10 @@ RUN rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-pro
&& yum update cache
# if you need SDK use dotnet-sdk-$DOTNET_VERSION
-RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 unzip libgit2-devel.x86_64 \
+RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 \
&& yum clean all \
&& rm -rf /tmp/*
-RUN ln -s /usr/lib64/libgit2.so /usr/lib64/libgit2-15e1193.so
-
WORKDIR /app
COPY $contentFolder/ ./
diff --git a/src/Docker/netcoreapp2.2/linux/debian-9/Dockerfile b/src/Docker/netcoreapp2.2/linux/debian-9/Dockerfile
index 288a8b9bb8..bddb968314 100644
--- a/src/Docker/netcoreapp2.2/linux/debian-9/Dockerfile
+++ b/src/Docker/netcoreapp2.2/linux/debian-9/Dockerfile
@@ -2,10 +2,6 @@ FROM mcr.microsoft.com/dotnet/core/runtime:2.2
LABEL maintainers="GitTools Maintainers"
ARG contentFolder
-RUN apt-get update && \
- apt-get install -y libgit2-dev && \
- ln -s /usr/lib/x86_64-linux-gnu/libgit2.so /lib/x86_64-linux-gnu/libgit2-15e1193.so
-
WORKDIR /app
COPY $contentFolder/ ./
diff --git a/src/Docker/netcoreapp2.2/linux/fedora-27/Dockerfile b/src/Docker/netcoreapp2.2/linux/fedora-27/Dockerfile
index dece7f6f6f..fa628e82be 100644
--- a/src/Docker/netcoreapp2.2/linux/fedora-27/Dockerfile
+++ b/src/Docker/netcoreapp2.2/linux/fedora-27/Dockerfile
@@ -5,15 +5,13 @@ ENV DOTNET_VERSION='2.2'
ARG contentFolder
# https://dotnet.microsoft.com/download/linux-package-manager/rhel/sdk-current
-RUN rpm -Uvh https://packages.microsoft.com/config/fedora/27/packages-microsoft-prod.rpm
+RUN rpm -Uvh https://packages.microsoft.com/config/fedora/27/packages-microsoft-prod.rpm
# if you need SDK use dotnet-sdk-$DOTNET_VERSION
-RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 unzip libgit2-devel.x86_64 \
+RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 \
&& yum clean all \
&& rm -rf /tmp/*
-RUN ln -s /usr/lib64/libgit2.so /usr/lib64/libgit2-15e1193.so
-
WORKDIR /app
COPY $contentFolder/ ./
diff --git a/src/GitVersion.sln b/src/GitVersion.sln
index 905eca67b7..3792ed65a1 100644
--- a/src/GitVersion.sln
+++ b/src/GitVersion.sln
@@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitVersionTask", "GitVersio
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitVersion.Tool", "GitVersionExe\GitVersion.Tool.csproj", "{929263FD-5CD2-42E1-BF3D-E0C1B0320DA4}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionTask.MsBuild", "GitVersionTask.MsBuild\GitVersionTask.MsBuild.csproj", "{0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -68,6 +70,10 @@ Global
{929263FD-5CD2-42E1-BF3D-E0C1B0320DA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{929263FD-5CD2-42E1-BF3D-E0C1B0320DA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{929263FD-5CD2-42E1-BF3D-E0C1B0320DA4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/GitVersionCore.Tests/Mocks/MockRepository.cs b/src/GitVersionCore.Tests/Mocks/MockRepository.cs
index 33e8709a4d..4bd39d65a8 100644
--- a/src/GitVersionCore.Tests/Mocks/MockRepository.cs
+++ b/src/GitVersionCore.Tests/Mocks/MockRepository.cs
@@ -225,6 +225,7 @@ public IQueryableCommitLog Commits
public ObjectDatabase ObjectDatabase { get; set; }
public NoteCollection Notes { get; set; }
public SubmoduleCollection Submodules { get; set; }
+ public WorktreeCollection Worktrees { get; set; }
public Rebase Rebase { get; private set; }
public Ignore Ignore
diff --git a/src/GitVersionTask.MsBuild/GitVersionTask.MsBuild.csproj b/src/GitVersionTask.MsBuild/GitVersionTask.MsBuild.csproj
new file mode 100644
index 0000000000..87c3f852fa
--- /dev/null
+++ b/src/GitVersionTask.MsBuild/GitVersionTask.MsBuild.csproj
@@ -0,0 +1,21 @@
+
+
+
+ net461;netstandard2.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/GitVersionTask.MsBuild/GitVersionTaskBase.cs b/src/GitVersionTask.MsBuild/GitVersionTaskBase.cs
new file mode 100644
index 0000000000..76a6ef68c0
--- /dev/null
+++ b/src/GitVersionTask.MsBuild/GitVersionTaskBase.cs
@@ -0,0 +1,13 @@
+namespace GitVersionTask.MsBuild
+{
+ using Microsoft.Build.Framework;
+ using Microsoft.Build.Utilities;
+
+ public abstract class GitVersionTaskBase : Task
+ {
+ [Required]
+ public string SolutionDirectory { get; set; }
+
+ public bool NoFetch { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/GitVersionTask.MsBuild/LibGit2Sharp/GitLoaderContext.cs b/src/GitVersionTask.MsBuild/LibGit2Sharp/GitLoaderContext.cs
new file mode 100644
index 0000000000..32ad0ab81a
--- /dev/null
+++ b/src/GitVersionTask.MsBuild/LibGit2Sharp/GitLoaderContext.cs
@@ -0,0 +1,87 @@
+// This code originally copied from https://raw.githubusercontent.com/dotnet/sourcelink/master/src/Microsoft.Build.Tasks.Git/GitLoaderContext.cs
+#if !NET461
+namespace GitVersionTask.MsBuild.LibGit2Sharp
+{
+ using System;
+ using System.IO;
+ using System.Linq;
+ using System.Reflection;
+ using System.Runtime.InteropServices;
+ using System.Runtime.Loader;
+ using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;
+
+ public sealed class GitLoaderContext : AssemblyLoadContext
+ {
+ private readonly string[] assemblies;
+ public static GitLoaderContext Instance { get; private set; }
+
+ private GitLoaderContext(string[] assemblies) => this.assemblies = assemblies;
+
+ public static void Init(params string[] assemblies) => Instance = new GitLoaderContext(assemblies);
+
+ protected override Assembly Load(AssemblyName assemblyName)
+ {
+ if (assemblies.Contains(assemblyName.Name))
+ {
+ var path = Path.Combine(Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location), assemblyName.Name + ".dll");
+ return LoadFromAssemblyPath(path);
+ }
+
+ return Default.LoadFromAssemblyName(assemblyName);
+ }
+
+ protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
+ {
+ var modulePtr = IntPtr.Zero;
+
+ if (unmanagedDllName.StartsWith("git2-", StringComparison.Ordinal) ||
+ unmanagedDllName.StartsWith("libgit2-", StringComparison.Ordinal))
+ {
+ var directory = GetNativeLibraryDirectory();
+ var extension = GetNativeLibraryExtension();
+
+ if (!unmanagedDllName.EndsWith(extension, StringComparison.Ordinal))
+ {
+ unmanagedDllName += extension;
+ }
+
+ var nativeLibraryPath = Path.Combine(directory, unmanagedDllName);
+ if (!File.Exists(nativeLibraryPath))
+ {
+ nativeLibraryPath = Path.Combine(directory, "lib" + unmanagedDllName);
+ }
+
+ modulePtr = LoadUnmanagedDllFromPath(nativeLibraryPath);
+ }
+
+ return modulePtr != IntPtr.Zero ? modulePtr : base.LoadUnmanagedDll(unmanagedDllName);
+ }
+
+ private static string GetNativeLibraryDirectory()
+ {
+ var dir = Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location);
+ return Path.Combine(dir, "runtimes", RuntimeIdMap.GetNativeLibraryDirectoryName(RuntimeEnvironment.GetRuntimeIdentifier()), "native");
+ }
+
+ private static string GetNativeLibraryExtension()
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ return ".dll";
+ }
+
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ {
+ return ".dylib";
+ }
+
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+ {
+ return ".so";
+ }
+
+ throw new PlatformNotSupportedException();
+ }
+ }
+}
+#endif
diff --git a/src/GitVersionTask.MsBuild/LibGit2Sharp/LibGit2SharpLoader.cs b/src/GitVersionTask.MsBuild/LibGit2Sharp/LibGit2SharpLoader.cs
new file mode 100644
index 0000000000..2fb18cfdf7
--- /dev/null
+++ b/src/GitVersionTask.MsBuild/LibGit2Sharp/LibGit2SharpLoader.cs
@@ -0,0 +1,90 @@
+// This code originally copied and adapted from https://raw.githubusercontent.com/dotnet/sourcelink/master/src/Microsoft.Build.Tasks.Git/TaskImplementation.cs
+
+namespace GitVersionTask.MsBuild.LibGit2Sharp
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Reflection;
+
+ public class LibGit2SharpLoader
+ {
+ private static string taskDirectory;
+
+ public static LibGit2SharpLoader Instance { get; private set; }
+ public Assembly Assembly { get; }
+
+ public static void LoadAssembly(string tasksAssembly) => Instance = new LibGit2SharpLoader(tasksAssembly);
+
+ private LibGit2SharpLoader(string tasksAssembly)
+ {
+ taskDirectory = Path.GetDirectoryName(typeof(LibGit2SharpLoader).Assembly.Location);
+#if NET461
+ nullVersion = new Version(0, 0, 0, 0);
+ loaderLog = new List();
+
+ AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
+
+ var assemblyName = typeof(LibGit2SharpLoader).Assembly.GetName();
+ assemblyName.Name = tasksAssembly;
+ Assembly = Assembly.Load(assemblyName);
+#else
+ var operationsPath = Path.Combine(taskDirectory, tasksAssembly + ".dll");
+ Assembly = GitLoaderContext.Instance.LoadFromAssemblyPath(operationsPath);
+#endif
+ }
+
+
+#if NET461
+
+ private static Version nullVersion;
+
+ private static List loaderLog;
+
+ private static void Log(ResolveEventArgs args, string outcome)
+ {
+ lock (loaderLog)
+ {
+ loaderLog.Add($"Loading '{args.Name}' referenced by '{args.RequestingAssembly}': {outcome}.");
+ }
+ }
+
+ public static string[] GetLog()
+ {
+ lock (loaderLog)
+ {
+ return loaderLog.ToArray();
+ }
+ }
+
+ private static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
+ {
+ // Limit resolution scope to minimum to affect the rest of msbuild as little as possible.
+ // Only resolve System.* assemblies from the task directory that are referenced with 0.0.0.0 version (from netstandard.dll).
+
+ var referenceName = new AssemblyName(args.Name);
+ if (!referenceName.Name.StartsWith("System.", StringComparison.OrdinalIgnoreCase))
+ {
+ Log(args, "not System");
+ return null;
+ }
+
+ if (referenceName.Version != nullVersion)
+ {
+ Log(args, "not null version");
+ return null;
+ }
+
+ var referencePath = Path.Combine(taskDirectory, referenceName.Name + ".dll");
+ if (!File.Exists(referencePath))
+ {
+ Log(args, $"file '{referencePath}' not found");
+ return null;
+ }
+
+ Log(args, $"loading from '{referencePath}'");
+ return Assembly.Load(AssemblyName.GetAssemblyName(referencePath));
+ }
+#endif
+ }
+}
diff --git a/src/GitVersionTask.MsBuild/LibGit2Sharp/RuntimeIdMap.cs b/src/GitVersionTask.MsBuild/LibGit2Sharp/RuntimeIdMap.cs
new file mode 100644
index 0000000000..716d891f21
--- /dev/null
+++ b/src/GitVersionTask.MsBuild/LibGit2Sharp/RuntimeIdMap.cs
@@ -0,0 +1,378 @@
+// This code originally copied from https://raw.githubusercontent.com/dotnet/sourcelink/master/src/Microsoft.Build.Tasks.Git/RuntimeIdMap.cs
+#if !NET461
+
+namespace GitVersionTask.MsBuild.LibGit2Sharp
+{
+ using System;
+ using System.Diagnostics;
+
+ internal static class RuntimeIdMap
+ {
+ // This functionality needs to be provided as .NET Core API.
+ // Releated issues:
+ // https://github.com/dotnet/core-setup/issues/1846
+ // https://github.com/NuGet/Home/issues/5862
+
+ public static string GetNativeLibraryDirectoryName(string runtimeIdentifier)
+ {
+#if DEBUG
+ Debug.Assert(s_directories.Length == s_rids.Length);
+
+ for (int i = 1; i < s_rids.Length; i++)
+ {
+ Debug.Assert(StringComparer.Ordinal.Compare(s_rids[i - 1], s_rids[i]) < 0);
+ }
+#endif
+ int index = Array.BinarySearch(s_rids, runtimeIdentifier, StringComparer.Ordinal);
+ if (index < 0)
+ {
+ // Take the runtime id with highest version of matching OS.
+ // The runtimes in the table are currently sorted so that this works.
+
+ ParseRuntimeId(runtimeIdentifier, out var runtimeOS, out var runtimeVersion, out var runtimeQualifiers);
+
+ // find version-less rid:
+ int bestMatchIndex = -1;
+ string[] bestVersion = null;
+
+ void FindBestCandidate(int startIndex, int increment)
+ {
+ int i = startIndex;
+ while (i >= 0 && i < s_rids.Length)
+ {
+ string candidate = s_rids[i];
+ ParseRuntimeId(candidate, out var candidateOS, out var candidateVersion, out var candidateQualifiers);
+ if (candidateOS != runtimeOS)
+ {
+ break;
+ }
+
+ // Find the highest available version that is lower than or equal to the runtime version
+ // among candidates that have the same qualifiers.
+ if (candidateQualifiers == runtimeQualifiers &&
+ CompareVersions(candidateVersion, runtimeVersion) <= 0 &&
+ (bestVersion == null || CompareVersions(candidateVersion, bestVersion) > 0))
+ {
+ bestMatchIndex = i;
+ bestVersion = candidateVersion;
+ }
+
+ i += increment;
+ }
+ }
+
+ FindBestCandidate(~index - 1, -1);
+ FindBestCandidate(~index, +1);
+
+ if (bestMatchIndex < 0)
+ {
+ throw new PlatformNotSupportedException(runtimeIdentifier);
+ }
+
+ index = bestMatchIndex;
+ }
+
+ return s_directories[index];
+ }
+
+ internal static int CompareVersions(string[] left, string[] right)
+ {
+ for (int i = 0; i < Math.Max(left.Length, right.Length); i++)
+ {
+ // pad with zeros (consider "1.2" == "1.2.0")
+ var leftPart = (i < left.Length) ? left[i] : "0";
+ var rightPart = (i < right.Length) ? right[i] : "0";
+
+ int result;
+ if (!int.TryParse(leftPart, out var leftNumber) || !int.TryParse(rightPart, out var rightNumber))
+ {
+ // alphabetical order:
+ result = StringComparer.Ordinal.Compare(leftPart, rightPart);
+ }
+ else
+ {
+ // numerical order:
+ result = leftNumber.CompareTo(rightNumber);
+ }
+
+ if (result != 0)
+ {
+ return result;
+ }
+ }
+
+ return 0;
+ }
+
+ internal static void ParseRuntimeId(string runtimeId, out string osName, out string[] version, out string qualifiers)
+ {
+ // We use the following convention in all newly-defined RIDs. Some RIDs (win7-x64, win8-x64) predate this convention and don't follow it, but all new RIDs should follow it.
+ // [os name].[version]-[architecture]-[additional qualifiers]
+ // See https://github.com/dotnet/corefx/blob/master/pkg/Microsoft.NETCore.Platforms/readme.md#naming-convention
+
+ int versionSeparator = runtimeId.IndexOf('.');
+ if (versionSeparator >= 0)
+ {
+ osName = runtimeId.Substring(0, versionSeparator);
+ }
+ else
+ {
+ osName = null;
+ }
+
+ int architectureSeparator = runtimeId.IndexOf('-', versionSeparator + 1);
+ if (architectureSeparator >= 0)
+ {
+ if (versionSeparator >= 0)
+ {
+ version = runtimeId.Substring(versionSeparator + 1, architectureSeparator - versionSeparator - 1).Split('.');
+ }
+ else
+ {
+ osName = runtimeId.Substring(0, architectureSeparator);
+ version = Array.Empty();
+ }
+
+ qualifiers = runtimeId.Substring(architectureSeparator + 1);
+ }
+ else
+ {
+ if (versionSeparator >= 0)
+ {
+ version = runtimeId.Substring(versionSeparator + 1).Split('.');
+ }
+ else
+ {
+ osName = runtimeId;
+ version = Array.Empty();
+ }
+
+ qualifiers = string.Empty;
+ }
+ }
+
+ // The following tables were generated by scripts/RuntimeIdMapGenerator.csx.
+ // Regenerate when upgrading LibGit2Sharp to a new version that supports more platforms.
+
+ private static readonly string[] s_rids = new[]
+ {
+ "alpine-x64",
+ "alpine.3.6-x64",
+ "alpine.3.7-x64",
+ "alpine.3.8-x64",
+ "alpine.3.9-x64",
+ "centos-x64",
+ "centos.7-x64",
+ "debian-x64",
+ "debian.8-x64",
+ "debian.9-x64",
+ "fedora-x64",
+ "fedora.23-x64",
+ "fedora.24-x64",
+ "fedora.25-x64",
+ "fedora.26-x64",
+ "fedora.27-x64",
+ "fedora.28-x64",
+ "fedora.29-x64",
+ "gentoo-x64",
+ "linux-musl-x64",
+ "linux-x64",
+ "linuxmint.17-x64",
+ "linuxmint.17.1-x64",
+ "linuxmint.17.2-x64",
+ "linuxmint.17.3-x64",
+ "linuxmint.18-x64",
+ "linuxmint.18.1-x64",
+ "linuxmint.18.2-x64",
+ "linuxmint.18.3-x64",
+ "linuxmint.19-x64",
+ "ol-x64",
+ "ol.7-x64",
+ "ol.7.0-x64",
+ "ol.7.1-x64",
+ "ol.7.2-x64",
+ "ol.7.3-x64",
+ "ol.7.4-x64",
+ "ol.7.5-x64",
+ "ol.7.6-x64",
+ "opensuse-x64",
+ "opensuse.13.2-x64",
+ "opensuse.15.0-x64",
+ "opensuse.42.1-x64",
+ "opensuse.42.2-x64",
+ "opensuse.42.3-x64",
+ "osx",
+ "osx-x64",
+ "osx.10.10",
+ "osx.10.10-x64",
+ "osx.10.11",
+ "osx.10.11-x64",
+ "osx.10.12",
+ "osx.10.12-x64",
+ "osx.10.13",
+ "osx.10.13-x64",
+ "osx.10.14",
+ "osx.10.14-x64",
+ "rhel-x64",
+ "rhel.6-x64",
+ "rhel.7-x64",
+ "rhel.7.0-x64",
+ "rhel.7.1-x64",
+ "rhel.7.2-x64",
+ "rhel.7.3-x64",
+ "rhel.7.4-x64",
+ "rhel.7.5-x64",
+ "rhel.7.6-x64",
+ "rhel.8-x64",
+ "rhel.8.0-x64",
+ "sles-x64",
+ "sles.12-x64",
+ "sles.12.1-x64",
+ "sles.12.2-x64",
+ "sles.12.3-x64",
+ "sles.15-x64",
+ "ubuntu-x64",
+ "ubuntu.14.04-x64",
+ "ubuntu.14.10-x64",
+ "ubuntu.15.04-x64",
+ "ubuntu.15.10-x64",
+ "ubuntu.16.04-x64",
+ "ubuntu.16.10-x64",
+ "ubuntu.17.04-x64",
+ "ubuntu.17.10-x64",
+ "ubuntu.18.04-x64",
+ "ubuntu.18.10-x64",
+ "win-x64",
+ "win-x64-aot",
+ "win-x86",
+ "win-x86-aot",
+ "win10-x64",
+ "win10-x64-aot",
+ "win10-x86",
+ "win10-x86-aot",
+ "win7-x64",
+ "win7-x64-aot",
+ "win7-x86",
+ "win7-x86-aot",
+ "win8-x64",
+ "win8-x64-aot",
+ "win8-x86",
+ "win8-x86-aot",
+ "win81-x64",
+ "win81-x64-aot",
+ "win81-x86",
+ "win81-x86-aot",
+ };
+
+ private static readonly string[] s_directories = new[]
+ {
+ "alpine-x64",
+ "alpine-x64",
+ "alpine-x64",
+ "alpine-x64",
+ "alpine-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "linux-x64",
+ "linux-x64",
+ "debian.9-x64",
+ "fedora-x64",
+ "fedora-x64",
+ "fedora-x64",
+ "fedora-x64",
+ "fedora-x64",
+ "fedora-x64",
+ "fedora-x64",
+ "fedora-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "ubuntu.18.04-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "osx",
+ "osx",
+ "osx",
+ "osx",
+ "osx",
+ "osx",
+ "osx",
+ "osx",
+ "osx",
+ "osx",
+ "osx",
+ "osx",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "rhel-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "linux-x64",
+ "ubuntu.18.04-x64",
+ "linux-x64",
+ "win-x64",
+ "win-x64",
+ "win-x86",
+ "win-x86",
+ "win-x64",
+ "win-x64",
+ "win-x86",
+ "win-x86",
+ "win-x64",
+ "win-x64",
+ "win-x86",
+ "win-x86",
+ "win-x64",
+ "win-x64",
+ "win-x86",
+ "win-x86",
+ "win-x64",
+ "win-x64",
+ "win-x86",
+ "win-x86",
+ };
+ }
+}
+#endif
diff --git a/src/GitVersionTask.MsBuild/TaskProxy.cs b/src/GitVersionTask.MsBuild/TaskProxy.cs
new file mode 100644
index 0000000000..6184713652
--- /dev/null
+++ b/src/GitVersionTask.MsBuild/TaskProxy.cs
@@ -0,0 +1,32 @@
+namespace GitVersionTask.MsBuild
+{
+ using System;
+ using System.Reflection;
+ using GitVersionTask.MsBuild.LibGit2Sharp;
+ using GitVersionTask.MsBuild.Tasks;
+
+ public static class TaskProxy
+ {
+ public static Func GetVersion;
+ public static Func GenerateGitVersionInformation;
+ public static Func UpdateAssemblyInfo;
+ public static Func WriteVersionInfoToBuildLog;
+
+ static TaskProxy()
+ {
+#if !NET461
+ GitLoaderContext.Init("GitVersionCore", "LibGit2Sharp");
+#endif
+ LibGit2SharpLoader.LoadAssembly("GitVersionTask");
+
+ var type = LibGit2SharpLoader.Instance.Assembly.GetType("GitVersionTask.GitVersionTasks", throwOnError: true).GetTypeInfo();
+
+ GetVersion = GetMethod(type, nameof(GetVersion));
+ GenerateGitVersionInformation = GetMethod(type, nameof(GenerateGitVersionInformation));
+ UpdateAssemblyInfo = GetMethod(type, nameof(UpdateAssemblyInfo));
+ WriteVersionInfoToBuildLog = GetMethod(type, nameof(WriteVersionInfoToBuildLog));
+ }
+
+ private static Func GetMethod(TypeInfo type, string name) => (Func)type.GetDeclaredMethod(name).CreateDelegate(typeof(Func));
+ }
+}
diff --git a/src/GitVersionTask.MsBuild/Tasks/GenerateGitVersionInformation.cs b/src/GitVersionTask.MsBuild/Tasks/GenerateGitVersionInformation.cs
new file mode 100644
index 0000000000..ee3191f964
--- /dev/null
+++ b/src/GitVersionTask.MsBuild/Tasks/GenerateGitVersionInformation.cs
@@ -0,0 +1,21 @@
+namespace GitVersionTask.MsBuild.Tasks
+{
+ using Microsoft.Build.Framework;
+
+ public class GenerateGitVersionInformation : GitVersionTaskBase
+ {
+ [Required]
+ public string ProjectFile { get; set; }
+
+ [Required]
+ public string IntermediateOutputPath { get; set; }
+
+ [Required]
+ public string Language { get; set; }
+
+ [Output]
+ public string GitVersionInformationFilePath { get; set; }
+
+ public override bool Execute() => TaskProxy.GenerateGitVersionInformation(this);
+ }
+}
diff --git a/src/GitVersionTask.MsBuild/Tasks/GetVersion.cs b/src/GitVersionTask.MsBuild/Tasks/GetVersion.cs
new file mode 100644
index 0000000000..b867a55375
--- /dev/null
+++ b/src/GitVersionTask.MsBuild/Tasks/GetVersion.cs
@@ -0,0 +1,99 @@
+namespace GitVersionTask.MsBuild.Tasks
+{
+ using Microsoft.Build.Framework;
+
+ public class GetVersion : GitVersionTaskBase
+ {
+ [Output]
+ public string Major { get; set; }
+
+ [Output]
+ public string Minor { get; set; }
+
+ [Output]
+ public string Patch { get; set; }
+
+ [Output]
+ public string PreReleaseTag { get; set; }
+
+ [Output]
+ public string PreReleaseTagWithDash { get; set; }
+
+ [Output]
+ public string PreReleaseLabel { get; set; }
+
+ [Output]
+ public string PreReleaseNumber { get; set; }
+
+ [Output]
+ public string WeightedPreReleaseNumber { get; set; }
+
+ [Output]
+ public string BuildMetaData { get; set; }
+
+ [Output]
+ public string BuildMetaDataPadded { get; set; }
+
+ [Output]
+ public string FullBuildMetaData { get; set; }
+
+ [Output]
+ public string MajorMinorPatch { get; set; }
+
+ [Output]
+ public string SemVer { get; set; }
+
+ [Output]
+ public string LegacySemVer { get; set; }
+
+ [Output]
+ public string LegacySemVerPadded { get; set; }
+
+ [Output]
+ public string AssemblySemVer { get; set; }
+
+ [Output]
+ public string AssemblySemFileVer { get; set; }
+
+ [Output]
+ public string FullSemVer { get; set; }
+
+ [Output]
+ public string InformationalVersion { get; set; }
+
+ [Output]
+ public string BranchName { get; set; }
+
+ [Output]
+ public string Sha { get; set; }
+
+ [Output]
+ public string ShortSha { get; set; }
+
+ [Output]
+ public string NuGetVersionV2 { get; set; }
+
+ [Output]
+ public string NuGetVersion { get; set; }
+
+ [Output]
+ public string NuGetPreReleaseTagV2 { get; set; }
+
+ [Output]
+ public string NuGetPreReleaseTag { get; set; }
+
+ [Output]
+ public string CommitDate { get; set; }
+
+ [Output]
+ public string VersionSourceSha { get; set; }
+
+ [Output]
+ public string CommitsSinceVersionSource { get; set; }
+
+ [Output]
+ public string CommitsSinceVersionSourcePadded { get; set; }
+
+ public override bool Execute() => TaskProxy.GetVersion(this);
+ }
+}
diff --git a/src/GitVersionTask.MsBuild/Tasks/UpdateAssemblyInfo.cs b/src/GitVersionTask.MsBuild/Tasks/UpdateAssemblyInfo.cs
new file mode 100644
index 0000000000..6bd388fbed
--- /dev/null
+++ b/src/GitVersionTask.MsBuild/Tasks/UpdateAssemblyInfo.cs
@@ -0,0 +1,24 @@
+namespace GitVersionTask.MsBuild.Tasks
+{
+ using Microsoft.Build.Framework;
+
+ public class UpdateAssemblyInfo : GitVersionTaskBase
+ {
+ [Required]
+ public string ProjectFile { get; set; }
+
+ [Required]
+ public string IntermediateOutputPath { get; set; }
+
+ [Required]
+ public ITaskItem[] CompileFiles { get; set; }
+
+ [Required]
+ public string Language { get; set; }
+
+ [Output]
+ public string AssemblyInfoTempFilePath { get; set; }
+
+ public override bool Execute() => TaskProxy.UpdateAssemblyInfo(this);
+ }
+}
diff --git a/src/GitVersionTask.MsBuild/Tasks/WriteVersionInfoToBuildLog.cs b/src/GitVersionTask.MsBuild/Tasks/WriteVersionInfoToBuildLog.cs
new file mode 100644
index 0000000000..df5bfd75e9
--- /dev/null
+++ b/src/GitVersionTask.MsBuild/Tasks/WriteVersionInfoToBuildLog.cs
@@ -0,0 +1,7 @@
+namespace GitVersionTask.MsBuild.Tasks
+{
+ public class WriteVersionInfoToBuildLog : GitVersionTaskBase
+ {
+ public override bool Execute() => TaskProxy.WriteVersionInfoToBuildLog(this);
+ }
+}
diff --git a/src/GitVersionTask.Tests/GetVersionTaskTests.cs b/src/GitVersionTask.Tests/GetVersionTaskTests.cs
index 22fbaf54e5..8130896dad 100644
--- a/src/GitVersionTask.Tests/GetVersionTaskTests.cs
+++ b/src/GitVersionTask.Tests/GetVersionTaskTests.cs
@@ -1,6 +1,7 @@
using System.Linq;
using GitVersion;
-using GitVersionTask;
+using GitVersionTask.MsBuild.Tasks;
+using Microsoft.Build.Framework;
using NUnit.Framework;
using Shouldly;
@@ -10,8 +11,9 @@ public class GetVersionTaskTests : TestBase
[Test]
public void OutputsShouldMatchVariableProvider()
{
- var taskProperties = typeof(GetVersion.Output)
+ var taskProperties = typeof(GetVersion)
.GetProperties()
+ .Where(p => p.GetCustomAttributes(typeof(OutputAttribute), false).Any())
.Select(p => p.Name);
var variablesProperties = VersionVariables.AvailableVariables;
diff --git a/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs b/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
index 6f02115ee0..b2b13c6eb2 100644
--- a/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
+++ b/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
@@ -1,6 +1,9 @@
using System;
using System.IO;
using GitVersion;
+using GitVersionTask;
+using GitVersionTask.Tests.Mocks;
+using Microsoft.Build.Framework;
using NUnit.Framework;
[TestFixture]
@@ -39,7 +42,7 @@ public void VerifyIgnoreNonAssemblyInfoFile()
");
}
- FileHelper.CheckForInvalidFiles(new[] { "SomeOtherFile.cs" }, projectFile);
+ FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "SomeOtherFile.cs" } }, projectFile);
}
[Test]
@@ -55,7 +58,7 @@ public void VerifyAttributeFoundCSharp([Values("AssemblyVersion", "AssemblyFileV
", attribute);
}
- var ex = Assert.Throws(() => FileHelper.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile), attribute);
+ var ex = Assert.Throws(() => FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile), attribute);
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs"));
}
@@ -73,7 +76,7 @@ public void VerifyUnformattedAttributeFoundCSharp([Values("AssemblyVersion", "As
", attribute);
}
- var ex = Assert.Throws(() => FileHelper.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile), attribute);
+ var ex = Assert.Throws(() => FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile), attribute);
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs"));
}
@@ -90,7 +93,7 @@ public void VerifyCommentWorksCSharp([Values("AssemblyVersion", "AssemblyFileVer
", attribute);
}
- FileHelper.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
+ FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
}
[Test]
@@ -109,7 +112,7 @@ public class Temp
", attribute);
}
- FileHelper.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
+ FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
}
[Test]
@@ -127,7 +130,7 @@ public class {0}
", attribute);
}
- FileHelper.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
+ FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
}
[Test]
@@ -143,7 +146,7 @@ Imports System.Reflection
", attribute);
}
- var ex = Assert.Throws(() => FileHelper.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile), attribute);
+ var ex = Assert.Throws(() => FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile), attribute);
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb"));
}
@@ -161,7 +164,7 @@ Imports System.Reflection
", attribute);
}
- var ex = Assert.Throws(() => FileHelper.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile), attribute);
+ var ex = Assert.Throws(() => FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile), attribute);
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb"));
}
@@ -178,7 +181,7 @@ Imports System.Reflection
", attribute);
}
- FileHelper.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
+ FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
}
[Test]
@@ -196,7 +199,7 @@ End Class
", attribute);
}
- FileHelper.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
+ FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
}
[Test]
@@ -213,6 +216,6 @@ End Class
", attribute);
}
- FileHelper.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
+ FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
}
}
diff --git a/src/GitVersionTask.Tests/Mocks/MockTaskItem.cs b/src/GitVersionTask.Tests/Mocks/MockTaskItem.cs
new file mode 100644
index 0000000000..45a98850b9
--- /dev/null
+++ b/src/GitVersionTask.Tests/Mocks/MockTaskItem.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections;
+using Microsoft.Build.Framework;
+
+namespace GitVersionTask.Tests.Mocks
+{
+ class MockTaskItem : ITaskItem
+ {
+ public string ItemSpec { get; set; }
+
+ public int MetadataCount { get; private set; }
+
+ public ICollection MetadataNames { get; private set; }
+
+ public IDictionary CloneCustomMetadata()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void CopyMetadataTo(ITaskItem destinationItem)
+ {
+ throw new NotImplementedException();
+ }
+
+ public string GetMetadata(string metadataName)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void RemoveMetadata(string metadataName)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SetMetadata(string metadataName, string metadataValue)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/GitVersionTask/FileHelper.cs b/src/GitVersionTask/FileHelper.cs
index 5f4a99fe85..9e117bf228 100644
--- a/src/GitVersionTask/FileHelper.cs
+++ b/src/GitVersionTask/FileHelper.cs
@@ -4,97 +4,114 @@
using System.Linq;
using System.Text.RegularExpressions;
using GitVersion;
+using Microsoft.Build.Framework;
-public static class FileHelper
+namespace GitVersionTask
{
- private static readonly Dictionary> versionAttributeFinders = new Dictionary>()
+ public sealed class FileWriteInfo
{
- { ".cs", CSharpFileContainsVersionAttribute },
- { ".vb", VisualBasicFileContainsVersionAttribute }
- };
-
- public static string TempPath;
+ public FileWriteInfo(string workingDirectory, string fileName, string fileExtension)
+ {
+ WorkingDirectory = workingDirectory;
+ FileName = fileName;
+ FileExtension = fileExtension;
+ }
- static FileHelper()
- {
- TempPath = Path.Combine(Path.GetTempPath(), "GitVersionTask");
- Directory.CreateDirectory(TempPath);
+ public string WorkingDirectory { get; }
+ public string FileName { get; }
+ public string FileExtension { get; }
}
- public static void DeleteTempFiles()
+ public static class FileHelper
{
- if (!Directory.Exists(TempPath))
+ private static readonly Dictionary> versionAttributeFinders = new Dictionary>()
+ {
+ { ".cs", CSharpFileContainsVersionAttribute },
+ { ".vb", VisualBasicFileContainsVersionAttribute }
+ };
+
+ public static string TempPath;
+
+ static FileHelper()
{
- return;
+ TempPath = Path.Combine(Path.GetTempPath(), "GitVersionTask");
+ Directory.CreateDirectory(TempPath);
}
- foreach (var file in Directory.GetFiles(TempPath))
+ public static void DeleteTempFiles()
{
- if (File.GetLastWriteTime(file) < DateTime.Now.AddDays(-1))
+ if (!Directory.Exists(TempPath))
{
- try
- {
- File.Delete(file);
- }
- catch (UnauthorizedAccessException)
+ return;
+ }
+
+ foreach (var file in Directory.GetFiles(TempPath))
+ {
+ if (File.GetLastWriteTime(file) < DateTime.Now.AddDays(-1))
{
- //ignore contention
+ try
+ {
+ File.Delete(file);
+ }
+ catch (UnauthorizedAccessException)
+ {
+ //ignore contention
+ }
}
}
}
- }
- public static string GetFileExtension(string language)
- {
- switch (language)
+ public static string GetFileExtension(string language)
{
- case "C#":
- return "cs";
- case "F#":
- return "fs";
- case "VB":
- return "vb";
- default:
- throw new ArgumentException($"Unknown language detected: '{language}'");
+ switch (language)
+ {
+ case "C#":
+ return "cs";
+ case "F#":
+ return "fs";
+ case "VB":
+ return "vb";
+ default:
+ throw new ArgumentException($"Unknown language detected: '{language}'");
+ }
}
- }
- public static void CheckForInvalidFiles(IEnumerable compileFiles, string projectFile)
- {
- foreach (var compileFile in GetInvalidFiles(compileFiles, projectFile))
+ public static void CheckForInvalidFiles(IEnumerable compileFiles, string projectFile)
{
- throw new WarningException("File contains assembly version attributes which conflict with the attributes generated by GitVersion " + compileFile);
+ foreach (var compileFile in GetInvalidFiles(compileFiles, projectFile))
+ {
+ throw new WarningException("File contains assembly version attributes which conflict with the attributes generated by GitVersion " + compileFile);
+ }
}
- }
- private static bool FileContainsVersionAttribute(string compileFile, string projectFile)
- {
- var compileFileExtension = Path.GetExtension(compileFile);
-
- if (versionAttributeFinders.TryGetValue(compileFileExtension, out var languageSpecificFileContainsVersionAttribute))
+ private static bool FileContainsVersionAttribute(string compileFile, string projectFile)
{
- return languageSpecificFileContainsVersionAttribute(compileFile, projectFile);
- }
+ var compileFileExtension = Path.GetExtension(compileFile);
- throw new WarningException("File with name containing AssemblyInfo could not be checked for assembly version attributes which conflict with the attributes generated by GitVersion " + compileFile);
- }
+ if (versionAttributeFinders.TryGetValue(compileFileExtension, out var languageSpecificFileContainsVersionAttribute))
+ {
+ return languageSpecificFileContainsVersionAttribute(compileFile, projectFile);
+ }
- private static bool CSharpFileContainsVersionAttribute(string compileFile, string projectFile)
- {
- var combine = Path.Combine(Path.GetDirectoryName(projectFile), compileFile);
- var allText = File.ReadAllText(combine);
+ throw new WarningException("File with name containing AssemblyInfo could not be checked for assembly version attributes which conflict with the attributes generated by GitVersion " + compileFile);
+ }
+
+ private static bool CSharpFileContainsVersionAttribute(string compileFile, string projectFile)
+ {
+ var combine = Path.Combine(Path.GetDirectoryName(projectFile), compileFile);
+ var allText = File.ReadAllText(combine);
- var blockComments = @"/\*(.*?)\*/";
- var lineComments = @"//(.*?)\r?\n";
- var strings = @"""((\\[^\n]|[^""\n])*)""";
- var verbatimStrings = @"@(""[^""]*"")+";
+ var blockComments = @"/\*(.*?)\*/";
+ var lineComments = @"//(.*?)\r?\n";
+ var strings = @"""((\\[^\n]|[^""\n])*)""";
+ var verbatimStrings = @"@(""[^""]*"")+";
- var noCommentsOrStrings = Regex.Replace(allText,
- blockComments + "|" + lineComments + "|" + strings + "|" + verbatimStrings,
- me => me.Value.StartsWith("//") ? Environment.NewLine : "",
- RegexOptions.Singleline);
+ var noCommentsOrStrings = Regex.Replace(allText,
+ blockComments + "|" + lineComments + "|" + strings + "|" + verbatimStrings,
+ me => me.Value.StartsWith("//") ? Environment.NewLine : string.Empty,
+ RegexOptions.Singleline);
- return Regex.IsMatch(noCommentsOrStrings, @"(?x) # IgnorePatternWhitespace
+ return Regex.IsMatch(noCommentsOrStrings, @"(?x) # IgnorePatternWhitespace
\[\s*assembly\s*:\s* # The [assembly: part
@@ -103,22 +120,22 @@ private static bool CSharpFileContainsVersionAttribute(string compileFile, strin
Assembly(File|Informational)?Version # The attribute AssemblyVersion, AssemblyFileVersion, or AssemblyInformationalVersion
\s*\(\s*\)\s*\] # End brackets ()]");
- }
+ }
- private static bool VisualBasicFileContainsVersionAttribute(string compileFile, string projectFile)
- {
- var combine = Path.Combine(Path.GetDirectoryName(projectFile), compileFile);
- var allText = File.ReadAllText(combine);
+ private static bool VisualBasicFileContainsVersionAttribute(string compileFile, string projectFile)
+ {
+ var combine = Path.Combine(Path.GetDirectoryName(projectFile), compileFile);
+ var allText = File.ReadAllText(combine);
- var lineComments = @"'(.*?)\r?\n";
- var strings = @"""((\\[^\n]|[^""\n])*)""";
+ var lineComments = @"'(.*?)\r?\n";
+ var strings = @"""((\\[^\n]|[^""\n])*)""";
- var noCommentsOrStrings = Regex.Replace(allText,
- lineComments + "|" + strings,
- me => me.Value.StartsWith("'") ? Environment.NewLine : "",
- RegexOptions.Singleline);
+ var noCommentsOrStrings = Regex.Replace(allText,
+ lineComments + "|" + strings,
+ me => me.Value.StartsWith("'") ? Environment.NewLine : string.Empty,
+ RegexOptions.Singleline);
- return Regex.IsMatch(noCommentsOrStrings, @"(?x) # IgnorePatternWhitespace
+ return Regex.IsMatch(noCommentsOrStrings, @"(?x) # IgnorePatternWhitespace
\<\s*Assembly\s*:\s* # The # End brackets ()>");
- }
+ }
- private static IEnumerable GetInvalidFiles(IEnumerable compileFiles, string projectFile)
- {
- return compileFiles
- .Where(compileFile => compileFile.Contains("AssemblyInfo"))
- .Where(s => FileContainsVersionAttribute(s, projectFile));
+ private static IEnumerable GetInvalidFiles(IEnumerable compileFiles, string projectFile)
+ {
+ return compileFiles.Select(x => x.ItemSpec)
+ .Where(compileFile => compileFile.Contains("AssemblyInfo"))
+ .Where(s => FileContainsVersionAttribute(s, projectFile));
+ }
+
+ public static FileWriteInfo GetFileWriteInfo(this string intermediateOutputPath, string language, string projectFile, string outputFileName)
+ {
+ var fileExtension = FileHelper.GetFileExtension(language);
+ string workingDirectory, fileName;
+
+ if (intermediateOutputPath == null)
+ {
+ fileName = $"{outputFileName}.g.{fileExtension}";
+ workingDirectory = FileHelper.TempPath;
+ }
+ else
+ {
+ fileName = $"{outputFileName}_{Path.GetFileNameWithoutExtension(projectFile)}_{Path.GetRandomFileName()}.g.{fileExtension}";
+ workingDirectory = intermediateOutputPath;
+ }
+ return new FileWriteInfo(workingDirectory, fileName, fileExtension);
+ }
}
}
diff --git a/src/GitVersionTask/GenerateGitVersionInformation.cs b/src/GitVersionTask/GenerateGitVersionInformation.cs
deleted file mode 100644
index 04c7507059..0000000000
--- a/src/GitVersionTask/GenerateGitVersionInformation.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-namespace GitVersionTask
-{
- using System.IO;
- using GitVersion;
- using GitVersion.Helpers;
-
- public static class GenerateGitVersionInformation
- {
- // This method is entrypoint for the task declared in .props file
- public static Output Execute(Input input) => GitVersionTaskUtils.ExecuteGitVersionTask(input, InnerExecute);
-
- private static Output InnerExecute(Input input, TaskLogger logger)
- {
- if (!GitVersionTaskUtils.GetVersionVariables(input, out var versionVariables))
- {
- return null;
- }
-
- return CreateGitVersionInfo(input, versionVariables);
- }
-
- private static Output CreateGitVersionInfo(Input input, VersionVariables versionVariables)
- {
- var fileWriteInfo = input.IntermediateOutputPath.GetFileWriteInfo(
- input.Language,
- input.ProjectFile,
- (pf, ext) => $"GitVersionInformation.g.{ext}",
- (pf, ext) => $"GitVersionInformation_{Path.GetFileNameWithoutExtension(pf)}_{Path.GetRandomFileName()}.g.{ext}"
- );
-
- var output = new Output
- {
- GitVersionInformationFilePath = Path.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName)
- };
- var generator = new GitVersionInformationGenerator(fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem());
- generator.Generate();
-
- return output;
- }
-
- public sealed class Input : InputWithCommonAdditionalProperties
- {
- }
-
- public sealed class Output
- {
- public string GitVersionInformationFilePath { get; set; }
- }
- }
-}
diff --git a/src/GitVersionTask/GetVersion.cs b/src/GitVersionTask/GetVersion.cs
deleted file mode 100644
index 3944d507cd..0000000000
--- a/src/GitVersionTask/GetVersion.cs
+++ /dev/null
@@ -1,91 +0,0 @@
-namespace GitVersionTask
-{
- public static class GetVersion
- {
- public static Output Execute(Input input) => GitVersionTaskUtils.ExecuteGitVersionTask(input, InnerExecute);
-
- private static Output InnerExecute(Input input, TaskLogger logger)
- {
- if (!GitVersionTaskUtils.GetVersionVariables(input, out var versionVariables))
- {
- return null;
- }
-
- var outputType = typeof(Output);
- var output = new Output();
- foreach (var variable in versionVariables)
- {
- outputType.GetProperty(variable.Key)?.SetValue(output, variable.Value, null);
- }
-
- return output;
- }
-
- public sealed class Input : InputBase
- {
- }
-
- public sealed class Output
- {
- public string Major { get; set; }
-
- public string Minor { get; set; }
-
- public string Patch { get; set; }
-
- public string PreReleaseTag { get; set; }
-
- public string PreReleaseTagWithDash { get; set; }
-
- public string PreReleaseLabel { get; set; }
-
- public string PreReleaseNumber { get; set; }
-
- public string WeightedPreReleaseNumber { get; set; }
-
- public string BuildMetaData { get; set; }
-
- public string BuildMetaDataPadded { get; set; }
-
- public string FullBuildMetaData { get; set; }
-
- public string MajorMinorPatch { get; set; }
-
- public string SemVer { get; set; }
-
- public string LegacySemVer { get; set; }
-
- public string LegacySemVerPadded { get; set; }
-
- public string AssemblySemVer { get; set; }
-
- public string AssemblySemFileVer { get; set; }
-
- public string FullSemVer { get; set; }
-
- public string InformationalVersion { get; set; }
-
- public string BranchName { get; set; }
-
- public string Sha { get; set; }
-
- public string ShortSha { get; set; }
-
- public string NuGetVersionV2 { get; set; }
-
- public string NuGetVersion { get; set; }
-
- public string NuGetPreReleaseTagV2 { get; set; }
-
- public string NuGetPreReleaseTag { get; set; }
-
- public string CommitDate { get; set; }
-
- public string VersionSourceSha { get; set; }
-
- public string CommitsSinceVersionSource { get; set; }
-
- public string CommitsSinceVersionSourcePadded { get; set; }
- }
- }
-}
diff --git a/src/GitVersionTask/GitVersionTask.csproj b/src/GitVersionTask/GitVersionTask.csproj
index dd0310d602..14a407eaf0 100644
--- a/src/GitVersionTask/GitVersionTask.csproj
+++ b/src/GitVersionTask/GitVersionTask.csproj
@@ -1,53 +1,23 @@
-
-
+
-
+
+ net461;netcoreapp2.1
-
- net461;netstandard2.0
- false
+ true
- GitVersionTask
- GitVersionTask
+ GitVersionTask.nuspec
+ bin\$(Configuration)
+ 0.0.1-alpha-0001
+ version=$(PackageVersion)
- Stamps an assembly with git information based on SemVer.
+ true
+
+
+
+
- true
- build
-
- NugetAssets\GitVersionTask.nuspec
- 0.0.1-alpha-0001
- version=$(PackageVersion);configuration=$(Configuration);nugetutilsversion=$(PackageVersion_NuGetUtilsMSBuildExec);libgit2sharpversion=$(PackageVersion_LibGit2Sharp);yamldotnetversion=$(PackageVersion_YamlDotNet)
-
- $(AssemblyName)
-
-
-
-
-
-
-
- build\
-
-
-
-
-
- All
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers
-
-
-
-
-
-
-
-
-
-
+
+
+
+
diff --git a/src/GitVersionTask/GitVersionTask.nuspec b/src/GitVersionTask/GitVersionTask.nuspec
new file mode 100644
index 0000000000..cc2f12e938
--- /dev/null
+++ b/src/GitVersionTask/GitVersionTask.nuspec
@@ -0,0 +1,45 @@
+
+
+
+ GitVersionTask
+ 1.0.0
+ GitVersionTask
+ GitTools and Contributors
+ GitTools and Contributors
+ false
+ true
+ MIT
+ https://github.com/GitTools/GitVersion
+ https://raw.githubusercontent.com/GitTools/GitVersion/master/docs/img/package_icon.png
+ Stamps an assembly with git information based on SemVer.
+ https://github.com/GitTools/GitVersion/releases
+ Copyright GitTools 2019.
+ Git Versioning GitVersion GitFlowVersion GitFlow GitHubFlow SemVer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/GitVersionTask/GitVersionTaskUtils.cs b/src/GitVersionTask/GitVersionTaskUtils.cs
deleted file mode 100644
index f1ba5c7af0..0000000000
--- a/src/GitVersionTask/GitVersionTaskUtils.cs
+++ /dev/null
@@ -1,127 +0,0 @@
-namespace GitVersionTask
-{
- using GitVersion;
- using GitVersion.Helpers;
- using System;
-
- public static class GitVersionTaskUtils
- {
- internal static TOutput ExecuteGitVersionTask(TInput input, Func execute)
- where TInput : InputBase
- where TOutput : class, new()
- {
- input.ValidateInputOrThrowException();
-
- var logger = new TaskLogger();
- Logger.SetLoggers(logger.LogInfo, logger.LogInfo, logger.LogWarning, s => logger.LogError(s));
-
- TOutput output;
- try
- {
- output = execute(input, logger);
- }
- catch (WarningException errorException)
- {
- logger.LogWarning(errorException.Message);
- output = new TOutput();
- }
- catch (Exception exception)
- {
- logger.LogError("Error occurred: " + exception);
- throw;
- }
- finally
- {
- Logger.Reset();
- }
-
- return output;
- }
-
- public static bool GetVersionVariables(InputBase input, out VersionVariables versionVariables)
- => new ExecuteCore(new FileSystem()).TryGetVersion(input.SolutionDirectory, out versionVariables, input.NoFetch, new Authentication());
-
- public static FileWriteInfo GetFileWriteInfo(
- this string intermediateOutputPath,
- string language,
- string projectFile,
- Func fileNameWithIntermediatePath,
- Func fileNameNoIntermediatePath
- )
- {
- var fileExtension = FileHelper.GetFileExtension(language);
- string workingDirectory, fileName;
- if (intermediateOutputPath == null)
- {
- fileName = fileNameWithIntermediatePath(projectFile, fileExtension);
- workingDirectory = FileHelper.TempPath;
- }
- else
- {
- workingDirectory = intermediateOutputPath;
- fileName = fileNameNoIntermediatePath(projectFile, fileExtension);
- }
- return new FileWriteInfo(workingDirectory, fileName, fileExtension);
- }
- }
-
- public abstract class InputBase
- {
- public string SolutionDirectory { get; set; }
-
- public bool NoFetch { get; set; }
-
- public void ValidateInputOrThrowException()
- {
- if (!ValidateInput())
- {
- throw new InputValidationException($"Invalid input for {GetType()}.");
- }
- }
-
- protected virtual bool ValidateInput()
- {
- return !string.IsNullOrEmpty(SolutionDirectory);
- }
- }
-
- public abstract class InputWithCommonAdditionalProperties : InputBase
- {
- public string ProjectFile { get; set; }
-
- public string IntermediateOutputPath { get; set; }
-
- public string Language { get; set; }
-
- protected override bool ValidateInput()
- {
- return base.ValidateInput()
- && !string.IsNullOrEmpty(ProjectFile)
- && !string.IsNullOrEmpty(IntermediateOutputPath)
- && !string.IsNullOrEmpty(Language);
- }
- }
-
- public sealed class InputValidationException : Exception
- {
- public InputValidationException(string msg, Exception inner = null)
- : base(msg, inner)
- {
-
- }
- }
-
- public sealed class FileWriteInfo
- {
- public FileWriteInfo(string workingDirectory, string fileName, string fileExtension)
- {
- WorkingDirectory = workingDirectory;
- FileName = fileName;
- FileExtension = fileExtension;
- }
-
- public string WorkingDirectory { get; }
- public string FileName { get; }
- public string FileExtension { get; }
- }
-}
diff --git a/src/GitVersionTask/GitVersionTasks.cs b/src/GitVersionTask/GitVersionTasks.cs
new file mode 100644
index 0000000000..e8b9c9ada2
--- /dev/null
+++ b/src/GitVersionTask/GitVersionTasks.cs
@@ -0,0 +1,113 @@
+namespace GitVersionTask
+{
+ using System;
+ using System.IO;
+ using GitVersion;
+ using GitVersion.Helpers;
+ using GitVersionTask.MsBuild;
+ using GitVersionTask.MsBuild.Tasks;
+ using Microsoft.Build.Framework;
+
+ public static class GitVersionTasks
+ {
+ public static bool GetVersion(GetVersion task)
+ {
+ return ExecuteGitVersionTask(task, t =>
+ {
+ if (!GetVersionVariables(t, out var versionVariables)) return;
+
+ var outputType = typeof(GetVersion);
+ foreach (var variable in versionVariables)
+ {
+ outputType.GetProperty(variable.Key)?.SetValue(task, variable.Value, null);
+ }
+ });
+ }
+
+ public static bool UpdateAssemblyInfo(UpdateAssemblyInfo task)
+ {
+ return ExecuteGitVersionTask(task, t =>
+ {
+ FileHelper.DeleteTempFiles();
+ FileHelper.CheckForInvalidFiles(t.CompileFiles, t.ProjectFile);
+
+ if (!GetVersionVariables(t, out var versionVariables)) return;
+
+ var fileWriteInfo = t.IntermediateOutputPath.GetFileWriteInfo(t.Language, t.ProjectFile, "AssemblyInfo");
+
+ t.AssemblyInfoTempFilePath = Path.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName);
+
+ using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem(), true))
+ {
+ assemblyInfoFileUpdater.Update();
+ assemblyInfoFileUpdater.CommitChanges();
+ }
+ });
+ }
+
+ public static bool GenerateGitVersionInformation(GenerateGitVersionInformation task)
+ {
+ return ExecuteGitVersionTask(task, t =>
+ {
+ if (!GetVersionVariables(t, out var versionVariables)) return;
+
+ var fileWriteInfo = t.IntermediateOutputPath.GetFileWriteInfo(t.Language, t.ProjectFile, "GitVersionInformation");
+
+ t.GitVersionInformationFilePath = Path.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName);
+ var generator = new GitVersionInformationGenerator(fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem());
+ generator.Generate();
+ });
+ }
+
+ public static bool WriteVersionInfoToBuildLog(WriteVersionInfoToBuildLog task)
+ {
+ return ExecuteGitVersionTask(task, t =>
+ {
+ if (!GetVersionVariables(task, out var versionVariables)) return;
+
+ var logger = t.Log;
+ foreach (var buildServer in BuildServerList.GetApplicableBuildServers())
+ {
+ logger.LogMessage($"Executing GenerateSetVersionMessage for '{ buildServer.GetType().Name }'.");
+ logger.LogMessage(buildServer.GenerateSetVersionMessage(versionVariables));
+ logger.LogMessage($"Executing GenerateBuildLogOutput for '{ buildServer.GetType().Name }'.");
+ foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(buildServer, versionVariables))
+ {
+ logger.LogMessage(buildParameter);
+ }
+ }
+ });
+ }
+
+ private static bool ExecuteGitVersionTask(T task, Action action)
+ where T : GitVersionTaskBase
+ {
+ void LogDebug(string message) => task.Log.LogMessage(MessageImportance.Low, message);
+ void LogInfo(string message) => task.Log.LogMessage(MessageImportance.Normal, message);
+ void LogWarning(string message) => task.Log.LogWarning(message);
+ void LogError(string message) => task.Log.LogError(message);
+
+ Logger.SetLoggers(LogDebug, LogInfo, LogWarning, LogError);
+ var log = task.Log;
+ try
+ {
+ action(task);
+ }
+ catch (WarningException errorException)
+ {
+ log.LogWarningFromException(errorException);
+ return true;
+ }
+ catch (Exception exception)
+ {
+ log.LogErrorFromException(exception);
+ return false;
+ }
+
+ return !log.HasLoggedErrors;
+ }
+
+ private static bool GetVersionVariables(GitVersionTaskBase task, out VersionVariables versionVariables)
+ => new ExecuteCore(new FileSystem()).TryGetVersion(task.SolutionDirectory, out versionVariables, task.NoFetch, new Authentication());
+ }
+}
diff --git a/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props b/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props
deleted file mode 100644
index a00890c752..0000000000
--- a/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
- 2.0.5
-
-
-
diff --git a/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec b/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec
deleted file mode 100644
index 2c6d00d55a..0000000000
--- a/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
- GitVersionTask
- 1.0.0
- GitVersionTask
- GitTools and Contributors
- GitTools and Contributors
- false
- true
- MIT
- https://github.com/GitTools/GitVersion
- https://raw.githubusercontent.com/GitTools/GitVersion/master/docs/img/package_icon.png
- Stamps an assembly with git information based on SemVer.
- https://github.com/GitTools/GitVersion/releases
- Copyright GitTools 2019.
- Git Versioning GitVersion GitFlowVersion GitFlow GitHubFlow SemVer
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/GitVersionTask/NugetAssets/build/GitVersionTask.targets b/src/GitVersionTask/NugetAssets/build/GitVersionTask.targets
deleted file mode 100644
index fc1e76270d..0000000000
--- a/src/GitVersionTask/NugetAssets/build/GitVersionTask.targets
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
- false
- true
-
-
-
-
-
-
-
-
diff --git a/src/GitVersionTask/NugetAssets/build/Infrastructure.props b/src/GitVersionTask/NugetAssets/build/Infrastructure.props
deleted file mode 100644
index dbdb4e8f01..0000000000
--- a/src/GitVersionTask/NugetAssets/build/Infrastructure.props
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
- $(MSBuildThisFileDirectory)functionality/
- $(GitVersionTaskBuildTools_FunctionalityDir)GitVersionBuild.targets
- $(GitVersionTaskBuildTools_FunctionalityDir)GitVersionMultiTargetBuild.targets
- $(GitVersionTaskBuildTools_FunctionalityDir)obj/
-
-
-
- $(PackageVersion_NuGetUtilsMSBuildExec)
- $(MSBuildThisFileDirectory)../../../nugetutils.msbuild.exec/$(NuGetUtilsVersion)/build/NuGetUtils.MSBuild.Exec.props
- $([System.IO.Path]::GetFullPath('$(NuGetUtilsMSBuildPropsPath)'))
-
-
-
-
-
- true
-
-
-
-
- net461
-
-
- $(NuGetUtilsTaskFactoryParametersXML)
- true
- GitVersionTask.dll
-
-
-
-
-
-
-
-
-
-
diff --git a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionBuild.targets b/src/GitVersionTask/NugetAssets/build/functionality/GitVersionBuild.targets
deleted file mode 100644
index 4bbaa9f970..0000000000
--- a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionBuild.targets
+++ /dev/null
@@ -1,121 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $(GitVersion_FullSemVer)
- $(GitVersion_MajorMinorPatch)
- $(GitVersion_NuGetPreReleaseTag)
- $(GitVersion_PreReleaseTag)
- $(GitVersion_NuGetVersion)
- $(GitVersion_FullSemVer)
- $(GitVersion_InformationalVersion)
- $(GitVersion_AssemblySemVer)
- $(GitVersion_AssemblySemFileVer)
-
-
-
- GitVersion_Major=$(GitVersion_Major);$(DefineConstants)
- GitVersion_Minor=$(GitVersion_Minor);$(DefineConstants)
- GitVersion_Patch=$(GitVersion_Patch);$(DefineConstants)
- GitVersion_PreReleaseTag=$(GitVersion_PreReleaseTag);$(DefineConstants)
- GitVersion_PreReleaseTagWithDash=$(GitVersion_PreReleaseTagWithDash);$(DefineConstants)
- GitVersion_PreReleaseLabel=$(GitVersion_PreReleaseLabel);$(DefineConstants)
- GitVersion_PreReleaseNumber=$(GitVersion_PreReleaseNumber);$(DefineConstants)
- GitVersion_BuildMetaData=$(GitVersion_BuildMetaData);$(DefineConstants)
- GitVersion_BuildMetaDataPadded=$(GitVersion_BuildMetaDataPadded);$(DefineConstants)
- GitVersion_FullBuildMetaData=$(GitVersion_FullBuildMetaData);$(DefineConstants)
- GitVersion_MajorMinorPatch=$(GitVersion_MajorMinorPatch);$(DefineConstants)
- GitVersion_SemVer=$(GitVersion_SemVer);$(DefineConstants)
- GitVersion_LegacySemVer=$(GitVersion_LegacySemVer);$(DefineConstants)
- GitVersion_LegacySemVerPadded=$(GitVersion_LegacySemVerPadded);$(DefineConstants)
- GitVersion_AssemblySemVer=$(GitVersion_AssemblySemVer);$(DefineConstants)
- GitVersion_AssemblySemFileVer=$(GitVersion_AssemblySemFileVer);$(DefineConstants)
- GitVersion_FullSemVer=$(GitVersion_FullSemVer);$(DefineConstants)
- GitVersion_InformationalVersion=$(GitVersion_InformationalVersion);$(DefineConstants)
- GitVersion_BranchName=$(GitVersion_BranchName);$(DefineConstants)
- GitVersion_Sha=$(GitVersion_Sha);$(DefineConstants)
- GitVersion_NuGetVersionV2=$(GitVersion_NuGetVersionV2);$(DefineConstants)
- GitVersion_NuGetVersion=$(GitVersion_NuGetVersion);$(DefineConstants)
- GitVersion_NuGetPreReleaseTagV2=$(GitVersion_NuGetPreReleaseTagV2);$(DefineConstants)
- GitVersion_NuGetPreReleaseTag=$(GitVersion_NuGetPreReleaseTag);$(DefineConstants)
- GitVersion_CommitDate=$(GitVersion_CommitDate);$(DefineConstants)
- GitVersion_CommitsSinceVersionSource=$(GitVersion_CommitsSinceVersionSource);$(DefineConstants)
- GitVersion_CommitsSinceVersionSourcePadded=$(GitVersion_CommitsSinceVersionSourcePadded);$(DefineConstants)
-
-
-
-
-
diff --git a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props b/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
deleted file mode 100644
index 64bab514d0..0000000000
--- a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
+++ /dev/null
@@ -1,93 +0,0 @@
-
-
-
- $(MSBuildProjectDirectory)\..\
- $(SolutionDir)
- $(MSBuildProjectDirectory)
- $(SolutionDir)\GitVersionTask.targets
- $(SolutionDir)\GitVersionTask.targets
-
- false
- $(MSBuildProjectDirectory)\obj\$(Configuration)\
-
-
- true
-
-
- false
- true
-
-
- true
-
-
- true
-
- true
-
-
- $(MarkupCompilePass1DependsOn);GetVersion
-
- $(GetPackageVersionDependsOn);GetVersion
-
-
- true
- false
-
-
-
-
-
- $(NuGetUtilsTaskFactoryParametersXML)
- Execute
-
-
-
-
-
-
- $(NuGetUtilsTaskFactoryParametersXML)
- Execute
-
-
-
-
-
-
- $(NuGetUtilsTaskFactoryParametersXML)
- Execute
-
-
-
-
-
-
- $(NuGetUtilsTaskFactoryParametersXML)
- Execute
-
-
-
-
- True
-
-
-
diff --git a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionMultiTargetBuild.targets b/src/GitVersionTask/NugetAssets/build/functionality/GitVersionMultiTargetBuild.targets
deleted file mode 100644
index 6441c4d259..0000000000
--- a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionMultiTargetBuild.targets
+++ /dev/null
@@ -1,53 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $(GitVersion_FullSemVer)
- $(GitVersion_MajorMinorPatch)
- $(GitVersion_NuGetPreReleaseTag)
- $(GitVersion_PreReleaseTag)
- $(GitVersion_NuGetVersion)
- $(GitVersion_FullSemVer)
- $(GitVersion_InformationalVersion)
- $(GitVersion_AssemblySemVer)
- $(GitVersion_AssemblySemFileVer)
-
-
-
-
diff --git a/src/GitVersionTask/TaskLogger.cs b/src/GitVersionTask/TaskLogger.cs
deleted file mode 100644
index 10f7e1558a..0000000000
--- a/src/GitVersionTask/TaskLogger.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System;
-using System.IO;
-
-class TaskLogger
-{
- private readonly TextWriter stdout;
- private readonly TextWriter stderr;
-
- public TaskLogger(TextWriter paramStdout = null, TextWriter paramStderr = null)
- {
- stdout = paramStdout ?? Console.Out;
- stderr = paramStderr ?? Console.Error;
- }
-
- public void LogWarning(string message)
- {
- stdout.WriteLine(message);
- }
-
- public void LogInfo(string message)
- {
- stdout.WriteLine(message);
- }
-
- public void LogError(string message)
- {
- stderr.WriteLine(message);
- }
-}
diff --git a/src/GitVersionTask/UpdateAssemblyInfo.cs b/src/GitVersionTask/UpdateAssemblyInfo.cs
deleted file mode 100644
index faa577acde..0000000000
--- a/src/GitVersionTask/UpdateAssemblyInfo.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-namespace GitVersionTask
-{
- using System.IO;
-
- using GitVersion;
- using GitVersion.Helpers;
-
- public static class UpdateAssemblyInfo
- {
- public static Output Execute(Input input) => GitVersionTaskUtils.ExecuteGitVersionTask(input, InnerExecute);
-
- private static Output InnerExecute(Input input, TaskLogger logger)
- {
- FileHelper.DeleteTempFiles();
-
- FileHelper.CheckForInvalidFiles(input.CompileFiles, input.ProjectFile);
-
- if (!GitVersionTaskUtils.GetVersionVariables(input, out var versionVariables))
- {
- return null;
- }
-
- return CreateTempAssemblyInfo(input, versionVariables);
- }
-
- private static Output CreateTempAssemblyInfo(Input input, VersionVariables versionVariables)
- {
- var fileWriteInfo = input.IntermediateOutputPath.GetFileWriteInfo(
- input.Language,
- input.ProjectFile,
- (pf, ext) => $"AssemblyInfo.g.{ext}",
- (pf, ext) => $"AssemblyInfo_{Path.GetFileNameWithoutExtension(pf)}_{Path.GetRandomFileName()}.g.{ext}"
- );
-
- var output = new Output
- {
- AssemblyInfoTempFilePath = Path.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName)
- };
-
- using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem(), true))
- {
- assemblyInfoFileUpdater.Update();
- assemblyInfoFileUpdater.CommitChanges();
- }
-
- return output;
- }
-
- public sealed class Input : InputWithCommonAdditionalProperties
- {
- public string[] CompileFiles { get; set; }
-
- protected override bool ValidateInput()
- {
- return base.ValidateInput()
- && CompileFiles != null;
- }
- }
-
- public sealed class Output
- {
- public string AssemblyInfoTempFilePath { get; set; }
- }
- }
-}
diff --git a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs b/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
deleted file mode 100644
index 7b7e6aed08..0000000000
--- a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-namespace GitVersionTask
-{
- using System.Collections.Generic;
- using GitVersion;
-
- public class WriteVersionInfoToBuildLog
- {
- public static Output Execute(Input input) => GitVersionTaskUtils.ExecuteGitVersionTask(input, InnerExecute);
-
- public sealed class Input : InputBase
- {
- // No additional inputs for this task
- }
-
- public sealed class Output
- {
- // No output for this task
- }
-
- private static Output InnerExecute(Input input, TaskLogger logger)
- {
- if (!GitVersionTaskUtils.GetVersionVariables(input, out var versionVariables))
- {
- return null;
- }
-
- WriteIntegrationParameters(logger, BuildServerList.GetApplicableBuildServers(), versionVariables);
-
- return new Output();
- }
-
- private static void WriteIntegrationParameters(TaskLogger logger, IEnumerable applicableBuildServers, VersionVariables versionVariables)
- {
- foreach (var buildServer in applicableBuildServers)
- {
- logger.LogInfo($"Executing GenerateSetVersionMessage for '{ buildServer.GetType().Name }'.");
- logger.LogInfo(buildServer.GenerateSetVersionMessage(versionVariables));
- logger.LogInfo($"Executing GenerateBuildLogOutput for '{ buildServer.GetType().Name }'.");
- foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(buildServer, versionVariables))
- {
- logger.LogInfo(buildParameter);
- }
- }
- }
- }
-}
diff --git a/src/GitVersionTask/build/GitVersionTask.props b/src/GitVersionTask/build/GitVersionTask.props
new file mode 100644
index 0000000000..29b23c27b6
--- /dev/null
+++ b/src/GitVersionTask/build/GitVersionTask.props
@@ -0,0 +1,37 @@
+
+
+
+ $(MSBuildThisFileDirectory)..\tools\net461\GitVersionTask.MsBuild.dll
+ $(MSBuildThisFileDirectory)..\tools\netstandard2.0\GitVersionTask.MsBuild.dll
+
+ $(MSBuildProjectDirectory)\..\
+ $(SolutionDir)
+ $(MSBuildProjectDirectory)
+
+ false
+
+
+ true
+
+
+ true
+
+
+ true
+
+
+ true
+
+ true
+
+ $(MarkupCompilePass1DependsOn);GetVersion
+ $(GetPackageVersionDependsOn);GetVersion
+
+
+ true
+ false
+
+
diff --git a/src/GitVersionTask/build/GitVersionTask.targets b/src/GitVersionTask/build/GitVersionTask.targets
new file mode 100644
index 0000000000..a0cbe5896a
--- /dev/null
+++ b/src/GitVersionTask/build/GitVersionTask.targets
@@ -0,0 +1,128 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $(GitVersion_FullSemVer)
+ $(GitVersion_MajorMinorPatch)
+ $(GitVersion_NuGetPreReleaseTag)
+ $(GitVersion_PreReleaseTag)
+ $(GitVersion_NuGetVersion)
+ $(GitVersion_FullSemVer)
+ $(GitVersion_InformationalVersion)
+ $(GitVersion_AssemblySemVer)
+ $(GitVersion_AssemblySemFileVer)
+
+
+
+ GitVersion_Major=$(GitVersion_Major);$(DefineConstants)
+ GitVersion_Minor=$(GitVersion_Minor);$(DefineConstants)
+ GitVersion_Patch=$(GitVersion_Patch);$(DefineConstants)
+ GitVersion_PreReleaseTag=$(GitVersion_PreReleaseTag);$(DefineConstants)
+ GitVersion_PreReleaseTagWithDash=$(GitVersion_PreReleaseTagWithDash);$(DefineConstants)
+ GitVersion_PreReleaseLabel=$(GitVersion_PreReleaseLabel);$(DefineConstants)
+ GitVersion_PreReleaseNumber=$(GitVersion_PreReleaseNumber);$(DefineConstants)
+ GitVersion_BuildMetaData=$(GitVersion_BuildMetaData);$(DefineConstants)
+ GitVersion_BuildMetaDataPadded=$(GitVersion_BuildMetaDataPadded);$(DefineConstants)
+ GitVersion_FullBuildMetaData=$(GitVersion_FullBuildMetaData);$(DefineConstants)
+ GitVersion_MajorMinorPatch=$(GitVersion_MajorMinorPatch);$(DefineConstants)
+ GitVersion_SemVer=$(GitVersion_SemVer);$(DefineConstants)
+ GitVersion_LegacySemVer=$(GitVersion_LegacySemVer);$(DefineConstants)
+ GitVersion_LegacySemVerPadded=$(GitVersion_LegacySemVerPadded);$(DefineConstants)
+ GitVersion_AssemblySemVer=$(GitVersion_AssemblySemVer);$(DefineConstants)
+ GitVersion_AssemblySemFileVer=$(GitVersion_AssemblySemFileVer);$(DefineConstants)
+ GitVersion_FullSemVer=$(GitVersion_FullSemVer);$(DefineConstants)
+ GitVersion_InformationalVersion=$(GitVersion_InformationalVersion);$(DefineConstants)
+ GitVersion_BranchName=$(GitVersion_BranchName);$(DefineConstants)
+ GitVersion_Sha=$(GitVersion_Sha);$(DefineConstants)
+ GitVersion_NuGetVersionV2=$(GitVersion_NuGetVersionV2);$(DefineConstants)
+ GitVersion_NuGetVersion=$(GitVersion_NuGetVersion);$(DefineConstants)
+ GitVersion_NuGetPreReleaseTagV2=$(GitVersion_NuGetPreReleaseTagV2);$(DefineConstants)
+ GitVersion_NuGetPreReleaseTag=$(GitVersion_NuGetPreReleaseTag);$(DefineConstants)
+ GitVersion_CommitDate=$(GitVersion_CommitDate);$(DefineConstants)
+ GitVersion_CommitsSinceVersionSource=$(GitVersion_CommitsSinceVersionSource);$(DefineConstants)
+ GitVersion_CommitsSinceVersionSourcePadded=$(GitVersion_CommitsSinceVersionSourcePadded);$(DefineConstants)
+
+
+
+
+
diff --git a/src/GitVersionTask/buildMultiTargeting/GitVersionTask.props b/src/GitVersionTask/buildMultiTargeting/GitVersionTask.props
new file mode 100644
index 0000000000..38b3a09ab9
--- /dev/null
+++ b/src/GitVersionTask/buildMultiTargeting/GitVersionTask.props
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/src/GitVersionTask/buildMultiTargeting/GitVersionTask.targets b/src/GitVersionTask/buildMultiTargeting/GitVersionTask.targets
new file mode 100644
index 0000000000..a31cac6368
--- /dev/null
+++ b/src/GitVersionTask/buildMultiTargeting/GitVersionTask.targets
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ UpdateAssemblyInfo
+
+
+
+
+
+
+ GenerateGitVersionInformation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $(GitVersion_FullSemVer)
+ $(GitVersion_MajorMinorPatch)
+ $(GitVersion_NuGetPreReleaseTag)
+ $(GitVersion_PreReleaseTag)
+ $(GitVersion_NuGetVersion)
+ $(GitVersion_FullSemVer)
+ $(GitVersion_InformationalVersion)
+ $(GitVersion_AssemblySemVer)
+ $(GitVersion_AssemblySemFileVer)
+
+
+
+