From 5fe1246a5973ce01de00ff02b3c95599abb9ba11 Mon Sep 17 00:00:00 2001 From: Petrik van der Velde Date: Sat, 13 Apr 2019 21:57:50 +1200 Subject: [PATCH 1/2] Updating to nBuildKit 1.0.0 references #8 --- entrypoint.msbuild | 964 +++++++++++++++++---------------------------- 1 file changed, 363 insertions(+), 601 deletions(-) diff --git a/entrypoint.msbuild b/entrypoint.msbuild index c33b423..77785b0 100644 --- a/entrypoint.msbuild +++ b/entrypoint.msbuild @@ -1,36 +1,43 @@ - + - $(MSBuildProjectDirectory) + $(MSBuildProjectDirectory) $(DirWorkspace)\packages + + $(DirWorkspace) - $(DirWorkspace)\settings.props + $(DirUserSettings)\settings.props - $(DirWorkspace)\packages.config + $(DirWorkspace)\packages.config - $(DirWorkspace)\nuget.config + $(DirWorkspace)\nuget.config NuGet.exe + + nBuildKit.MsBuild.EntryPoint + + - - - - - + + + + - + - + - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + - - - false - true - - $(DirWorkspace)\build - $(DirBuildDefault)\temp - $(DirWorkspace)\src - $(DirWorkspace)\tests - - https://raw.githubusercontent.com/nbuildkit/nBuildKit.MsBuild - $(UrlNBuildKitOnGitHub)/master/src/samples - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Build + - - - + + + + + + Test + - - + + + + + + Deploy + + + + + + + - - + + + + - - - - + + - + - - + + - + - - + + - - + + + + + - + - - - - - - - + + + + + - - - - - - + + + + - - - - - - - + + - + - + - - + + - - + + - - + + - - + + - + - + - - -
- - - - - - - - - - - - - - - - - - - - - - { - if (!string.IsNullOrWhiteSpace(e.Data)) - { - text.Append(e.Data); - } - }; - process.ErrorDataReceived += - (s, e) => - { - if (!string.IsNullOrWhiteSpace(e.Data)) - { - Log.LogError(e.Data); - } - }; - process.Start(); - - process.BeginOutputReadLine(); - process.BeginErrorReadLine(); - process.WaitForExit(); - - if (process.ExitCode != 0) - { - Log.LogError( - string.Format( - "{0} exited with a non-zero exit code. Exit code was: {1}", - System.IO.Path.GetFileName(process.StartInfo.FileName), - process.ExitCode)); - return false; - } - - try - { - string listText = text.ToString(); - const string nbuildKitVersionStart = "nBuildKit.Msbuild "; - var index = listText.IndexOf(nbuildKitVersionStart, StringComparison.OrdinalIgnoreCase); - var versionText = listText.Substring( - index + nbuildKitVersionStart.Length, - listText.IndexOf("nBuildKit", index + nbuildKitVersionStart.Length, StringComparison.OrdinalIgnoreCase) - (index + nbuildKitVersionStart.Length)) - .Trim(); - var version = new Version(versionText); - Major = version.Major; - Minor = version.Minor; - Patch = version.Build; - } - catch(Exception e) - { - Log.LogError(e.ToString()); - } - - // Log.HasLoggedErrors is true if the task logged any errors -- even if they were logged - // from a task's constructor or property setter. As long as this task is written to always log an error - // when it fails, we can reliably return HasLoggedErrors. - return !Log.HasLoggedErrors; - } - ]]> - - - - - - - - - - - - - { - if (!string.IsNullOrWhiteSpace(e.Data)) - { - text.Append(e.Data); - } - }; - process.ErrorDataReceived += - (s, e) => - { - if (!string.IsNullOrWhiteSpace(e.Data)) - { - Log.LogError(e.Data); - } - }; - process.Start(); - - process.BeginOutputReadLine(); - process.BeginErrorReadLine(); - process.WaitForExit(); - - if (process.ExitCode != 0) - { - Log.LogError( - string.Format( - "{0} exited with a non-zero exit code. Exit code was: {1}", - System.IO.Path.GetFileName(process.StartInfo.FileName), - process.ExitCode)); - return false; - } - - RemoteRepositoryUrl = ""; - try - { - string listText = text.ToString(); - const string remoteStart = "Fetch URL: "; - var index = listText.IndexOf(remoteStart, StringComparison.OrdinalIgnoreCase); - if (index > -1) - { - RemoteRepositoryUrl = listText.Substring( - index + remoteStart.Length, - listText.IndexOf("Push URL:", index + remoteStart.Length, StringComparison.OrdinalIgnoreCase) - (index + remoteStart.Length)) - .Trim(); - } - } - catch(Exception e) - { - Log.LogError(e.ToString()); - } - - // Log.HasLoggedErrors is true if the task logged any errors -- even if they were logged - // from a task's constructor or property setter. As long as this task is written to always log an error - // when it fails, we can reliably return HasLoggedErrors. - return !Log.HasLoggedErrors; - } - ]]> - - - + + @@ -710,7 +325,7 @@ - + - + + - - - + + + - + t.ItemSpec)))); + } try { - var webClient = new System.Net.WebClient(); - var response = webClient.DownloadString("https://api.nuget.org/v3-flatcontainer/nbuildkit.msbuild/index.json"); - var subResponse = response - .Replace(" ", "") - .Replace(System.Environment.NewLine, ""); - subResponse = subResponse.Substring(subResponse.IndexOf("[") + 1, subResponse.IndexOf("]") - subResponse.IndexOf("[") - 1); - var versions = subResponse.Split(','); - - var highestVersion = new Version(MinimumVersion); - var notAllowedVersion = new Version(MaximumVersion); - foreach (var versionText in versions) + var builder = new System.Text.StringBuilder(); { - var version = new Version(versionText.Trim('"')); - if ((version > highestVersion) && (version < notAllowedVersion)) + builder.Append(string.Format("list \"{0}\" ", PackageName)); + builder.Append("-NonInteractive "); + + // If the user has specified any sources to install from then only search those sources. + if (Sources != null) { - highestVersion = version; + foreach (var source in Sources) + { + // Make sure we remove the back-slash because if we don't then + // the closing quote will be eaten by the command line parser. Note that + // this is only necessary because we're dealing with a directory + builder.Append(string.Format("-Source \"{0}\" ", source.ItemSpec.TrimEnd('\\'))); + } } } - Version = highestVersion.ToString(3); + var info = new System.Diagnostics.ProcessStartInfo + { + FileName = NuGetPath, + Arguments = builder.ToString(), + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + }; + + Log.LogMessage( + MessageImportance.Low, + "Executing {0} with arguments: {1}", + NuGetPath, + info.Arguments); + + var text = new System.Collections.Generic.List(); + var process = new System.Diagnostics.Process(); + process.StartInfo = info; + process.OutputDataReceived += + (s, e) => + { + if (!string.IsNullOrWhiteSpace(e.Data)) + { + text.Add(e.Data); + } + }; + process.ErrorDataReceived += + (s, e) => + { + if (!string.IsNullOrWhiteSpace(e.Data)) + { + Log.LogError(e.Data); + } + }; + process.Start(); + + process.BeginOutputReadLine(); + process.BeginErrorReadLine(); + process.WaitForExit(); + + if (process.ExitCode != 0) + { + Log.LogError( + string.Format( + "{0} exited with a non-zero exit code. Exit code was: {1}", + System.IO.Path.GetFileName(process.StartInfo.FileName), + process.ExitCode)); + return false; + } + + Log.LogMessage( + MessageImportance.Low, + "{0} produced the following output: {1}", + NuGetPath, + string.Join(Environment.NewLine, text)); + + // Expecting something like: + // A 1.2.3 + // A.B 1.2.3 + // A.C 4.5.6 + // A.C.D 7.8.9 + // A.E 0.0.1 + // + // So find the exact package name by searching for the string that has the package name + // followed by a space + var packageNameInText = PackageName + " "; + + string selectedPackage = null; + var selectedVersion = new Version(); + foreach(var line in text) + { + if (line.StartsWith(packageNameInText)) + { + var versionText = line.Substring(packageNameInText.Length); + + System.Version packageVersion; + if (!System.Version.TryParse(versionText, out packageVersion)) + { + Log.LogMessage( + MessageImportance.Low, + "Package {0} is not a match for package {1}", + line, + PackageName); + + continue; + } + + if (packageVersion > selectedVersion) + { + Log.LogMessage( + MessageImportance.Low, + "Path {0} is a better match for package {1} than {2}", + line, + PackageName, + selectedPackage); + + selectedVersion = packageVersion; + selectedPackage = line; + } + } + } + + if (string.IsNullOrEmpty(selectedPackage)) + { + Log.LogError("Failed to find the correct package version."); + return false; + } + + Version = selectedVersion.ToString(3); } catch(Exception e) { @@ -848,26 +590,29 @@ - + + - + + - + - \ No newline at end of file + + + + + + + + + + 1.0 + + From 831b378de8629b18b08c9c4fe33dc700cea4494e Mon Sep 17 00:00:00 2001 From: Petrik van der Velde Date: Sat, 13 Apr 2019 22:02:08 +1200 Subject: [PATCH 2/2] Don't check if the values are defined in the settings.props file because nBuildKit provides defaults which we don't want references #8 --- settings.props | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/settings.props b/settings.props index e2bd0f8..7d8a34a 100644 --- a/settings.props +++ b/settings.props @@ -86,7 +86,7 @@ * Copyrights * API documentation --> - Nuclei.Build + Nuclei.Build - nuclei.build + nuclei.build - Nuclei.Build + Nuclei.Build - 2013 + 2013 - TheNucleus + TheNucleus - TheNucleus + TheNucleus - https://github.com/TheNucleus/nuclei.build + https://github.com/TheNucleus/nuclei.build - UNDEFINED + UNDEFINED - thenucleus + thenucleus - nuclei.build + nuclei.build - https://github.com/$(GitHubUserName)/nuclei.build.git + https://github.com/$(GitHubUserName)/nuclei.build.git - 0.8.0 - 1.0.0 + 1.0.0 + 2.0.0