diff --git a/src/Cake.GitVersioning/Cake.GitVersioning.csproj b/src/Cake.GitVersioning/Cake.GitVersioning.csproj index e8c9befc..331d6222 100644 --- a/src/Cake.GitVersioning/Cake.GitVersioning.csproj +++ b/src/Cake.GitVersioning/Cake.GitVersioning.csproj @@ -13,9 +13,10 @@ cake-contrib-medium.png http://github.com/dotnet/Nerdbank.GitVersioning false - - false + $(TargetsForTfmSpecificContentInPackage);PackBuildOutputs + $(NuGetPackageRoot)libgit2sharp.nativebinaries\$(LibGit2SharpNativeVersion)\ + true @@ -36,6 +37,15 @@ + + + + + + + + + @@ -44,9 +54,21 @@ - - lib\$(TargetFramework)\ + + lib\$(TargetFramework) - + \ No newline at end of file diff --git a/src/Cake.GitVersioning/GitVersioningAliases.cs b/src/Cake.GitVersioning/GitVersioningAliases.cs index d1187897..b7e8a3b2 100644 --- a/src/Cake.GitVersioning/GitVersioningAliases.cs +++ b/src/Cake.GitVersioning/GitVersioningAliases.cs @@ -6,6 +6,11 @@ namespace Cake.GitVersioning { + using System; + using System.Linq; + + using Validation; + /// /// Contains functionality for using Nerdbank.GitVersioning. /// @@ -30,7 +35,35 @@ public static VersionOracle GitVersioningGetVersion(this ICakeContext context, s { var fullProjectDirectory = (new DirectoryInfo(projectDirectory)).FullName; - GitExtensions.HelpFindLibGit2NativeBinaries(Path.GetDirectoryName(Assembly.GetAssembly(typeof(GitVersioningAliases)).Location)); + string directoryName = Path.GetDirectoryName(Assembly.GetAssembly(typeof(GitVersioningAliases)).Location); + + if (string.IsNullOrWhiteSpace(directoryName)) + { + throw new InvalidOperationException("Could not locate the Cake.GitVersioning library"); + } + + // Even after adding the folder containing the native libgit2 DLL to the PATH, DllNotFoundException is still thrown + // Workaround this by copying the contents of the found folder to the current directory + GitExtensions.HelpFindLibGit2NativeBinaries(directoryName, out var attemptedDirectory); + + // The HelpFindLibGit2NativeBinaries method throws if the directory does not exist + var directoryInfo = new DirectoryInfo(attemptedDirectory); + + // There should only be a single file in the directory, but we do not know its extension + // So, we will just get a list of all files rather than trying to determine the correct name and extension + // If there are other files there for some reason, it should not matter as long as we don't overwrite anything in the current directory + var fileInfos = directoryInfo.GetFiles(); + + foreach (var fileInfo in fileInfos) + { + // Copy the file to the Cake.GitVersioning DLL directory, without overwriting anything + string destFileName = Path.Combine(directoryName, fileInfo.Name); + + if (!File.Exists(destFileName)) + { + File.Copy(fileInfo.FullName, destFileName); + } + } return VersionOracle.Create(fullProjectDirectory, null, CloudBuild.Active); } diff --git a/src/Directory.Build.props b/src/Directory.Build.props index d4ad827f..4f4bbbf6 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -19,6 +19,10 @@ true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + 2.0.298 + diff --git a/src/NerdBank.GitVersioning/GitExtensions.cs b/src/NerdBank.GitVersioning/GitExtensions.cs index b31a4053..cb60f1de 100644 --- a/src/NerdBank.GitVersioning/GitExtensions.cs +++ b/src/NerdBank.GitVersioning/GitExtensions.cs @@ -353,7 +353,18 @@ public static IEnumerable GetCommitsFromVersion(this Repository repo, Ve /// Thrown if the provided path does not lead to an existing directory. public static void HelpFindLibGit2NativeBinaries(string basePath) { - if (!TryHelpFindLibGit2NativeBinaries(basePath, out string attemptedDirectory)) + HelpFindLibGit2NativeBinaries(basePath, out string _); + } + + /// + /// Assists the operating system in finding the appropriate native libgit2 module. + /// + /// The path to the directory that contains the lib folder. + /// Receives the directory that native binaries are expected. + /// Thrown if the provided path does not lead to an existing directory. + public static void HelpFindLibGit2NativeBinaries(string basePath, out string attemptedDirectory) + { + if (!TryHelpFindLibGit2NativeBinaries(basePath, out attemptedDirectory)) { throw new ArgumentException($"Unable to find native binaries under directory: \"{attemptedDirectory}\"."); } @@ -366,7 +377,7 @@ public static void HelpFindLibGit2NativeBinaries(string basePath) /// true if the libgit2 native binaries have been found; false otherwise. public static bool TryHelpFindLibGit2NativeBinaries(string basePath) { - return TryHelpFindLibGit2NativeBinaries(basePath, out string attemptedDirectory); + return TryHelpFindLibGit2NativeBinaries(basePath, out string _); } /// diff --git a/src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.Tasks.csproj b/src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.Tasks.csproj index 9b6b1d44..a2e4b0b2 100644 --- a/src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.Tasks.csproj +++ b/src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.Tasks.csproj @@ -18,7 +18,7 @@ - $(NuGetPackageRoot)libgit2sharp.nativebinaries\2.0.298\ + $(NuGetPackageRoot)libgit2sharp.nativebinaries\$(LibGit2SharpNativeVersion)\ $(NuspecProperties);Version=$(Version);commit=$(GitCommitId);BaseOutputPath=$(OutputPath);LibGit2SharpNativeBinaries=$(LibGit2SharpNativeBinaries)