From 6ae9c553f83d20ffa1fab4ba648d7146d2419e46 Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Fri, 8 Mar 2019 23:46:14 +0200
Subject: [PATCH 01/15] First modifications for changing from
UtilPack.NuGet.MSBuild to NuGetUtils.MSBuild.Exec.
---
.../GitVersionTask.Tests.csproj | 1 -
src/GitVersionTask/BuildLogger.cs | 25 ---
.../GenerateGitVersionInformation.cs | 112 ++++++-----
src/GitVersionTask/GetVersion.cs | 183 ++++++++----------
src/GitVersionTask/GitVersionTask.csproj | 5 +-
src/GitVersionTask/GitVersionTaskBase.cs | 71 +++++--
src/GitVersionTask/InvalidFileChecker.cs | 7 +-
.../NugetAssets/build/Infrastructure.props | 10 +-
.../functionality/GitVersionCommon.props | 40 ++--
src/GitVersionTask/TaskLogger.cs | 24 ++-
src/GitVersionTask/UpdateAssemblyInfo.cs | 125 ++++++------
src/GitVersionTask/UtilPack.Version.props | 2 +-
.../WriteVersionInfoToBuildLog.cs | 66 ++++---
13 files changed, 357 insertions(+), 314 deletions(-)
delete mode 100644 src/GitVersionTask/BuildLogger.cs
diff --git a/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj b/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj
index d8d542866b..ef3d567686 100644
--- a/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj
+++ b/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj
@@ -17,7 +17,6 @@
-
diff --git a/src/GitVersionTask/BuildLogger.cs b/src/GitVersionTask/BuildLogger.cs
deleted file mode 100644
index 9c9ec461cf..0000000000
--- a/src/GitVersionTask/BuildLogger.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Microsoft.Build.Framework;
-using Microsoft.Build.Utilities;
-
-public static class BuildLogger
-{
- public static void LogDebug(this Task task, string message)
- {
- task.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Low));
- }
-
- public static void LogInfo(this Task task, string message)
- {
- task.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Normal));
- }
-
- public static void LogWarning(this Task task, string message)
- {
- task.BuildEngine.LogWarningEvent(new BuildWarningEventArgs(string.Empty, string.Empty, null, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
- }
-
- public static void LogError(this Task task, string message, string file = null)
- {
- task.BuildEngine.LogErrorEvent(new BuildErrorEventArgs(string.Empty, string.Empty, file, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
- }
-}
\ No newline at end of file
diff --git a/src/GitVersionTask/GenerateGitVersionInformation.cs b/src/GitVersionTask/GenerateGitVersionInformation.cs
index d91a7898dc..c002731c5a 100644
--- a/src/GitVersionTask/GenerateGitVersionInformation.cs
+++ b/src/GitVersionTask/GenerateGitVersionInformation.cs
@@ -4,98 +4,96 @@ namespace GitVersionTask
using System.IO;
using GitVersion;
using GitVersion.Helpers;
- using Microsoft.Build.Framework;
- public class GenerateGitVersionInformation : GitVersionTaskBase
+ public static class GenerateGitVersionInformation
{
- TaskLogger logger;
-
- public GenerateGitVersionInformation()
+ public static Output Execute(
+ Input input
+ )
{
- logger = new TaskLogger(this);
- Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
- }
-
- [Required]
- public string SolutionDirectory { get; set; }
-
- [Required]
- public string ProjectFile { get; set; }
-
- [Required]
- public string IntermediateOutputPath { get; set; }
-
- [Required]
- public string Language { get; set; }
-
- [Output]
- public string GitVersionInformationFilePath { get; set; }
+ if ( !input.ValidateInput() )
+ {
+ throw new Exception( "Invalid input." );
+ }
- public bool NoFetch { get; set; }
+ var logger = new TaskLogger();
+ Logger.SetLoggers( logger.LogInfo, logger.LogInfo, logger.LogWarning, s => logger.LogError( s ) );
+
- public override bool Execute()
- {
+ Output output = null;
try
{
- InnerExecute();
- return true;
+ output = InnerExecute(input );
}
catch (WarningException errorException)
{
logger.LogWarning(errorException.Message);
- return true;
+ output = new Output();
}
catch (Exception exception)
{
logger.LogError("Error occurred: " + exception);
- return false;
+ throw;
}
finally
{
Logger.Reset();
}
+
+ return output;
}
- void InnerExecute()
+ private static Output InnerExecute( Input input )
{
- VersionVariables versionVariables;
- if (!ExecuteCore.TryGetVersion(SolutionDirectory, out versionVariables, NoFetch, new Authentication()))
+ var execute = GitVersionTaskBase.CreateExecuteCore();
+ if (!execute.TryGetVersion(input.SolutionDirectory, out var versionVariables, input.NoFetch, new Authentication()))
{
- return;
+ return null;
}
- var fileExtension = GetFileExtension();
- var fileName = $"GitVersionInformation.g.{fileExtension}";
+ var fileWriteInfo = input.IntermediateOutputPath.GetWorkingDirectoryAndFileNameAndExtension(
+ input.Language,
+ input.ProjectFile,
+ ( pf, ext ) => $"GitVersionInformation.g.{ext}",
+ ( pf, ext ) => $"GitVersionInformation_{Path.GetFileNameWithoutExtension( pf )}_{Path.GetRandomFileName()}.g.{ext}"
+ );
- if (IntermediateOutputPath == null)
+ var output = new Output()
{
- fileName = $"GitVersionInformation_{Path.GetFileNameWithoutExtension(ProjectFile)}_{Path.GetRandomFileName()}.g.{fileExtension}";
- }
-
- var workingDirectory = IntermediateOutputPath ?? TempFileTracker.TempPath;
-
- GitVersionInformationFilePath = Path.Combine(workingDirectory, fileName);
-
- var generator = new GitVersionInformationGenerator(fileName, workingDirectory, versionVariables, new FileSystem());
+ GitVersionInformationFilePath = Path.Combine( fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName )
+ };
+ var generator = new GitVersionInformationGenerator( fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem());
generator.Generate();
+
+ return output;
}
- string GetFileExtension()
+ public sealed class Input
{
- switch (Language)
- {
- case "C#":
- return "cs";
+ public string SolutionDirectory { get; set; }
- case "F#":
- return "fs";
+ public string ProjectFile { get; set; }
- case "VB":
- return "vb";
+ public string IntermediateOutputPath { get; set; }
- default:
- throw new Exception($"Unknown language detected: '{Language}'");
- }
+ public string Language { get; set; }
+
+ public bool NoFetch { get; set; }
+ }
+
+ private static Boolean ValidateInput( this Input input )
+ {
+ return input != null
+ && !String.IsNullOrEmpty( input.SolutionDirectory )
+ && !String.IsNullOrEmpty(input.ProjectFile)
+ // && !String.IsNullOrEmpty(input.IntermediateOutputPath) // This was marked as [Required] but it InnerExecute still seems to allow it to be null... ?
+ && !String.IsNullOrEmpty(input.Language)
+ ;
+ }
+
+ public sealed class Output
+ {
+ public string GitVersionInformationFilePath { get; set; }
}
}
}
diff --git a/src/GitVersionTask/GetVersion.cs b/src/GitVersionTask/GetVersion.cs
index 31e4d6211b..1d7bbc2e5c 100644
--- a/src/GitVersionTask/GetVersion.cs
+++ b/src/GitVersionTask/GetVersion.cs
@@ -3,140 +3,125 @@ namespace GitVersionTask
using System;
using GitVersion;
- using Microsoft.Build.Framework;
-
- public class GetVersion : GitVersionTaskBase
+ public static class GetVersion
{
- TaskLogger logger;
-
- public GetVersion()
+ public static Output Execute(
+ Input input
+ )
{
- logger = new TaskLogger(this);
- Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
- }
+ if (!input.ValidateInput())
+ {
+ throw new Exception( "Invalid input." );
+ }
- [Required]
- public string SolutionDirectory { get; set; }
+ var logger = new TaskLogger();
+ Logger.SetLoggers( logger.LogInfo, logger.LogInfo, logger.LogWarning, s => logger.LogError( s ) );
+ var execute = GitVersionTaskBase.CreateExecuteCore();
- public bool NoFetch { get; set; }
+ Output output = null;
+ try
+ {
+ if ( execute.TryGetVersion(input.SolutionDirectory, out var variables, input.NoFetch, new Authentication()))
+ {
+ var outputType = typeof( Output );
+ output = new Output();
+ foreach (var variable in variables)
+ {
+ outputType.GetProperty(variable.Key).SetValue( output, variable.Value, null);
+ }
+ }
+ }
+ catch (WarningException errorException)
+ {
+ logger.LogWarning(errorException.Message);
+ output = new Output();
+ }
+ catch (Exception exception)
+ {
+ logger.LogError("Error occurred: " + exception);
+ throw;
+ }
+ finally
+ {
+ Logger.Reset();
+ }
- [Output]
- public string Major { get; set; }
+ return output;
+ }
- [Output]
- public string Minor { get; set; }
+ public sealed class Input
+ {
+ public string SolutionDirectory { get; set; }
- [Output]
- public string Patch { get; set; }
+ public bool NoFetch { get; set; }
+ }
- [Output]
- public string PreReleaseTag { get; set; }
+ private static Boolean ValidateInput(this Input input)
+ {
+ return !String.IsNullOrEmpty( input?.SolutionDirectory );
+ }
- [Output]
- public string PreReleaseTagWithDash { get; set; }
+ public sealed class Output
+ {
+ public string Major { get; set; }
- [Output]
- public string PreReleaseLabel { get; set; }
+ public string Minor { get; set; }
- [Output]
- public string PreReleaseNumber { get; set; }
+ public string Patch { get; set; }
- [Output]
- public string WeightedPreReleaseNumber { get; set; }
+ public string PreReleaseTag { get; set; }
- [Output]
- public string BuildMetaData { get; set; }
+ public string PreReleaseTagWithDash { get; set; }
- [Output]
- public string BuildMetaDataPadded { get; set; }
+ public string PreReleaseLabel { get; set; }
- [Output]
- public string FullBuildMetaData { get; set; }
+ public string PreReleaseNumber { get; set; }
- [Output]
- public string MajorMinorPatch { get; set; }
+ public string WeightedPreReleaseNumber { get; set; }
- [Output]
- public string SemVer { get; set; }
+ public string BuildMetaData { get; set; }
- [Output]
- public string LegacySemVer { get; set; }
+ public string BuildMetaDataPadded { get; set; }
- [Output]
- public string LegacySemVerPadded { get; set; }
+ public string FullBuildMetaData { get; set; }
- [Output]
- public string AssemblySemVer { get; set; }
+ public string MajorMinorPatch { get; set; }
- [Output]
- public string AssemblySemFileVer { get; set; }
+ public string SemVer { get; set; }
- [Output]
- public string FullSemVer { get; set; }
+ public string LegacySemVer { get; set; }
- [Output]
- public string InformationalVersion { get; set; }
+ public string LegacySemVerPadded { get; set; }
- [Output]
- public string BranchName { get; set; }
+ public string AssemblySemVer { get; set; }
- [Output]
- public string Sha { get; set; }
+ public string AssemblySemFileVer { get; set; }
- [Output]
- public string ShortSha { get; set; }
+ public string FullSemVer { get; set; }
- [Output]
- public string NuGetVersionV2 { get; set; }
+ public string InformationalVersion { get; set; }
- [Output]
- public string NuGetVersion { get; set; }
+ public string BranchName { get; set; }
- [Output]
- public string NuGetPreReleaseTagV2 { get; set; }
+ public string Sha { get; set; }
- [Output]
- public string NuGetPreReleaseTag { get; set; }
+ public string ShortSha { get; set; }
- [Output]
- public string CommitDate { get; set; }
+ public string NuGetVersionV2 { get; set; }
- [Output]
- public string CommitsSinceVersionSource { get; set; }
+ public string NuGetVersion { get; set; }
- [Output]
- public string CommitsSinceVersionSourcePadded { get; set; }
+ public string NuGetPreReleaseTagV2 { get; set; }
- public override bool Execute()
- {
- try
- {
- VersionVariables variables;
+ public string NuGetPreReleaseTag { get; set; }
- if (ExecuteCore.TryGetVersion(SolutionDirectory, out variables, NoFetch, new Authentication()))
- {
- var thisType = typeof(GetVersion);
- foreach (var variable in variables)
- {
- thisType.GetProperty(variable.Key).SetValue(this, variable.Value, null);
- }
- }
- return true;
- }
- catch (WarningException errorException)
- {
- logger.LogWarning(errorException.Message);
- return true;
- }
- catch (Exception exception)
- {
- logger.LogError("Error occurred: " + exception);
- return false;
- }
- finally
- {
- Logger.Reset();
- }
+ public string CommitDate { 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 39f6ddf96e..62265f9bf8 100644
--- a/src/GitVersionTask/GitVersionTask.csproj
+++ b/src/GitVersionTask/GitVersionTask.csproj
@@ -20,6 +20,7 @@
version=$(PackageVersion);configuration=$(Configuration);utilpackversion=$(PackageVersion_UtilPackNuGetMSBuild);libgit2sharpversion=$(PackageVersion_LibGit2Sharp);yamldotnetversion=$(PackageVersion_YamlDotNet)
$(AssemblyName)
+ latest
@@ -37,9 +38,7 @@
All
-
-
-
+
all
runtime; build; native; contentfiles; analyzers
diff --git a/src/GitVersionTask/GitVersionTaskBase.cs b/src/GitVersionTask/GitVersionTaskBase.cs
index 3337ad8fb6..45aa95ce68 100644
--- a/src/GitVersionTask/GitVersionTaskBase.cs
+++ b/src/GitVersionTask/GitVersionTaskBase.cs
@@ -1,23 +1,72 @@
-namespace GitVersionTask
+namespace GitVersionTask
{
using GitVersion;
using GitVersion.Helpers;
+ using System;
+ using System.IO;
- using Microsoft.Build.Utilities;
-
- public abstract class GitVersionTaskBase : Task
+ public static class GitVersionTaskBase
{
- readonly ExecuteCore executeCore;
+ public static ExecuteCore CreateExecuteCore()
+ => new ExecuteCore( new FileSystem() );
+
+ private static string GetFileExtension( this String language )
+ {
+ switch ( language )
+ {
+ case "C#":
+ return "cs";
+
+ case "F#":
+ return "fs";
+
+ case "VB":
+ return "vb";
- protected GitVersionTaskBase()
+ default:
+ throw new Exception( $"Unknown language detected: '{language}'" );
+ }
+ }
+
+ public static FileWriteInfo GetWorkingDirectoryAndFileNameAndExtension(
+ this String intermediateOutputPath,
+ String language,
+ String projectFile,
+ Func fileNameWithIntermediatePath,
+ Func fileNameNoIntermediatePath
+ )
{
- var fileSystem = new FileSystem();
- executeCore = new ExecuteCore(fileSystem);
+ var fileExtension = language.GetFileExtension();
+ String workingDirectory, fileName;
+ if ( intermediateOutputPath == null )
+ {
+ fileName = fileNameWithIntermediatePath(projectFile, fileExtension);
+ workingDirectory = TempFileTracker.TempPath;
+ }
+ else
+ {
+ workingDirectory = intermediateOutputPath;
+ fileName = fileNameNoIntermediatePath(projectFile, fileExtension);
+ }
+ return new FileWriteInfo(workingDirectory, fileName, fileExtension);
}
+ }
- protected ExecuteCore ExecuteCore
+ public sealed class FileWriteInfo
+ {
+ public FileWriteInfo(
+ String workingDirectory,
+ String fileName,
+ String fileExtension
+ )
{
- get { return executeCore; }
+ this.WorkingDirectory = this.WorkingDirectory;
+ this.FileName = fileName;
+ this.FileExtension = fileExtension;
}
+
+ public String WorkingDirectory { get; }
+ public String FileName { get; }
+ public String FileExtension { get; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GitVersionTask/InvalidFileChecker.cs b/src/GitVersionTask/InvalidFileChecker.cs
index d20be03e56..8cc308fddb 100644
--- a/src/GitVersionTask/InvalidFileChecker.cs
+++ b/src/GitVersionTask/InvalidFileChecker.cs
@@ -4,7 +4,6 @@
using System.Linq;
using System.Text.RegularExpressions;
using GitVersion;
-using Microsoft.Build.Framework;
public static class InvalidFileChecker
{
@@ -14,7 +13,7 @@ public static class InvalidFileChecker
{ ".vb", VisualBasicFileContainsVersionAttribute }
};
- public static void CheckForInvalidFiles(IEnumerable compileFiles, string projectFile)
+ public static void CheckForInvalidFiles(IEnumerable compileFiles, string projectFile)
{
foreach (var compileFile in GetInvalidFiles(compileFiles, projectFile))
{
@@ -98,9 +97,9 @@ static bool VisualBasicFileContainsVersionAttribute(string compileFile, string p
\s*\(\s*\)\s*\> # End brackets ()>");
}
- static IEnumerable GetInvalidFiles(IEnumerable compileFiles, string projectFile)
+ static IEnumerable GetInvalidFiles(IEnumerable compileFiles, string projectFile)
{
- return compileFiles.Select(x => x.ItemSpec)
+ return compileFiles
.Where(compileFile => compileFile.Contains("AssemblyInfo"))
.Where(s => FileContainsVersionAttribute(s, projectFile));
}
diff --git a/src/GitVersionTask/NugetAssets/build/Infrastructure.props b/src/GitVersionTask/NugetAssets/build/Infrastructure.props
index e5ff8092e1..93d9083b49 100644
--- a/src/GitVersionTask/NugetAssets/build/Infrastructure.props
+++ b/src/GitVersionTask/NugetAssets/build/Infrastructure.props
@@ -1,4 +1,4 @@
-
+
@@ -9,16 +9,16 @@
$(GitVersionTaskBuildTools_FunctionalityDir)obj/
-
+
$(PackageVersion_UtilPackNuGetMSBuild)
- $(MSBuildThisFileDirectory)../../../utilpack.nuget.msbuild/$(UtilPackVersion)/build/UtilPack.NuGet.MSBuild.props
+ $(MSBuildThisFileDirectory)../../../nugetutils.msbuild.exec/$(UtilPackVersion)/build/NuGetUtils.MSBuild.Exec.props
$([System.IO.Path]::GetFullPath('$(UtilPackNuGetMSBuildPropsPath)'))
- true
+ true
@@ -35,7 +35,7 @@
-
+
diff --git a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props b/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
index 36b320e5a5..783dfcc277 100644
--- a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
+++ b/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
@@ -1,4 +1,4 @@
-
+
$(MSBuildProjectDirectory)\..\
@@ -40,43 +40,55 @@
- $(UtilPackTaskFactoryParametersXML)
+
+ $(UtilPackTaskFactoryParametersXML)
+ Execute
+
- $(UtilPackTaskFactoryParametersXML)
+
+ $(UtilPackTaskFactoryParametersXML)
+ Execute
+
- $(UtilPackTaskFactoryParametersXML)
+
+ $(UtilPackTaskFactoryParametersXML)
+ Execute
+
- $(UtilPackTaskFactoryParametersXML)
+
+ $(UtilPackTaskFactoryParametersXML)
+ Execute
+
True
-
\ No newline at end of file
+
diff --git a/src/GitVersionTask/TaskLogger.cs b/src/GitVersionTask/TaskLogger.cs
index ba33729ed8..baa46b9b09 100644
--- a/src/GitVersionTask/TaskLogger.cs
+++ b/src/GitVersionTask/TaskLogger.cs
@@ -1,26 +1,32 @@
-using Microsoft.Build.Framework;
+using System;
+using System.IO;
class TaskLogger
{
- ITask task;
+ private readonly TextWriter stdout;
+ private readonly TextWriter stderr;
- public TaskLogger(ITask task)
+ public TaskLogger(
+ TextWriter paramStdout = null,
+ TextWriter paramStderr = null
+ )
{
- this.task = task;
+ this.stdout = paramStdout ?? Console.Out;
+ this.stderr = paramStderr ?? Console.Error;
}
public void LogWarning(string message)
{
- task.BuildEngine.LogWarningEvent(new BuildWarningEventArgs(string.Empty, string.Empty, null, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
+ this.stdout.WriteLine( message );
}
public void LogInfo(string message)
{
- task.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Normal));
+ this.stdout.WriteLine( message );
}
- public void LogError(string message, string file = null)
+ public void LogError(string message)
{
- task.BuildEngine.LogErrorEvent(new BuildErrorEventArgs(string.Empty, string.Empty, file, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
+ this.stderr.WriteLine( message );
}
-}
\ No newline at end of file
+}
diff --git a/src/GitVersionTask/UpdateAssemblyInfo.cs b/src/GitVersionTask/UpdateAssemblyInfo.cs
index 27ccab47d1..87744a9c01 100644
--- a/src/GitVersionTask/UpdateAssemblyInfo.cs
+++ b/src/GitVersionTask/UpdateAssemblyInfo.cs
@@ -5,113 +5,112 @@ namespace GitVersionTask
using GitVersion;
using GitVersion.Helpers;
- using Microsoft.Build.Framework;
- public class UpdateAssemblyInfo : GitVersionTaskBase
+ public static class UpdateAssemblyInfo
{
- TaskLogger logger;
-
- public UpdateAssemblyInfo()
+ public static Output Execute(
+ Input input
+ )
{
- logger = new TaskLogger(this);
- Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
- }
-
- [Required]
- public string SolutionDirectory { get; set; }
-
- [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; }
+ if ( !input.ValidateInput() )
+ {
+ throw new Exception( "Invalid input." );
+ }
- public bool NoFetch { get; set; }
+ var logger = new TaskLogger();
+ Logger.SetLoggers( logger.LogInfo, logger.LogInfo, logger.LogWarning, s => logger.LogError( s ) );
- public override bool Execute()
- {
+ Output output = null;
try
{
- InnerExecute();
- return true;
+ output = InnerExecute( input );
}
catch (WarningException errorException)
{
logger.LogWarning(errorException.Message);
- return true;
+ output = new Output();
}
catch (Exception exception)
{
logger.LogError("Error occurred: " + exception);
- return false;
+ throw;
}
finally
{
Logger.Reset();
}
+
+ return output;
}
- void InnerExecute()
+ private static Output InnerExecute( Input input )
{
+ var execute = GitVersionTaskBase.CreateExecuteCore();
+
TempFileTracker.DeleteTempFiles();
- InvalidFileChecker.CheckForInvalidFiles(CompileFiles, ProjectFile);
+ InvalidFileChecker.CheckForInvalidFiles(input.CompileFiles, input.ProjectFile);
- VersionVariables versionVariables;
- if (!ExecuteCore.TryGetVersion(SolutionDirectory, out versionVariables, NoFetch, new Authentication()))
+ if (!execute.TryGetVersion( input.SolutionDirectory, out var versionVariables, input.NoFetch, new Authentication()))
{
- return;
+ return null;
}
- CreateTempAssemblyInfo(versionVariables);
+ return CreateTempAssemblyInfo(input, versionVariables);
}
- void CreateTempAssemblyInfo(VersionVariables versionVariables)
+ private static Output CreateTempAssemblyInfo( Input input, VersionVariables versionVariables)
{
- var fileExtension = GetFileExtension();
- var assemblyInfoFileName = $"GitVersionTaskAssemblyInfo.g.{fileExtension}";
-
- if (IntermediateOutputPath == null)
+ var fileWriteInfo = input.IntermediateOutputPath.GetWorkingDirectoryAndFileNameAndExtension(
+ input.Language,
+ input.ProjectFile,
+ ( pf, ext ) => $"GitVersionTaskAssemblyInfo.g.{ext}",
+ ( pf, ext ) => $"AssemblyInfo_{Path.GetFileNameWithoutExtension( pf )}_{Path.GetRandomFileName()}.g.{ext}"
+ );
+
+ var output = new Output()
{
- assemblyInfoFileName = $"AssemblyInfo_{Path.GetFileNameWithoutExtension(ProjectFile)}_{Path.GetRandomFileName()}.g.{fileExtension}";
- }
-
- var workingDirectory = IntermediateOutputPath ?? TempFileTracker.TempPath;
+ AssemblyInfoTempFilePath = Path.Combine( fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName )
+ };
- AssemblyInfoTempFilePath = Path.Combine(workingDirectory, assemblyInfoFileName);
-
- using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFileName, workingDirectory, versionVariables, new FileSystem(), true))
+ using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater( fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem(), true))
{
assemblyInfoFileUpdater.Update();
assemblyInfoFileUpdater.CommitChanges();
}
+
+ return output;
}
- string GetFileExtension()
+ public sealed class Input
{
- switch(Language)
- {
- case "C#":
- return "cs";
+ public string SolutionDirectory { get; set; }
- case "F#":
- return "fs";
+ public string ProjectFile { get; set; }
- case "VB":
- return "vb";
+ public string IntermediateOutputPath { get; set; }
- default:
- throw new Exception($"Unknown language detected: '{Language}'");
- }
+ public String[] CompileFiles { get; set; }
+
+ public string Language { get; set; }
+
+ public bool NoFetch { get; set; }
+ }
+
+ private static Boolean ValidateInput(this Input input)
+ {
+ return input != null
+ && !String.IsNullOrEmpty( input.SolutionDirectory )
+ && !String.IsNullOrEmpty( input.ProjectFile )
+ && !String.IsNullOrEmpty( input.IntermediateOutputPath )
+ && input.CompileFiles != null
+ && !String.IsNullOrEmpty( input.Language )
+ ;
+ }
+
+ public sealed class Output
+ {
+ public string AssemblyInfoTempFilePath { get; set; }
}
}
}
diff --git a/src/GitVersionTask/UtilPack.Version.props b/src/GitVersionTask/UtilPack.Version.props
index 109fbf9d1e..42fd789c7e 100644
--- a/src/GitVersionTask/UtilPack.Version.props
+++ b/src/GitVersionTask/UtilPack.Version.props
@@ -1,6 +1,6 @@
- 2.9.1
+ 2.0.0
diff --git a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs b/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
index fcc1f8998d..777dca7192 100644
--- a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
+++ b/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
@@ -3,58 +3,63 @@ namespace GitVersionTask
using System;
using System.Collections.Generic;
using GitVersion;
- using Microsoft.Build.Framework;
- public class WriteVersionInfoToBuildLog : GitVersionTaskBase
+ public static class WriteVersionInfoToBuildLog
{
- readonly TaskLogger logger;
- public WriteVersionInfoToBuildLog()
+ public static Output Execute(
+ Input input
+ )
{
- logger = new TaskLogger(this);
- Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
- }
+ if ( !input.ValidateInput() )
+ {
+ throw new Exception( "Invalid input." );
+ }
- [Required]
- public string SolutionDirectory { get; set; }
+ var logger = new TaskLogger();
+ Logger.SetLoggers( logger.LogInfo, logger.LogInfo, logger.LogWarning, s => logger.LogError( s ) );
- public bool NoFetch { get; set; }
- public override bool Execute()
- {
+ Output output = null;
try
{
- InnerExecute();
- return true;
+ output = InnerExecute(logger, input);
}
catch (WarningException errorException)
{
logger.LogWarning(errorException.Message);
- return true;
+ output = new Output();
}
catch (Exception exception)
{
logger.LogError("Error occurred: " + exception);
- return false;
+ throw;
}
finally
{
Logger.Reset();
}
+
+ return output;
}
- void InnerExecute()
+ private static Output InnerExecute(
+ TaskLogger logger,
+ Input input
+ )
{
- VersionVariables result;
- if (!ExecuteCore.TryGetVersion(SolutionDirectory, out result, NoFetch, new Authentication()))
+ var execute = GitVersionTaskBase.CreateExecuteCore();
+ if (!execute.TryGetVersion(input.SolutionDirectory, out var result, input.NoFetch, new Authentication()))
{
- return;
+ return null;
}
- WriteIntegrationParameters(BuildServerList.GetApplicableBuildServers(), result);
+ WriteIntegrationParameters(logger, BuildServerList.GetApplicableBuildServers(), result);
+
+ return new Output();
}
- void WriteIntegrationParameters(IEnumerable applicableBuildServers, VersionVariables variables)
+ private static void WriteIntegrationParameters(TaskLogger logger, IEnumerable applicableBuildServers, VersionVariables variables)
{
foreach (var buildServer in applicableBuildServers)
{
@@ -67,5 +72,22 @@ void WriteIntegrationParameters(IEnumerable applicableBuildServers
}
}
}
+
+ public sealed class Input
+ {
+ public string SolutionDirectory { get; set; }
+
+ public bool NoFetch { get; set; }
+ }
+
+ public static Boolean ValidateInput(this Input input)
+ {
+ return !String.IsNullOrEmpty( input?.SolutionDirectory );
+ }
+
+ public sealed class Output
+ {
+ // No output for this task
+ }
}
}
From ac88f0d55dc081a25c4974a5832d07bb5fac306a Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Sun, 10 Mar 2019 23:06:56 +0200
Subject: [PATCH 02/15] Also updated .nuspec file with new dependency, and
modified task factory name in .props file.
---
src/GitVersionTask/NugetAssets/GitVersionTask.nuspec | 8 ++++----
.../build/functionality/GitVersionCommon.props | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec b/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec
index b3436fdce8..65f98a0b56 100644
--- a/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec
+++ b/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec
@@ -1,4 +1,4 @@
-
+
GitVersionTask
@@ -17,15 +17,15 @@
Git Versioning GitVersion GitFlowVersion GitFlow GitHubFlow SemVer
-
+
-
+
-
+
diff --git a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props b/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
index 783dfcc277..5e868860fb 100644
--- a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
+++ b/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
@@ -41,7 +41,7 @@
@@ -53,7 +53,7 @@
@@ -65,7 +65,7 @@
@@ -77,7 +77,7 @@
From 61a71ebdcb64e5c87ec4302eaa87045d5b6861dc Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Mon, 11 Mar 2019 00:02:55 +0200
Subject: [PATCH 03/15] Making GitVersionTask.Tests compilable again.
---
.../GetVersionTaskTests.cs | 6 +--
.../InvalidFileCheckerTests.cs | 24 +++++-----
.../Mocks/MockBuildEngine.cs | 45 -------------------
.../Mocks/MockTaskItem.cs | 40 -----------------
4 files changed, 13 insertions(+), 102 deletions(-)
delete mode 100644 src/GitVersionTask.Tests/Mocks/MockBuildEngine.cs
delete mode 100644 src/GitVersionTask.Tests/Mocks/MockTaskItem.cs
diff --git a/src/GitVersionTask.Tests/GetVersionTaskTests.cs b/src/GitVersionTask.Tests/GetVersionTaskTests.cs
index a3f6d5c7d1..22fbaf54e5 100644
--- a/src/GitVersionTask.Tests/GetVersionTaskTests.cs
+++ b/src/GitVersionTask.Tests/GetVersionTaskTests.cs
@@ -1,7 +1,6 @@
-using System.Linq;
+using System.Linq;
using GitVersion;
using GitVersionTask;
-using Microsoft.Build.Framework;
using NUnit.Framework;
using Shouldly;
@@ -11,9 +10,8 @@ public class GetVersionTaskTests : TestBase
[Test]
public void OutputsShouldMatchVariableProvider()
{
- var taskProperties = typeof(GetVersion)
+ var taskProperties = typeof(GetVersion.Output)
.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 e8877d2f94..c25568137a 100644
--- a/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
+++ b/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
@@ -1,8 +1,6 @@
using System;
using System.IO;
using GitVersion;
-using GitVersionTask.Tests.Mocks;
-using Microsoft.Build.Framework;
using NUnit.Framework;
[TestFixture]
@@ -41,7 +39,7 @@ public void VerifyIgnoreNonAssemblyInfoFile()
");
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "SomeOtherFile.cs" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles(new[] { "SomeOtherFile.cs" }, projectFile);
}
[Test]
@@ -57,7 +55,7 @@ public void VerifyAttributeFoundCSharp([Values("AssemblyVersion", "AssemblyFileV
", attribute);
}
- var ex = Assert.Throws(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile), attribute);
+ var ex = Assert.Throws(() => InvalidFileChecker.CheckForInvalidFiles(new [] { "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"));
}
@@ -75,7 +73,7 @@ public void VerifyUnformattedAttributeFoundCSharp([Values("AssemblyVersion", "As
", attribute);
}
- var ex = Assert.Throws(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile), attribute);
+ var ex = Assert.Throws(() => InvalidFileChecker.CheckForInvalidFiles(new [] { "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"));
}
@@ -92,7 +90,7 @@ public void VerifyCommentWorksCSharp([Values("AssemblyVersion", "AssemblyFileVer
", attribute);
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
}
[Test]
@@ -111,7 +109,7 @@ public class Temp
", attribute);
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
}
[Test]
@@ -129,7 +127,7 @@ public class {0}
", attribute);
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.cs" }, projectFile);
}
[Test]
@@ -145,7 +143,7 @@ Imports System.Reflection
", attribute);
}
- var ex = Assert.Throws(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile), attribute);
+ var ex = Assert.Throws(() => InvalidFileChecker.CheckForInvalidFiles(new[] { "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"));
}
@@ -163,7 +161,7 @@ Imports System.Reflection
", attribute);
}
- var ex = Assert.Throws(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile), attribute);
+ var ex = Assert.Throws(() => InvalidFileChecker.CheckForInvalidFiles(new[] { "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"));
}
@@ -180,7 +178,7 @@ Imports System.Reflection
", attribute);
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
}
[Test]
@@ -198,7 +196,7 @@ End Class
", attribute);
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
}
[Test]
@@ -215,6 +213,6 @@ End Class
", attribute);
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles(new[] { "AssemblyInfo.vb" }, projectFile);
}
}
diff --git a/src/GitVersionTask.Tests/Mocks/MockBuildEngine.cs b/src/GitVersionTask.Tests/Mocks/MockBuildEngine.cs
deleted file mode 100644
index 710462eff5..0000000000
--- a/src/GitVersionTask.Tests/Mocks/MockBuildEngine.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System;
-using System.Collections;
-using Microsoft.Build.Framework;
-
-class MockBuildEngine : IBuildEngine
-{
- public void LogErrorEvent(BuildErrorEventArgs e)
- { }
-
- public void LogWarningEvent(BuildWarningEventArgs e)
- { }
-
- public void LogMessageEvent(BuildMessageEventArgs e)
- { }
-
- public void LogCustomEvent(CustomBuildEventArgs e)
- {
- throw new NotImplementedException();
- }
-
- public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs)
- {
- throw new NotImplementedException();
- }
-
- public bool ContinueOnError
- {
- get { throw new NotImplementedException(); }
- }
-
- public int LineNumberOfTaskNode
- {
- get { throw new NotImplementedException(); }
- }
-
- public int ColumnNumberOfTaskNode
- {
- get { throw new NotImplementedException(); }
- }
-
- public string ProjectFileOfTaskNode
- {
- get { throw new NotImplementedException(); }
- }
-}
\ No newline at end of file
diff --git a/src/GitVersionTask.Tests/Mocks/MockTaskItem.cs b/src/GitVersionTask.Tests/Mocks/MockTaskItem.cs
deleted file mode 100644
index 45a98850b9..0000000000
--- a/src/GitVersionTask.Tests/Mocks/MockTaskItem.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-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
From 844fbc06f182468f810a3d434923a408de2a6070 Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Thu, 14 Mar 2019 01:06:40 +0200
Subject: [PATCH 04/15] Updated to newer NuGetUtils.MSBuild.Exec, which runs on
.NET Desktop successfully now. Also modified the task factory parameter as
needed.
---
src/GitVersionTask/NugetAssets/build/Infrastructure.props | 3 +--
src/GitVersionTask/UtilPack.Version.props | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/GitVersionTask/NugetAssets/build/Infrastructure.props b/src/GitVersionTask/NugetAssets/build/Infrastructure.props
index 93d9083b49..f21a1bb007 100644
--- a/src/GitVersionTask/NugetAssets/build/Infrastructure.props
+++ b/src/GitVersionTask/NugetAssets/build/Infrastructure.props
@@ -23,8 +23,7 @@
- .NETFramework
- 4.6.1
+ net461
$(UtilPackTaskFactoryParametersXML)
diff --git a/src/GitVersionTask/UtilPack.Version.props b/src/GitVersionTask/UtilPack.Version.props
index 42fd789c7e..61d0a62649 100644
--- a/src/GitVersionTask/UtilPack.Version.props
+++ b/src/GitVersionTask/UtilPack.Version.props
@@ -1,6 +1,6 @@
- 2.0.0
+ 2.0.1
From e3fd1b7efe78dd5e3f9c189952dcc806d7f77297 Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Thu, 14 Mar 2019 17:00:34 +0200
Subject: [PATCH 05/15] Fixing a typo causing NullReferenceException.
---
src/GitVersionTask/GitVersionTaskBase.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/GitVersionTask/GitVersionTaskBase.cs b/src/GitVersionTask/GitVersionTaskBase.cs
index 45aa95ce68..cd68978b34 100644
--- a/src/GitVersionTask/GitVersionTaskBase.cs
+++ b/src/GitVersionTask/GitVersionTaskBase.cs
@@ -60,7 +60,7 @@ public FileWriteInfo(
String fileExtension
)
{
- this.WorkingDirectory = this.WorkingDirectory;
+ this.WorkingDirectory = workingDirectory;
this.FileName = fileName;
this.FileExtension = fileExtension;
}
From 43121f3aadff8aa3582a9cd4482c51e55852aaef Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Mon, 18 Mar 2019 22:55:25 +0200
Subject: [PATCH 06/15] Updating to newer NuGetUtils.MSBuild.Exec version,
which fixes the bug with ITaskItems (seen as String arrays to
GitVersionTask).
---
src/GitVersionTask/UtilPack.Version.props | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/GitVersionTask/UtilPack.Version.props b/src/GitVersionTask/UtilPack.Version.props
index 61d0a62649..7fa286761b 100644
--- a/src/GitVersionTask/UtilPack.Version.props
+++ b/src/GitVersionTask/UtilPack.Version.props
@@ -1,6 +1,6 @@
- 2.0.1
+ 2.0.2
From 166ffe0cf8c9d183697ff693b6a7c179497d45f8 Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Wed, 20 Mar 2019 20:43:50 +0200
Subject: [PATCH 07/15] Updated NuGetUtils.MSBuild.Exec to 2.0.3.
---
src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props
diff --git a/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props b/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props
new file mode 100644
index 0000000000..ec1509507e
--- /dev/null
+++ b/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props
@@ -0,0 +1,6 @@
+
+
+ 2.0.3
+
+
+
From 44c73b2e06cffc580353bc9a8bc126d454415d10 Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Wed, 20 Mar 2019 20:45:04 +0200
Subject: [PATCH 08/15] Partially changed UtilPack names to
NuGetUtils.MSBuild.Exec. Need more thorough check later though.
---
src/GitVersionTask/GitVersionTask.csproj | 8 ++++----
src/GitVersionTask/NugetAssets/GitVersionTask.nuspec | 2 +-
src/GitVersionTask/NugetAssets/build/Infrastructure.props | 4 ++--
src/GitVersionTask/UtilPack.Version.props | 6 ------
4 files changed, 7 insertions(+), 13 deletions(-)
delete mode 100644 src/GitVersionTask/UtilPack.Version.props
diff --git a/src/GitVersionTask/GitVersionTask.csproj b/src/GitVersionTask/GitVersionTask.csproj
index 62265f9bf8..ca085ee175 100644
--- a/src/GitVersionTask/GitVersionTask.csproj
+++ b/src/GitVersionTask/GitVersionTask.csproj
@@ -1,7 +1,7 @@
-
+
net461;netstandard2.0
@@ -24,10 +24,10 @@
-
+
-
+
build\
@@ -38,7 +38,7 @@
All
-
+
all
runtime; build; native; contentfiles; analyzers
diff --git a/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec b/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec
index 65f98a0b56..4a95b6e0d8 100644
--- a/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec
+++ b/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec
@@ -33,6 +33,6 @@
-
+
diff --git a/src/GitVersionTask/NugetAssets/build/Infrastructure.props b/src/GitVersionTask/NugetAssets/build/Infrastructure.props
index f21a1bb007..4ef57bf76a 100644
--- a/src/GitVersionTask/NugetAssets/build/Infrastructure.props
+++ b/src/GitVersionTask/NugetAssets/build/Infrastructure.props
@@ -1,5 +1,5 @@
-
+
@@ -10,7 +10,7 @@
- $(PackageVersion_UtilPackNuGetMSBuild)
+ $(PackageVersion_NuGetUtilsMSBuildExec)
$(MSBuildThisFileDirectory)../../../nugetutils.msbuild.exec/$(UtilPackVersion)/build/NuGetUtils.MSBuild.Exec.props
$([System.IO.Path]::GetFullPath('$(UtilPackNuGetMSBuildPropsPath)'))
diff --git a/src/GitVersionTask/UtilPack.Version.props b/src/GitVersionTask/UtilPack.Version.props
deleted file mode 100644
index 7fa286761b..0000000000
--- a/src/GitVersionTask/UtilPack.Version.props
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
- 2.0.2
-
-
-
From 6e16a8c1dbf6779765777983adfd3db39d8fa771 Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Wed, 20 Mar 2019 21:34:38 +0200
Subject: [PATCH 09/15] Forgot to update one reference to renamed property.
---
src/GitVersionTask/GitVersionTask.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/GitVersionTask/GitVersionTask.csproj b/src/GitVersionTask/GitVersionTask.csproj
index ca085ee175..8bc70a2f56 100644
--- a/src/GitVersionTask/GitVersionTask.csproj
+++ b/src/GitVersionTask/GitVersionTask.csproj
@@ -17,7 +17,7 @@
NugetAssets\GitVersionTask.nuspec
0.0.1-alpha-0001
- version=$(PackageVersion);configuration=$(Configuration);utilpackversion=$(PackageVersion_UtilPackNuGetMSBuild);libgit2sharpversion=$(PackageVersion_LibGit2Sharp);yamldotnetversion=$(PackageVersion_YamlDotNet)
+ version=$(PackageVersion);configuration=$(Configuration);utilpackversion=$(PackageVersion_NuGetUtilsMSBuildExec);libgit2sharpversion=$(PackageVersion_LibGit2Sharp);yamldotnetversion=$(PackageVersion_YamlDotNet)
$(AssemblyName)
latest
From 855a7f0b7eb91b1870bb3997251af2db61f5345c Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Thu, 21 Mar 2019 00:22:28 +0200
Subject: [PATCH 10/15] Updating to newer version of NuGetUtils.MSBuild.Exec in
order to cut down the amount of process invocations used by the task factory.
---
src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props b/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props
index ec1509507e..40d39c08a1 100644
--- a/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props
+++ b/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props
@@ -1,6 +1,6 @@
- 2.0.3
+ 2.0.4
From c52b0727e81244da50cd701ac372809d7b7f83cc Mon Sep 17 00:00:00 2001
From: Doug Semler
Date: Thu, 21 Mar 2019 10:40:51 -0400
Subject: [PATCH 11/15] Do not reset Logger during call to Execute()
If the MSBuild Task object is reused, calls after the first call to the
Execute method fail because of the Reset.
---
src/GitVersionTask/GenerateGitVersionInformation.cs | 4 ----
src/GitVersionTask/GetVersion.cs | 4 ----
src/GitVersionTask/UpdateAssemblyInfo.cs | 4 ----
src/GitVersionTask/WriteVersionInfoToBuildLog.cs | 4 ----
4 files changed, 16 deletions(-)
diff --git a/src/GitVersionTask/GenerateGitVersionInformation.cs b/src/GitVersionTask/GenerateGitVersionInformation.cs
index d91a7898dc..cc5664561d 100644
--- a/src/GitVersionTask/GenerateGitVersionInformation.cs
+++ b/src/GitVersionTask/GenerateGitVersionInformation.cs
@@ -50,10 +50,6 @@ public override bool Execute()
logger.LogError("Error occurred: " + exception);
return false;
}
- finally
- {
- Logger.Reset();
- }
}
void InnerExecute()
diff --git a/src/GitVersionTask/GetVersion.cs b/src/GitVersionTask/GetVersion.cs
index f041a77120..a51126422e 100644
--- a/src/GitVersionTask/GetVersion.cs
+++ b/src/GitVersionTask/GetVersion.cs
@@ -136,10 +136,6 @@ public override bool Execute()
logger.LogError("Error occurred: " + exception);
return false;
}
- finally
- {
- Logger.Reset();
- }
}
}
}
diff --git a/src/GitVersionTask/UpdateAssemblyInfo.cs b/src/GitVersionTask/UpdateAssemblyInfo.cs
index 27ccab47d1..b8fe5daa67 100644
--- a/src/GitVersionTask/UpdateAssemblyInfo.cs
+++ b/src/GitVersionTask/UpdateAssemblyInfo.cs
@@ -54,10 +54,6 @@ public override bool Execute()
logger.LogError("Error occurred: " + exception);
return false;
}
- finally
- {
- Logger.Reset();
- }
}
void InnerExecute()
diff --git a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs b/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
index fcc1f8998d..c11a96890f 100644
--- a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
+++ b/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
@@ -37,10 +37,6 @@ public override bool Execute()
logger.LogError("Error occurred: " + exception);
return false;
}
- finally
- {
- Logger.Reset();
- }
}
void InnerExecute()
From 9be3c29d4edebbbe820cc4ff2faef07c40cbde16 Mon Sep 17 00:00:00 2001
From: Doug Semler
Date: Thu, 21 Mar 2019 11:04:35 -0400
Subject: [PATCH 12/15] Clean up logging
Consolidate all the logging calls that was separated out into the base
Task class rather than confusing multiple locations.
---
src/GitVersionTask/BuildLogger.cs | 25 ------------------
.../GenerateGitVersionInformation.cs | 8 ++----
src/GitVersionTask/GetVersion.cs | 8 ++----
src/GitVersionTask/GitVersionTaskBase.cs | 22 ++++++++++++++++
src/GitVersionTask/TaskLogger.cs | 26 -------------------
src/GitVersionTask/UpdateAssemblyInfo.cs | 8 ++----
.../WriteVersionInfoToBuildLog.cs | 16 +++++-------
7 files changed, 34 insertions(+), 79 deletions(-)
delete mode 100644 src/GitVersionTask/BuildLogger.cs
delete mode 100644 src/GitVersionTask/TaskLogger.cs
diff --git a/src/GitVersionTask/BuildLogger.cs b/src/GitVersionTask/BuildLogger.cs
deleted file mode 100644
index 9c9ec461cf..0000000000
--- a/src/GitVersionTask/BuildLogger.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Microsoft.Build.Framework;
-using Microsoft.Build.Utilities;
-
-public static class BuildLogger
-{
- public static void LogDebug(this Task task, string message)
- {
- task.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Low));
- }
-
- public static void LogInfo(this Task task, string message)
- {
- task.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Normal));
- }
-
- public static void LogWarning(this Task task, string message)
- {
- task.BuildEngine.LogWarningEvent(new BuildWarningEventArgs(string.Empty, string.Empty, null, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
- }
-
- public static void LogError(this Task task, string message, string file = null)
- {
- task.BuildEngine.LogErrorEvent(new BuildErrorEventArgs(string.Empty, string.Empty, file, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
- }
-}
\ No newline at end of file
diff --git a/src/GitVersionTask/GenerateGitVersionInformation.cs b/src/GitVersionTask/GenerateGitVersionInformation.cs
index cc5664561d..2e37e3975f 100644
--- a/src/GitVersionTask/GenerateGitVersionInformation.cs
+++ b/src/GitVersionTask/GenerateGitVersionInformation.cs
@@ -8,12 +8,8 @@ namespace GitVersionTask
public class GenerateGitVersionInformation : GitVersionTaskBase
{
- TaskLogger logger;
-
public GenerateGitVersionInformation()
{
- logger = new TaskLogger(this);
- Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
}
[Required]
@@ -42,12 +38,12 @@ public override bool Execute()
}
catch (WarningException errorException)
{
- logger.LogWarning(errorException.Message);
+ this.LogWarning(errorException.Message);
return true;
}
catch (Exception exception)
{
- logger.LogError("Error occurred: " + exception);
+ this.LogError("Error occurred: " + exception);
return false;
}
}
diff --git a/src/GitVersionTask/GetVersion.cs b/src/GitVersionTask/GetVersion.cs
index a51126422e..07f8be237f 100644
--- a/src/GitVersionTask/GetVersion.cs
+++ b/src/GitVersionTask/GetVersion.cs
@@ -7,12 +7,8 @@ namespace GitVersionTask
public class GetVersion : GitVersionTaskBase
{
- TaskLogger logger;
-
public GetVersion()
{
- logger = new TaskLogger(this);
- Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
}
[Required]
@@ -128,12 +124,12 @@ public override bool Execute()
}
catch (WarningException errorException)
{
- logger.LogWarning(errorException.Message);
+ this.LogWarning(errorException.Message);
return true;
}
catch (Exception exception)
{
- logger.LogError("Error occurred: " + exception);
+ this.LogError("Error occurred: " + exception);
return false;
}
}
diff --git a/src/GitVersionTask/GitVersionTaskBase.cs b/src/GitVersionTask/GitVersionTaskBase.cs
index 3337ad8fb6..caeb254ed2 100644
--- a/src/GitVersionTask/GitVersionTaskBase.cs
+++ b/src/GitVersionTask/GitVersionTaskBase.cs
@@ -3,6 +3,7 @@
using GitVersion;
using GitVersion.Helpers;
+ using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
public abstract class GitVersionTaskBase : Task
@@ -13,11 +14,32 @@ protected GitVersionTaskBase()
{
var fileSystem = new FileSystem();
executeCore = new ExecuteCore(fileSystem);
+ GitVersion.Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
}
protected ExecuteCore ExecuteCore
{
get { return executeCore; }
}
+
+ public void LogDebug(string message)
+ {
+ this.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Low));
+ }
+
+ public void LogWarning(string message)
+ {
+ this.BuildEngine.LogWarningEvent(new BuildWarningEventArgs(string.Empty, string.Empty, null, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
+ }
+
+ public void LogInfo(string message)
+ {
+ this.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Normal));
+ }
+
+ public void LogError(string message, string file = null)
+ {
+ this.BuildEngine.LogErrorEvent(new BuildErrorEventArgs(string.Empty, string.Empty, file, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
+ }
}
}
\ No newline at end of file
diff --git a/src/GitVersionTask/TaskLogger.cs b/src/GitVersionTask/TaskLogger.cs
deleted file mode 100644
index ba33729ed8..0000000000
--- a/src/GitVersionTask/TaskLogger.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Microsoft.Build.Framework;
-
-class TaskLogger
-{
- ITask task;
-
- public TaskLogger(ITask task)
- {
- this.task = task;
- }
-
- public void LogWarning(string message)
- {
- task.BuildEngine.LogWarningEvent(new BuildWarningEventArgs(string.Empty, string.Empty, null, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
- }
-
- public void LogInfo(string message)
- {
- task.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Normal));
- }
-
- public void LogError(string message, string file = null)
- {
- task.BuildEngine.LogErrorEvent(new BuildErrorEventArgs(string.Empty, string.Empty, file, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
- }
-}
\ No newline at end of file
diff --git a/src/GitVersionTask/UpdateAssemblyInfo.cs b/src/GitVersionTask/UpdateAssemblyInfo.cs
index b8fe5daa67..125575022c 100644
--- a/src/GitVersionTask/UpdateAssemblyInfo.cs
+++ b/src/GitVersionTask/UpdateAssemblyInfo.cs
@@ -9,12 +9,8 @@ namespace GitVersionTask
public class UpdateAssemblyInfo : GitVersionTaskBase
{
- TaskLogger logger;
-
public UpdateAssemblyInfo()
{
- logger = new TaskLogger(this);
- Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
}
[Required]
@@ -46,12 +42,12 @@ public override bool Execute()
}
catch (WarningException errorException)
{
- logger.LogWarning(errorException.Message);
+ this.LogWarning(errorException.Message);
return true;
}
catch (Exception exception)
{
- logger.LogError("Error occurred: " + exception);
+ this.LogError("Error occurred: " + exception);
return false;
}
}
diff --git a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs b/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
index c11a96890f..b2412132a9 100644
--- a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
+++ b/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
@@ -7,12 +7,8 @@ namespace GitVersionTask
public class WriteVersionInfoToBuildLog : GitVersionTaskBase
{
- readonly TaskLogger logger;
-
public WriteVersionInfoToBuildLog()
{
- logger = new TaskLogger(this);
- Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
}
[Required]
@@ -29,12 +25,12 @@ public override bool Execute()
}
catch (WarningException errorException)
{
- logger.LogWarning(errorException.Message);
+ this.LogWarning(errorException.Message);
return true;
}
catch (Exception exception)
{
- logger.LogError("Error occurred: " + exception);
+ this.LogError("Error occurred: " + exception);
return false;
}
}
@@ -54,12 +50,12 @@ void WriteIntegrationParameters(IEnumerable applicableBuildServers
{
foreach (var buildServer in applicableBuildServers)
{
- logger.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name));
- logger.LogInfo(buildServer.GenerateSetVersionMessage(variables));
- logger.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name));
+ this.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name));
+ this.LogInfo(buildServer.GenerateSetVersionMessage(variables));
+ this.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name));
foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(buildServer, variables))
{
- logger.LogInfo(buildParameter);
+ this.LogInfo(buildParameter);
}
}
}
From 3b28212a117c8c51cd4f24b28f354afccc0ed2fc Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Sat, 23 Mar 2019 16:25:03 +0200
Subject: [PATCH 13/15] Resolving conflicts related to #1644 .
---
.../GetVersionTaskTests.cs | 10 +-
.../GitVersionTask.Tests.csproj | 1 -
.../InvalidFileCheckerTests.cs | 128 +++++++------
.../Mocks/MockBuildEngine.cs | 45 -----
.../Mocks/MockTaskItem.cs | 40 ----
.../GenerateGitVersionInformation.cs | 116 ++++++------
src/GitVersionTask/GetVersion.cs | 178 +++++++++---------
src/GitVersionTask/GitVersionTask.csproj | 5 +-
src/GitVersionTask/GitVersionTaskBase.cs | 81 +++++---
src/GitVersionTask/InvalidFileChecker.cs | 7 +-
.../NugetAssets/build/Infrastructure.props | 10 +-
.../functionality/GitVersionCommon.props | 40 ++--
src/GitVersionTask/TaskLogger.cs | 32 ++++
src/GitVersionTask/UpdateAssemblyInfo.cs | 130 +++++++------
src/GitVersionTask/UtilPack.Version.props | 2 +-
.../WriteVersionInfoToBuildLog.cs | 80 +++++---
16 files changed, 460 insertions(+), 445 deletions(-)
delete mode 100644 src/GitVersionTask.Tests/Mocks/MockBuildEngine.cs
delete mode 100644 src/GitVersionTask.Tests/Mocks/MockTaskItem.cs
create mode 100644 src/GitVersionTask/TaskLogger.cs
diff --git a/src/GitVersionTask.Tests/GetVersionTaskTests.cs b/src/GitVersionTask.Tests/GetVersionTaskTests.cs
index a3f6d5c7d1..bf2d995164 100644
--- a/src/GitVersionTask.Tests/GetVersionTaskTests.cs
+++ b/src/GitVersionTask.Tests/GetVersionTaskTests.cs
@@ -1,7 +1,6 @@
-using System.Linq;
+using System.Linq;
using GitVersion;
using GitVersionTask;
-using Microsoft.Build.Framework;
using NUnit.Framework;
using Shouldly;
@@ -11,13 +10,12 @@ public class GetVersionTaskTests : TestBase
[Test]
public void OutputsShouldMatchVariableProvider()
{
- var taskProperties = typeof(GetVersion)
+ var taskProperties = typeof( GetVersion.Output )
.GetProperties()
- .Where(p => p.GetCustomAttributes(typeof(OutputAttribute), false).Any())
- .Select(p => p.Name);
+ .Select( p => p.Name );
var variablesProperties = VersionVariables.AvailableVariables;
- taskProperties.ShouldBe(variablesProperties, ignoreOrder: true);
+ taskProperties.ShouldBe( variablesProperties, ignoreOrder: true );
}
}
diff --git a/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj b/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj
index 3c18824740..7a1a43f9d4 100644
--- a/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj
+++ b/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj
@@ -17,7 +17,6 @@
-
diff --git a/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs b/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
index e8877d2f94..6531d1b34a 100644
--- a/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
+++ b/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
@@ -1,8 +1,6 @@
using System;
using System.IO;
using GitVersion;
-using GitVersionTask.Tests.Mocks;
-using Microsoft.Build.Framework;
using NUnit.Framework;
[TestFixture]
@@ -14,93 +12,93 @@ public class InvalidFileCheckerTests : TestBase
[SetUp]
public void CreateTemporaryProject()
{
- projectDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- projectFile = Path.Combine(projectDirectory, "Fake.csproj");
+ projectDirectory = Path.Combine( Path.GetTempPath(), Guid.NewGuid().ToString() );
+ projectFile = Path.Combine( projectDirectory, "Fake.csproj" );
- Directory.CreateDirectory(projectDirectory);
+ Directory.CreateDirectory( projectDirectory );
- File.Create(projectFile).Close();
+ File.Create( projectFile ).Close();
}
[TearDown]
public void Cleanup()
{
- Directory.Delete(projectDirectory, true);
+ Directory.Delete( projectDirectory, true );
}
[Test]
public void VerifyIgnoreNonAssemblyInfoFile()
{
- using (var writer = File.CreateText(Path.Combine(projectDirectory, "SomeOtherFile.cs")))
+ using ( var writer = File.CreateText( Path.Combine( projectDirectory, "SomeOtherFile.cs" ) ) )
{
- writer.Write(@"
+ writer.Write( @"
using System;
using System.Reflection;
[assembly: AssemblyVersion(""1.0.0.0"")]
-");
+" );
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "SomeOtherFile.cs" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles( new[] { "SomeOtherFile.cs" }, projectFile );
}
[Test]
- public void VerifyAttributeFoundCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System.Reflection.AssemblyVersion")]string attribute)
+ public void VerifyAttributeFoundCSharp( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System.Reflection.AssemblyVersion" )]string attribute )
{
- using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.cs")))
+ using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.cs" ) ) )
{
- writer.Write(@"
+ writer.Write( @"
using System;
using System.Reflection;
[assembly:{0}(""1.0.0.0"")]
-", attribute);
+", attribute );
}
- var ex = Assert.Throws(() => InvalidFileChecker.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"));
+ var ex = Assert.Throws( () => InvalidFileChecker.CheckForInvalidFiles( new[] { "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" ) );
}
[Test]
- public void VerifyUnformattedAttributeFoundCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System . Reflection . AssemblyVersion")]string attribute)
+ public void VerifyUnformattedAttributeFoundCSharp( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System . Reflection . AssemblyVersion" )]string attribute )
{
- using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.cs")))
+ using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.cs" ) ) )
{
- writer.Write(@"
+ writer.Write( @"
using System;
using System.Reflection;
[ assembly :
{0} ( ""1.0.0.0"")]
-", attribute);
+", attribute );
}
- var ex = Assert.Throws(() => InvalidFileChecker.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"));
+ var ex = Assert.Throws( () => InvalidFileChecker.CheckForInvalidFiles( new[] { "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" ) );
}
[Test]
- public void VerifyCommentWorksCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
+ public void VerifyCommentWorksCSharp( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
- using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.cs")))
+ using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.cs" ) ) )
{
- writer.Write(@"
+ writer.Write( @"
using System;
using System.Reflection;
//[assembly: {0}(""1.0.0.0"")]
-", attribute);
+", attribute );
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.cs" }, projectFile );
}
[Test]
- public void VerifyStringWorksCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
+ public void VerifyStringWorksCSharp( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
- using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.cs")))
+ using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.cs" ) ) )
{
- writer.Write(@"
+ writer.Write( @"
using System;
using System.Reflection;
@@ -108,113 +106,113 @@ public class Temp
{{
static const string Foo = ""[assembly: {0}(""""1.0.0.0"""")]"";
}}
-", attribute);
+", attribute );
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.cs" }, projectFile );
}
[Test]
- public void VerifyIdentifierWorksCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
+ public void VerifyIdentifierWorksCSharp( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
- using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.cs")))
+ using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.cs" ) ) )
{
- writer.Write(@"
+ writer.Write( @"
using System;
using System.Reflection;
public class {0}
{{
}}
-", attribute);
+", attribute );
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.cs" }, projectFile );
}
[Test]
- public void VerifyAttributeFoundVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System.Reflection.AssemblyVersion")]string attribute)
+ public void VerifyAttributeFoundVisualBasic( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System.Reflection.AssemblyVersion" )]string attribute )
{
- using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.vb")))
+ using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.vb" ) ) )
{
- writer.Write(@"
+ writer.Write( @"
Imports System
Imports System.Reflection
-", attribute);
+", attribute );
}
- var ex = Assert.Throws(() => InvalidFileChecker.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"));
+ var ex = Assert.Throws( () => InvalidFileChecker.CheckForInvalidFiles( new[] { "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" ) );
}
[Test]
- public void VerifyUnformattedAttributeFoundVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System . Reflection . AssemblyVersion")]string attribute)
+ public void VerifyUnformattedAttributeFoundVisualBasic( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System . Reflection . AssemblyVersion" )]string attribute )
{
- using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.vb")))
+ using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.vb" ) ) )
{
- writer.Write(@"
+ writer.Write( @"
Imports System
Imports System.Reflection
< Assembly :
{0} ( ""1.0.0.0"")>
-", attribute);
+", attribute );
}
- var ex = Assert.Throws(() => InvalidFileChecker.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"));
+ var ex = Assert.Throws( () => InvalidFileChecker.CheckForInvalidFiles( new[] { "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" ) );
}
[Test]
- public void VerifyCommentWorksVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
+ public void VerifyCommentWorksVisualBasic( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
- using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.vb")))
+ using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.vb" ) ) )
{
- writer.Write(@"
+ writer.Write( @"
Imports System
Imports System.Reflection
'
-", attribute);
+", attribute );
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.vb" }, projectFile );
}
[Test]
- public void VerifyStringWorksVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
+ public void VerifyStringWorksVisualBasic( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
- using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.vb")))
+ using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.vb" ) ) )
{
- writer.Write(@"
+ writer.Write( @"
Imports System
Imports System.Reflection
Public Class Temp
static const string Foo = """";
End Class
-", attribute);
+", attribute );
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.vb" }, projectFile );
}
[Test]
- public void VerifyIdentifierWorksVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
+ public void VerifyIdentifierWorksVisualBasic( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
- using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.vb")))
+ using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.vb" ) ) )
{
- writer.Write(@"
+ writer.Write( @"
Imports System
Imports System.Reflection
Public Class {0}
End Class
-", attribute);
+", attribute );
}
- InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
+ InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.vb" }, projectFile );
}
}
diff --git a/src/GitVersionTask.Tests/Mocks/MockBuildEngine.cs b/src/GitVersionTask.Tests/Mocks/MockBuildEngine.cs
deleted file mode 100644
index 710462eff5..0000000000
--- a/src/GitVersionTask.Tests/Mocks/MockBuildEngine.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System;
-using System.Collections;
-using Microsoft.Build.Framework;
-
-class MockBuildEngine : IBuildEngine
-{
- public void LogErrorEvent(BuildErrorEventArgs e)
- { }
-
- public void LogWarningEvent(BuildWarningEventArgs e)
- { }
-
- public void LogMessageEvent(BuildMessageEventArgs e)
- { }
-
- public void LogCustomEvent(CustomBuildEventArgs e)
- {
- throw new NotImplementedException();
- }
-
- public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs)
- {
- throw new NotImplementedException();
- }
-
- public bool ContinueOnError
- {
- get { throw new NotImplementedException(); }
- }
-
- public int LineNumberOfTaskNode
- {
- get { throw new NotImplementedException(); }
- }
-
- public int ColumnNumberOfTaskNode
- {
- get { throw new NotImplementedException(); }
- }
-
- public string ProjectFileOfTaskNode
- {
- get { throw new NotImplementedException(); }
- }
-}
\ No newline at end of file
diff --git a/src/GitVersionTask.Tests/Mocks/MockTaskItem.cs b/src/GitVersionTask.Tests/Mocks/MockTaskItem.cs
deleted file mode 100644
index 45a98850b9..0000000000
--- a/src/GitVersionTask.Tests/Mocks/MockTaskItem.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-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/GenerateGitVersionInformation.cs b/src/GitVersionTask/GenerateGitVersionInformation.cs
index 2e37e3975f..c002731c5a 100644
--- a/src/GitVersionTask/GenerateGitVersionInformation.cs
+++ b/src/GitVersionTask/GenerateGitVersionInformation.cs
@@ -4,90 +4,96 @@ namespace GitVersionTask
using System.IO;
using GitVersion;
using GitVersion.Helpers;
- using Microsoft.Build.Framework;
- public class GenerateGitVersionInformation : GitVersionTaskBase
+ public static class GenerateGitVersionInformation
{
- public GenerateGitVersionInformation()
+ public static Output Execute(
+ Input input
+ )
{
- }
-
- [Required]
- public string SolutionDirectory { get; set; }
-
- [Required]
- public string ProjectFile { get; set; }
-
- [Required]
- public string IntermediateOutputPath { get; set; }
-
- [Required]
- public string Language { get; set; }
-
- [Output]
- public string GitVersionInformationFilePath { get; set; }
+ if ( !input.ValidateInput() )
+ {
+ throw new Exception( "Invalid input." );
+ }
- public bool NoFetch { get; set; }
+ var logger = new TaskLogger();
+ Logger.SetLoggers( logger.LogInfo, logger.LogInfo, logger.LogWarning, s => logger.LogError( s ) );
+
- public override bool Execute()
- {
+ Output output = null;
try
{
- InnerExecute();
- return true;
+ output = InnerExecute(input );
}
catch (WarningException errorException)
{
- this.LogWarning(errorException.Message);
- return true;
+ logger.LogWarning(errorException.Message);
+ output = new Output();
}
catch (Exception exception)
{
- this.LogError("Error occurred: " + exception);
- return false;
+ logger.LogError("Error occurred: " + exception);
+ throw;
}
- }
-
- void InnerExecute()
- {
- VersionVariables versionVariables;
- if (!ExecuteCore.TryGetVersion(SolutionDirectory, out versionVariables, NoFetch, new Authentication()))
+ finally
{
- return;
+ Logger.Reset();
}
- var fileExtension = GetFileExtension();
- var fileName = $"GitVersionInformation.g.{fileExtension}";
+ return output;
+ }
- if (IntermediateOutputPath == null)
+ private static Output InnerExecute( Input input )
+ {
+ var execute = GitVersionTaskBase.CreateExecuteCore();
+ if (!execute.TryGetVersion(input.SolutionDirectory, out var versionVariables, input.NoFetch, new Authentication()))
{
- fileName = $"GitVersionInformation_{Path.GetFileNameWithoutExtension(ProjectFile)}_{Path.GetRandomFileName()}.g.{fileExtension}";
+ return null;
}
- var workingDirectory = IntermediateOutputPath ?? TempFileTracker.TempPath;
-
- GitVersionInformationFilePath = Path.Combine(workingDirectory, fileName);
+ var fileWriteInfo = input.IntermediateOutputPath.GetWorkingDirectoryAndFileNameAndExtension(
+ input.Language,
+ input.ProjectFile,
+ ( pf, ext ) => $"GitVersionInformation.g.{ext}",
+ ( pf, ext ) => $"GitVersionInformation_{Path.GetFileNameWithoutExtension( pf )}_{Path.GetRandomFileName()}.g.{ext}"
+ );
- var generator = new GitVersionInformationGenerator(fileName, workingDirectory, versionVariables, new FileSystem());
+ 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;
}
- string GetFileExtension()
+ public sealed class Input
{
- switch (Language)
- {
- case "C#":
- return "cs";
+ public string SolutionDirectory { get; set; }
- case "F#":
- return "fs";
+ public string ProjectFile { get; set; }
- case "VB":
- return "vb";
+ public string IntermediateOutputPath { get; set; }
- default:
- throw new Exception($"Unknown language detected: '{Language}'");
- }
+ public string Language { get; set; }
+
+ public bool NoFetch { get; set; }
+ }
+
+ private static Boolean ValidateInput( this Input input )
+ {
+ return input != null
+ && !String.IsNullOrEmpty( input.SolutionDirectory )
+ && !String.IsNullOrEmpty(input.ProjectFile)
+ // && !String.IsNullOrEmpty(input.IntermediateOutputPath) // This was marked as [Required] but it InnerExecute still seems to allow it to be null... ?
+ && !String.IsNullOrEmpty(input.Language)
+ ;
+ }
+
+ public sealed class Output
+ {
+ public string GitVersionInformationFilePath { get; set; }
}
}
}
diff --git a/src/GitVersionTask/GetVersion.cs b/src/GitVersionTask/GetVersion.cs
index 07f8be237f..d184204901 100644
--- a/src/GitVersionTask/GetVersion.cs
+++ b/src/GitVersionTask/GetVersion.cs
@@ -3,135 +3,127 @@ namespace GitVersionTask
using System;
using GitVersion;
- using Microsoft.Build.Framework;
-
- public class GetVersion : GitVersionTaskBase
+ public static class GetVersion
{
- public GetVersion()
+ public static Output Execute(
+ Input input
+ )
{
- }
+ if (!input.ValidateInput())
+ {
+ throw new Exception( "Invalid input." );
+ }
+
+ var logger = new TaskLogger();
+ Logger.SetLoggers( logger.LogInfo, logger.LogInfo, logger.LogWarning, s => logger.LogError( s ) );
+ var execute = GitVersionTaskBase.CreateExecuteCore();
+
+ Output output = null;
+ try
+ {
+ if ( execute.TryGetVersion(input.SolutionDirectory, out var variables, input.NoFetch, new Authentication()))
+ {
+ var outputType = typeof( Output );
+ output = new Output();
+ foreach (var variable in variables)
+ {
+ outputType.GetProperty(variable.Key).SetValue( output, variable.Value, null);
+ }
+ }
+ }
+ catch (WarningException errorException)
+ {
+ logger.LogWarning(errorException.Message);
+ output = new Output();
+ }
+ catch (Exception exception)
+ {
+ logger.LogError("Error occurred: " + exception);
+ throw;
+ }
+ finally
+ {
+ Logger.Reset();
+ }
- [Required]
- public string SolutionDirectory { get; set; }
+ return output;
+ }
- public bool NoFetch { get; set; }
+ public sealed class Input
+ {
+ public string SolutionDirectory { get; set; }
- [Output]
- public string Major { get; set; }
+ public bool NoFetch { get; set; }
+ }
- [Output]
- public string Minor { get; set; }
+ private static Boolean ValidateInput(this Input input)
+ {
+ return !String.IsNullOrEmpty( input?.SolutionDirectory );
+ }
- [Output]
- public string Patch { get; set; }
+ public sealed class Output
+ {
+ public string Major { get; set; }
- [Output]
- public string PreReleaseTag { get; set; }
+ public string Minor { get; set; }
- [Output]
- public string PreReleaseTagWithDash { get; set; }
+ public string Patch { get; set; }
- [Output]
- public string PreReleaseLabel { get; set; }
+ public string PreReleaseTag { get; set; }
- [Output]
- public string PreReleaseNumber { get; set; }
+ public string PreReleaseTagWithDash { get; set; }
- [Output]
- public string WeightedPreReleaseNumber { get; set; }
+ public string PreReleaseLabel { get; set; }
- [Output]
- public string BuildMetaData { get; set; }
+ public string PreReleaseNumber { get; set; }
- [Output]
- public string BuildMetaDataPadded { get; set; }
+ public string WeightedPreReleaseNumber { get; set; }
- [Output]
- public string FullBuildMetaData { get; set; }
+ public string BuildMetaData { get; set; }
- [Output]
- public string MajorMinorPatch { get; set; }
+ public string BuildMetaDataPadded { get; set; }
- [Output]
- public string SemVer { get; set; }
+ public string FullBuildMetaData { get; set; }
- [Output]
- public string LegacySemVer { get; set; }
+ public string MajorMinorPatch { get; set; }
- [Output]
- public string LegacySemVerPadded { get; set; }
+ public string SemVer { get; set; }
- [Output]
- public string AssemblySemVer { get; set; }
+ public string LegacySemVer { get; set; }
- [Output]
- public string AssemblySemFileVer { get; set; }
+ public string LegacySemVerPadded { get; set; }
- [Output]
- public string FullSemVer { get; set; }
+ public string AssemblySemVer { get; set; }
- [Output]
- public string InformationalVersion { get; set; }
+ public string AssemblySemFileVer { get; set; }
- [Output]
- public string BranchName { get; set; }
+ public string FullSemVer { get; set; }
- [Output]
- public string Sha { get; set; }
+ public string InformationalVersion { get; set; }
- [Output]
- public string ShortSha { get; set; }
+ public string BranchName { get; set; }
- [Output]
- public string NuGetVersionV2 { get; set; }
+ public string Sha { get; set; }
- [Output]
- public string NuGetVersion { get; set; }
+ public string ShortSha { get; set; }
- [Output]
- public string NuGetPreReleaseTagV2 { get; set; }
+ public string NuGetVersionV2 { get; set; }
- [Output]
- public string NuGetPreReleaseTag { get; set; }
+ public string VersionSourceSha { get; set; }
- [Output]
- public string CommitDate { get; set; }
+ public string CommitsSinceVersionSource { get; set; }
- [Output]
- public string VersionSourceSha { get; set; }
+ public string NuGetVersion { get; set; }
- [Output]
- public string CommitsSinceVersionSource { get; set; }
+ public string NuGetPreReleaseTagV2 { get; set; }
- [Output]
- public string CommitsSinceVersionSourcePadded { get; set; }
+ public string NuGetPreReleaseTag { get; set; }
- public override bool Execute()
- {
- try
- {
- VersionVariables variables;
+ public string CommitDate { get; set; }
- if (ExecuteCore.TryGetVersion(SolutionDirectory, out variables, NoFetch, new Authentication()))
- {
- var thisType = typeof(GetVersion);
- foreach (var variable in variables)
- {
- thisType.GetProperty(variable.Key).SetValue(this, variable.Value, null);
- }
- }
- return true;
- }
- catch (WarningException errorException)
- {
- this.LogWarning(errorException.Message);
- return true;
- }
- catch (Exception exception)
- {
- this.LogError("Error occurred: " + exception);
- return false;
- }
+ public string CommitsSinceVersionSourcePadded { get; set; }
}
}
+
+
}
diff --git a/src/GitVersionTask/GitVersionTask.csproj b/src/GitVersionTask/GitVersionTask.csproj
index 39f6ddf96e..62265f9bf8 100644
--- a/src/GitVersionTask/GitVersionTask.csproj
+++ b/src/GitVersionTask/GitVersionTask.csproj
@@ -20,6 +20,7 @@
version=$(PackageVersion);configuration=$(Configuration);utilpackversion=$(PackageVersion_UtilPackNuGetMSBuild);libgit2sharpversion=$(PackageVersion_LibGit2Sharp);yamldotnetversion=$(PackageVersion_YamlDotNet)
$(AssemblyName)
+ latest
@@ -37,9 +38,7 @@
All
-
-
-
+
all
runtime; build; native; contentfiles; analyzers
diff --git a/src/GitVersionTask/GitVersionTaskBase.cs b/src/GitVersionTask/GitVersionTaskBase.cs
index caeb254ed2..45aa95ce68 100644
--- a/src/GitVersionTask/GitVersionTaskBase.cs
+++ b/src/GitVersionTask/GitVersionTaskBase.cs
@@ -1,45 +1,72 @@
-namespace GitVersionTask
+namespace GitVersionTask
{
using GitVersion;
using GitVersion.Helpers;
+ using System;
+ using System.IO;
- using Microsoft.Build.Framework;
- using Microsoft.Build.Utilities;
-
- public abstract class GitVersionTaskBase : Task
+ public static class GitVersionTaskBase
{
- readonly ExecuteCore executeCore;
+ public static ExecuteCore CreateExecuteCore()
+ => new ExecuteCore( new FileSystem() );
- protected GitVersionTaskBase()
+ private static string GetFileExtension( this String language )
{
- var fileSystem = new FileSystem();
- executeCore = new ExecuteCore(fileSystem);
- GitVersion.Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
- }
+ switch ( language )
+ {
+ case "C#":
+ return "cs";
- protected ExecuteCore ExecuteCore
- {
- get { return executeCore; }
- }
+ case "F#":
+ return "fs";
- public void LogDebug(string message)
- {
- this.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Low));
- }
+ case "VB":
+ return "vb";
- public void LogWarning(string message)
- {
- this.BuildEngine.LogWarningEvent(new BuildWarningEventArgs(string.Empty, string.Empty, null, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
+ default:
+ throw new Exception( $"Unknown language detected: '{language}'" );
+ }
}
- public void LogInfo(string message)
+ public static FileWriteInfo GetWorkingDirectoryAndFileNameAndExtension(
+ this String intermediateOutputPath,
+ String language,
+ String projectFile,
+ Func fileNameWithIntermediatePath,
+ Func fileNameNoIntermediatePath
+ )
{
- this.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Normal));
+ var fileExtension = language.GetFileExtension();
+ String workingDirectory, fileName;
+ if ( intermediateOutputPath == null )
+ {
+ fileName = fileNameWithIntermediatePath(projectFile, fileExtension);
+ workingDirectory = TempFileTracker.TempPath;
+ }
+ else
+ {
+ workingDirectory = intermediateOutputPath;
+ fileName = fileNameNoIntermediatePath(projectFile, fileExtension);
+ }
+ return new FileWriteInfo(workingDirectory, fileName, fileExtension);
}
+ }
- public void LogError(string message, string file = null)
+ public sealed class FileWriteInfo
+ {
+ public FileWriteInfo(
+ String workingDirectory,
+ String fileName,
+ String fileExtension
+ )
{
- this.BuildEngine.LogErrorEvent(new BuildErrorEventArgs(string.Empty, string.Empty, file, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
+ this.WorkingDirectory = this.WorkingDirectory;
+ this.FileName = fileName;
+ this.FileExtension = fileExtension;
}
+
+ public String WorkingDirectory { get; }
+ public String FileName { get; }
+ public String FileExtension { get; }
}
-}
\ No newline at end of file
+}
diff --git a/src/GitVersionTask/InvalidFileChecker.cs b/src/GitVersionTask/InvalidFileChecker.cs
index d20be03e56..8cc308fddb 100644
--- a/src/GitVersionTask/InvalidFileChecker.cs
+++ b/src/GitVersionTask/InvalidFileChecker.cs
@@ -4,7 +4,6 @@
using System.Linq;
using System.Text.RegularExpressions;
using GitVersion;
-using Microsoft.Build.Framework;
public static class InvalidFileChecker
{
@@ -14,7 +13,7 @@ public static class InvalidFileChecker
{ ".vb", VisualBasicFileContainsVersionAttribute }
};
- public static void CheckForInvalidFiles(IEnumerable compileFiles, string projectFile)
+ public static void CheckForInvalidFiles(IEnumerable compileFiles, string projectFile)
{
foreach (var compileFile in GetInvalidFiles(compileFiles, projectFile))
{
@@ -98,9 +97,9 @@ static bool VisualBasicFileContainsVersionAttribute(string compileFile, string p
\s*\(\s*\)\s*\> # End brackets ()>");
}
- static IEnumerable GetInvalidFiles(IEnumerable compileFiles, string projectFile)
+ static IEnumerable GetInvalidFiles(IEnumerable compileFiles, string projectFile)
{
- return compileFiles.Select(x => x.ItemSpec)
+ return compileFiles
.Where(compileFile => compileFile.Contains("AssemblyInfo"))
.Where(s => FileContainsVersionAttribute(s, projectFile));
}
diff --git a/src/GitVersionTask/NugetAssets/build/Infrastructure.props b/src/GitVersionTask/NugetAssets/build/Infrastructure.props
index e5ff8092e1..93d9083b49 100644
--- a/src/GitVersionTask/NugetAssets/build/Infrastructure.props
+++ b/src/GitVersionTask/NugetAssets/build/Infrastructure.props
@@ -1,4 +1,4 @@
-
+
@@ -9,16 +9,16 @@
$(GitVersionTaskBuildTools_FunctionalityDir)obj/
-
+
$(PackageVersion_UtilPackNuGetMSBuild)
- $(MSBuildThisFileDirectory)../../../utilpack.nuget.msbuild/$(UtilPackVersion)/build/UtilPack.NuGet.MSBuild.props
+ $(MSBuildThisFileDirectory)../../../nugetutils.msbuild.exec/$(UtilPackVersion)/build/NuGetUtils.MSBuild.Exec.props
$([System.IO.Path]::GetFullPath('$(UtilPackNuGetMSBuildPropsPath)'))
- true
+ true
@@ -35,7 +35,7 @@
-
+
diff --git a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props b/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
index 36b320e5a5..783dfcc277 100644
--- a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
+++ b/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
@@ -1,4 +1,4 @@
-
+
$(MSBuildProjectDirectory)\..\
@@ -40,43 +40,55 @@
- $(UtilPackTaskFactoryParametersXML)
+
+ $(UtilPackTaskFactoryParametersXML)
+ Execute
+
- $(UtilPackTaskFactoryParametersXML)
+
+ $(UtilPackTaskFactoryParametersXML)
+ Execute
+
- $(UtilPackTaskFactoryParametersXML)
+
+ $(UtilPackTaskFactoryParametersXML)
+ Execute
+
- $(UtilPackTaskFactoryParametersXML)
+
+ $(UtilPackTaskFactoryParametersXML)
+ Execute
+
True
-
\ No newline at end of file
+
diff --git a/src/GitVersionTask/TaskLogger.cs b/src/GitVersionTask/TaskLogger.cs
new file mode 100644
index 0000000000..baa46b9b09
--- /dev/null
+++ b/src/GitVersionTask/TaskLogger.cs
@@ -0,0 +1,32 @@
+using System;
+using System.IO;
+
+class TaskLogger
+{
+ private readonly TextWriter stdout;
+ private readonly TextWriter stderr;
+
+ public TaskLogger(
+ TextWriter paramStdout = null,
+ TextWriter paramStderr = null
+ )
+ {
+ this.stdout = paramStdout ?? Console.Out;
+ this.stderr = paramStderr ?? Console.Error;
+ }
+
+ public void LogWarning(string message)
+ {
+ this.stdout.WriteLine( message );
+ }
+
+ public void LogInfo(string message)
+ {
+ this.stdout.WriteLine( message );
+ }
+
+ public void LogError(string message)
+ {
+ this.stderr.WriteLine( message );
+ }
+}
diff --git a/src/GitVersionTask/UpdateAssemblyInfo.cs b/src/GitVersionTask/UpdateAssemblyInfo.cs
index 125575022c..fd3fdafe12 100644
--- a/src/GitVersionTask/UpdateAssemblyInfo.cs
+++ b/src/GitVersionTask/UpdateAssemblyInfo.cs
@@ -5,105 +5,113 @@ namespace GitVersionTask
using GitVersion;
using GitVersion.Helpers;
- using Microsoft.Build.Framework;
- public class UpdateAssemblyInfo : GitVersionTaskBase
+ public static class UpdateAssemblyInfo
{
- public UpdateAssemblyInfo()
- {
- }
-
- [Required]
- public string SolutionDirectory { get; set; }
-
- [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 static Output Execute(
+ Input input
+ )
+ {
+ if ( !input.ValidateInput() )
+ {
+ throw new Exception( "Invalid input." );
+ }
- public bool NoFetch { get; set; }
+ var logger = new TaskLogger();
+ Logger.SetLoggers( logger.LogInfo, logger.LogInfo, logger.LogWarning, s => logger.LogError( s ) );
- public override bool Execute()
- {
+ Output output = null;
try
{
- InnerExecute();
- return true;
+ output = InnerExecute( input );
}
catch (WarningException errorException)
{
- this.LogWarning(errorException.Message);
- return true;
+ logger.LogWarning(errorException.Message);
+ output = new Output();
}
catch (Exception exception)
{
- this.LogError("Error occurred: " + exception);
- return false;
+ logger.LogError("Error occurred: " + exception);
+ throw;
}
+ finally
+ {
+ Logger.Reset();
+ }
+
+ return output;
}
- void InnerExecute()
+ private static Output InnerExecute( Input input )
{
+ var execute = GitVersionTaskBase.CreateExecuteCore();
+
TempFileTracker.DeleteTempFiles();
- InvalidFileChecker.CheckForInvalidFiles(CompileFiles, ProjectFile);
+ InvalidFileChecker.CheckForInvalidFiles(input.CompileFiles, input.ProjectFile);
- VersionVariables versionVariables;
- if (!ExecuteCore.TryGetVersion(SolutionDirectory, out versionVariables, NoFetch, new Authentication()))
+ if (!execute.TryGetVersion( input.SolutionDirectory, out var versionVariables, input.NoFetch, new Authentication()))
{
- return;
+ return null;
}
- CreateTempAssemblyInfo(versionVariables);
+ return CreateTempAssemblyInfo(input, versionVariables);
}
- void CreateTempAssemblyInfo(VersionVariables versionVariables)
+ private static Output CreateTempAssemblyInfo( Input input, VersionVariables versionVariables)
{
- var fileExtension = GetFileExtension();
- var assemblyInfoFileName = $"GitVersionTaskAssemblyInfo.g.{fileExtension}";
-
- if (IntermediateOutputPath == null)
+ var fileWriteInfo = input.IntermediateOutputPath.GetWorkingDirectoryAndFileNameAndExtension(
+ input.Language,
+ input.ProjectFile,
+ ( pf, ext ) => $"GitVersionTaskAssemblyInfo.g.{ext}",
+ ( pf, ext ) => $"AssemblyInfo_{Path.GetFileNameWithoutExtension( pf )}_{Path.GetRandomFileName()}.g.{ext}"
+ );
+
+ var output = new Output()
{
- assemblyInfoFileName = $"AssemblyInfo_{Path.GetFileNameWithoutExtension(ProjectFile)}_{Path.GetRandomFileName()}.g.{fileExtension}";
- }
-
- var workingDirectory = IntermediateOutputPath ?? TempFileTracker.TempPath;
-
- AssemblyInfoTempFilePath = Path.Combine(workingDirectory, assemblyInfoFileName);
+ AssemblyInfoTempFilePath = Path.Combine( fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName )
+ };
- using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFileName, workingDirectory, versionVariables, new FileSystem(), true))
+ using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater( fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem(), true))
{
assemblyInfoFileUpdater.Update();
assemblyInfoFileUpdater.CommitChanges();
}
+
+ return output;
}
- string GetFileExtension()
+ public sealed class Input
{
- switch(Language)
- {
- case "C#":
- return "cs";
+ public string SolutionDirectory { get; set; }
- case "F#":
- return "fs";
+ public string ProjectFile { get; set; }
- case "VB":
- return "vb";
+ public string IntermediateOutputPath { get; set; }
- default:
- throw new Exception($"Unknown language detected: '{Language}'");
- }
+ public String[] CompileFiles { get; set; }
+
+ public string Language { get; set; }
+
+ public bool NoFetch { get; set; }
+ }
+
+ private static Boolean ValidateInput(this Input input)
+ {
+ return input != null
+ && !String.IsNullOrEmpty( input.SolutionDirectory )
+ && !String.IsNullOrEmpty( input.ProjectFile )
+ && !String.IsNullOrEmpty( input.IntermediateOutputPath )
+ && input.CompileFiles != null
+ && !String.IsNullOrEmpty( input.Language )
+ ;
+ }
+
+ public sealed class Output
+ {
+ public string AssemblyInfoTempFilePath { get; set; }
}
}
}
diff --git a/src/GitVersionTask/UtilPack.Version.props b/src/GitVersionTask/UtilPack.Version.props
index 109fbf9d1e..42fd789c7e 100644
--- a/src/GitVersionTask/UtilPack.Version.props
+++ b/src/GitVersionTask/UtilPack.Version.props
@@ -1,6 +1,6 @@
- 2.9.1
+ 2.0.0
diff --git a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs b/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
index b2412132a9..777dca7192 100644
--- a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
+++ b/src/GitVersionTask/WriteVersionInfoToBuildLog.cs
@@ -3,61 +3,91 @@ namespace GitVersionTask
using System;
using System.Collections.Generic;
using GitVersion;
- using Microsoft.Build.Framework;
- public class WriteVersionInfoToBuildLog : GitVersionTaskBase
+ public static class WriteVersionInfoToBuildLog
{
- public WriteVersionInfoToBuildLog()
+
+ public static Output Execute(
+ Input input
+ )
{
- }
+ if ( !input.ValidateInput() )
+ {
+ throw new Exception( "Invalid input." );
+ }
- [Required]
- public string SolutionDirectory { get; set; }
+ var logger = new TaskLogger();
+ Logger.SetLoggers( logger.LogInfo, logger.LogInfo, logger.LogWarning, s => logger.LogError( s ) );
- public bool NoFetch { get; set; }
- public override bool Execute()
- {
+ Output output = null;
try
{
- InnerExecute();
- return true;
+ output = InnerExecute(logger, input);
}
catch (WarningException errorException)
{
- this.LogWarning(errorException.Message);
- return true;
+ logger.LogWarning(errorException.Message);
+ output = new Output();
}
catch (Exception exception)
{
- this.LogError("Error occurred: " + exception);
- return false;
+ logger.LogError("Error occurred: " + exception);
+ throw;
}
+ finally
+ {
+ Logger.Reset();
+ }
+
+ return output;
}
- void InnerExecute()
+ private static Output InnerExecute(
+ TaskLogger logger,
+ Input input
+ )
{
- VersionVariables result;
- if (!ExecuteCore.TryGetVersion(SolutionDirectory, out result, NoFetch, new Authentication()))
+ var execute = GitVersionTaskBase.CreateExecuteCore();
+ if (!execute.TryGetVersion(input.SolutionDirectory, out var result, input.NoFetch, new Authentication()))
{
- return;
+ return null;
}
- WriteIntegrationParameters(BuildServerList.GetApplicableBuildServers(), result);
+ WriteIntegrationParameters(logger, BuildServerList.GetApplicableBuildServers(), result);
+
+ return new Output();
}
- void WriteIntegrationParameters(IEnumerable applicableBuildServers, VersionVariables variables)
+ private static void WriteIntegrationParameters(TaskLogger logger, IEnumerable applicableBuildServers, VersionVariables variables)
{
foreach (var buildServer in applicableBuildServers)
{
- this.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name));
- this.LogInfo(buildServer.GenerateSetVersionMessage(variables));
- this.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name));
+ logger.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name));
+ logger.LogInfo(buildServer.GenerateSetVersionMessage(variables));
+ logger.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name));
foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(buildServer, variables))
{
- this.LogInfo(buildParameter);
+ logger.LogInfo(buildParameter);
}
}
}
+
+ public sealed class Input
+ {
+ public string SolutionDirectory { get; set; }
+
+ public bool NoFetch { get; set; }
+ }
+
+ public static Boolean ValidateInput(this Input input)
+ {
+ return !String.IsNullOrEmpty( input?.SolutionDirectory );
+ }
+
+ public sealed class Output
+ {
+ // No output for this task
+ }
}
}
From 8898886c699a29a24423a940487f455f8dc58966 Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Wed, 27 Mar 2019 17:50:21 +0200
Subject: [PATCH 14/15] Resolving last conflicts
---
.../NugetAssets/build/Infrastructure.props | 8 --------
.../build/functionality/GitVersionCommon.props | 16 ----------------
2 files changed, 24 deletions(-)
diff --git a/src/GitVersionTask/NugetAssets/build/Infrastructure.props b/src/GitVersionTask/NugetAssets/build/Infrastructure.props
index 70054988ab..4ef57bf76a 100644
--- a/src/GitVersionTask/NugetAssets/build/Infrastructure.props
+++ b/src/GitVersionTask/NugetAssets/build/Infrastructure.props
@@ -1,9 +1,5 @@
-<<<<<<< HEAD
-
-=======
->>>>>>> 854f16b6753d84214c78af52224f90500da7ac11
@@ -14,11 +10,7 @@
-<<<<<<< HEAD
- $(PackageVersion_UtilPackNuGetMSBuild)
-=======
$(PackageVersion_NuGetUtilsMSBuildExec)
->>>>>>> 854f16b6753d84214c78af52224f90500da7ac11
$(MSBuildThisFileDirectory)../../../nugetutils.msbuild.exec/$(UtilPackVersion)/build/NuGetUtils.MSBuild.Exec.props
$([System.IO.Path]::GetFullPath('$(UtilPackNuGetMSBuildPropsPath)'))
diff --git a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props b/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
index 8cbd36b70b..5e868860fb 100644
--- a/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
+++ b/src/GitVersionTask/NugetAssets/build/functionality/GitVersionCommon.props
@@ -41,11 +41,7 @@
>>>>>> 854f16b6753d84214c78af52224f90500da7ac11
AssemblyFile="$(NuGetUtilsMSBuildExecAssemblyPath)"
TaskName="GitVersionTask.UpdateAssemblyInfo">
@@ -57,11 +53,7 @@
>>>>>> 854f16b6753d84214c78af52224f90500da7ac11
AssemblyFile="$(NuGetUtilsMSBuildExecAssemblyPath)"
TaskName="GitVersionTask.GenerateGitVersionInformation">
@@ -73,11 +65,7 @@
>>>>>> 854f16b6753d84214c78af52224f90500da7ac11
AssemblyFile="$(NuGetUtilsMSBuildExecAssemblyPath)"
TaskName="GitVersionTask.GetVersion">
@@ -89,11 +77,7 @@
>>>>>> 854f16b6753d84214c78af52224f90500da7ac11
AssemblyFile="$(NuGetUtilsMSBuildExecAssemblyPath)"
TaskName="GitVersionTask.WriteVersionInfoToBuildLog">
From 6f64c34966d54ab38cf8d0e6aa3d94f72c2b6efc Mon Sep 17 00:00:00 2001
From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com>
Date: Wed, 27 Mar 2019 23:41:18 +0200
Subject: [PATCH 15/15] Updated the NuGetUtils.MSBuild.Exec version to newer,
with most recent fixes.
---
src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props b/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props
index 40d39c08a1..a00890c752 100644
--- a/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props
+++ b/src/GitVersionTask/NuGetUtils.MSBuild.Exec.Version.props
@@ -1,6 +1,6 @@
- 2.0.4
+ 2.0.5