From b7c7e841904d7c1f6d043a233c39e3a150929531 Mon Sep 17 00:00:00 2001 From: "Eric D. Guttormson" Date: Fri, 8 Jan 2021 11:57:48 -0600 Subject: [PATCH 1/7] Update Cake.Powershell to .Net 5.0 --- .../Cake.Powershell.Tests.csproj | 18 ++++++++++-------- src/Cake.Powershell/Cake.Powershell.csproj | 7 +++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj b/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj index a60c514..a8dbd92 100644 --- a/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj +++ b/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj @@ -5,7 +5,7 @@ Cake.Powershell.Tests Library - net46; + net50; false false @@ -19,15 +19,17 @@ - - - - + + + - - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/src/Cake.Powershell/Cake.Powershell.csproj b/src/Cake.Powershell/Cake.Powershell.csproj index d1937b2..5dfb1e8 100644 --- a/src/Cake.Powershell/Cake.Powershell.csproj +++ b/src/Cake.Powershell/Cake.Powershell.csproj @@ -5,7 +5,7 @@ Cake.Powershell Library - net46; + net50; false false @@ -19,8 +19,7 @@ - - - + + From 2f46212c24a6e99c187e148e1f85e7e887c29a92 Mon Sep 17 00:00:00 2001 From: "Eric D. Guttormson" Date: Fri, 8 Jan 2021 12:20:18 -0600 Subject: [PATCH 2/7] Update tests and add PowerShell sdk --- src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj | 1 + src/Cake.Powershell.Tests/Tests/FileTests.cs | 8 ++++---- src/Cake.Powershell/Cake.Powershell.csproj | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj b/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj index a8dbd92..991b616 100644 --- a/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj +++ b/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj @@ -21,6 +21,7 @@ + diff --git a/src/Cake.Powershell.Tests/Tests/FileTests.cs b/src/Cake.Powershell.Tests/Tests/FileTests.cs index 0a4ea5b..3e6bbf9 100644 --- a/src/Cake.Powershell.Tests/Tests/FileTests.cs +++ b/src/Cake.Powershell.Tests/Tests/FileTests.cs @@ -44,7 +44,7 @@ public void Start_File_With_ArrayParameters() new PowershellSettings().WithArguments(args => args.AppendArray("AnArray", array))); Assert.True((results != null) && (results.Count == array.Length + 1)); - Assert.Equal("0", results[0].BaseObject.ToString()); + Assert.Equal("", results[0].BaseObject.ToString()); foreach (var item in array) { @@ -65,7 +65,7 @@ public void Start_File_With_HashTableParameters() new PowershellSettings().WithArguments(args => args.AppendHashTable("AHashTable", dict))); Assert.True((results != null) && (results.Count == dict.Count + 1)); - Assert.Equal("0", results[0].BaseObject.ToString()); + Assert.Equal("", results[0].BaseObject.ToString()); foreach (var item in dict.ToArray()) { @@ -97,8 +97,8 @@ public void Returned_Error_Code_Should_Not_Throw_Exception_If_Option_Passed() .Start(new FilePath("Scripts/FailingScript.ps1"), new PowershellSettings() { ExceptionOnScriptError = false }); Assert.True(results != null && results.Count >= 1, "Check Rights"); - Assert.True(results.FirstOrDefault(r => r.BaseObject.ToString().Contains("Cannot find path")) != null); - Assert.Equal("1", results[0].BaseObject.ToString()); + Assert.True(results.Where(r => r.BaseObject.ToString().Contains("Cannot find path")) != null); + Assert.Equal("1", results.Last().BaseObject.ToString()); } [Fact] diff --git a/src/Cake.Powershell/Cake.Powershell.csproj b/src/Cake.Powershell/Cake.Powershell.csproj index 5dfb1e8..5b14231 100644 --- a/src/Cake.Powershell/Cake.Powershell.csproj +++ b/src/Cake.Powershell/Cake.Powershell.csproj @@ -20,6 +20,7 @@ + From 91e39dceac90d8310cf94ebbc77f814304120511 Mon Sep 17 00:00:00 2001 From: "Eric D. Guttormson" Date: Fri, 8 Jan 2021 13:38:08 -0600 Subject: [PATCH 3/7] Update build settings for .net 5.0 --- .vscode/launch.json | 27 ++++++++++++ .vscode/tasks.json | 42 +++++++++++++++++++ ReleaseNotes.md | 3 ++ nuspec/Cake.Powershell.nuspec | 10 ++--- src/Cake.Powershell/Cake.Powershell.csproj | 2 +- .../Host/CakePSHostRawUserInterface.cs | 7 +++- src/SolutionInfo.cs | 8 ++-- 7 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7ebed7a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/src/Cake.Powershell.Tests/bin/Debug/net5.0/Cake.Powershell.Tests.dll", + "args": [], + "cwd": "${workspaceFolder}/src/Cake.Powershell.Tests", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..239dd57 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/ReleaseNotes.md b/ReleaseNotes.md index a6513ab..08ae749 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,3 +1,6 @@ +### New in 0.5.0 (Released 2021/01/08) +* [Improvement] Update to Cake.Core v1.0 + ### New in 0.4.8 (Released 2019/05/12) * [Improvement] Update to Cake.Core v0.33 diff --git a/nuspec/Cake.Powershell.nuspec b/nuspec/Cake.Powershell.nuspec index 0c74040..b1d0aef 100644 --- a/nuspec/Cake.Powershell.nuspec +++ b/nuspec/Cake.Powershell.nuspec @@ -18,12 +18,10 @@ - - - - - - + + + + diff --git a/src/Cake.Powershell/Cake.Powershell.csproj b/src/Cake.Powershell/Cake.Powershell.csproj index 5b14231..27a1f15 100644 --- a/src/Cake.Powershell/Cake.Powershell.csproj +++ b/src/Cake.Powershell/Cake.Powershell.csproj @@ -15,7 +15,7 @@ - bin\Debug\net46\Cake.Powershell.xml + bin\Debug\net50\Cake.Powershell.xml diff --git a/src/Cake.Powershell/Host/CakePSHostRawUserInterface.cs b/src/Cake.Powershell/Host/CakePSHostRawUserInterface.cs index a344ca7..41fcfc3 100644 --- a/src/Cake.Powershell/Host/CakePSHostRawUserInterface.cs +++ b/src/Cake.Powershell/Host/CakePSHostRawUserInterface.cs @@ -1,7 +1,7 @@ #region Using Statements using System; using System.Management.Automation.Host; - +using System.Runtime.Versioning; using Cake.Core.Diagnostics; #endregion @@ -50,6 +50,7 @@ public override ConsoleColor BackgroundColor /// Gets or sets the size of the host buffer. In this example the /// buffer size is adapted from the Console buffer size members. /// + [SupportedOSPlatform("windows")] public override Size BufferSize { get { return new Size(Console.BufferWidth, Console.BufferHeight); } @@ -78,6 +79,7 @@ public override Coordinates CursorPosition /// the cursor size is taken directly from the Console.CursorSize /// property. /// + [SupportedOSPlatform("windows")] public override int CursorSize { get { return Console.CursorSize; } @@ -131,6 +133,7 @@ public override Size MaxWindowSize /// uses the Console window position APIs to determine the returned /// value of this property. /// + [SupportedOSPlatform("windows")] public override Coordinates WindowPosition { get { return new Coordinates(Console.WindowLeft, Console.WindowTop); } @@ -142,6 +145,7 @@ public override Coordinates WindowPosition /// uses the corresponding Console window size APIs to determine the /// returned value of this property. /// + [SupportedOSPlatform("windows")] public override Size WindowSize { get { return new Size(Console.WindowWidth, Console.WindowHeight); } @@ -152,6 +156,7 @@ public override Size WindowSize /// Gets or sets the title of the displayed window. The example /// maps the Console.Title property to the value of this property. /// + [SupportedOSPlatform("windows")] public override string WindowTitle { get { return Console.Title; } diff --git a/src/SolutionInfo.cs b/src/SolutionInfo.cs index 607af33..f80666f 100644 --- a/src/SolutionInfo.cs +++ b/src/SolutionInfo.cs @@ -5,8 +5,8 @@ //------------------------------------------------------------------------------ using System.Reflection; -[assembly: AssemblyVersion("0.4.6")] -[assembly: AssemblyFileVersion("0.4.6")] -[assembly: AssemblyInformationalVersion("0.4.6")] -[assembly: AssemblyCopyright("Copyright (c) 2015 - 2018 Phillip Sharpe")] +[assembly: AssemblyVersion("0.5.0")] +[assembly: AssemblyFileVersion("0.5.0")] +[assembly: AssemblyInformationalVersion("0.5.0")] +[assembly: AssemblyCopyright("Copyright (c) 2015 - 2021 Phillip Sharpe")] From 258a06cb1770085d213a8fbdcea8e339cb9b3e0e Mon Sep 17 00:00:00 2001 From: ericgutt10 Date: Fri, 8 Jan 2021 15:12:57 -0600 Subject: [PATCH 4/7] Set up CI with Azure Pipelines [skip ci] --- azure-pipelines.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..ac078ef --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,19 @@ +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: +- main + +pool: + vmImage: 'ubuntu-latest' + +steps: +- script: echo Hello, world! + displayName: 'Run a one-line script' + +- script: | + echo Add other tasks to build, test, and deploy your project. + echo See https://aka.ms/yaml + displayName: 'Run a multi-line script' From cdeaf91579ca0377a6c86ecc631160912df119c0 Mon Sep 17 00:00:00 2001 From: "Eric D. Guttormson" Date: Wed, 13 Jan 2021 17:31:14 -0600 Subject: [PATCH 5/7] Update references --- src/Cake.Powershell/Cake.Powershell.csproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Cake.Powershell/Cake.Powershell.csproj b/src/Cake.Powershell/Cake.Powershell.csproj index 27a1f15..ffa07a9 100644 --- a/src/Cake.Powershell/Cake.Powershell.csproj +++ b/src/Cake.Powershell/Cake.Powershell.csproj @@ -20,7 +20,9 @@ - - + + + + From ecf16688943c0cf9f4976bf508fa3ee4b0db9d66 Mon Sep 17 00:00:00 2001 From: Eric Guttormson Date: Mon, 17 Jan 2022 15:54:57 -0600 Subject: [PATCH 6/7] Updated versions --- src/SolutionInfo.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SolutionInfo.cs b/src/SolutionInfo.cs index 6800adb..1de7adf 100644 --- a/src/SolutionInfo.cs +++ b/src/SolutionInfo.cs @@ -5,8 +5,8 @@ //------------------------------------------------------------------------------ using System.Reflection; -[assembly: AssemblyVersion("0.4.8")] -[assembly: AssemblyFileVersion("0.4.8")] -[assembly: AssemblyInformationalVersion("0.4.8")] -[assembly: AssemblyCopyright("Copyright (c) 2015 - 2021 Phillip Sharpe")] +[assembly: AssemblyVersion("1.0.1")] +[assembly: AssemblyFileVersion("1.0.1")] +[assembly: AssemblyInformationalVersion("1.0.1")] +[assembly: AssemblyCopyright("Copyright (c) 2015 - 2022 Phillip Sharpe")] From e7a127a7aca4c929a1ed7c95553eb254dbbf821a Mon Sep 17 00:00:00 2001 From: Eric Guttormson Date: Mon, 17 Jan 2022 15:43:46 -0600 Subject: [PATCH 7/7] local edits --- nuget.config | 45 +++++++++++++++++++ .../Cake.Powershell.Tests.csproj | 16 +++---- .../Aliases/PowershellAliases.cs | 7 +-- src/Cake.Powershell/Cake.Powershell.csproj | 9 ++-- .../Interfaces/IPowershellRunner.cs | 4 +- .../Runner/PowershellRunner.cs | 19 +++++--- 6 files changed, 77 insertions(+), 23 deletions(-) create mode 100644 nuget.config diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..d3d9481 --- /dev/null +++ b/nuget.config @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj b/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj index dc3fc60..3f35dbd 100644 --- a/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj +++ b/src/Cake.Powershell.Tests/Cake.Powershell.Tests.csproj @@ -5,7 +5,7 @@ Cake.Powershell.Tests Library - net46;netcoreapp3.1;net5.0 + net60 false false @@ -19,20 +19,20 @@ - - + + - - + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/src/Cake.Powershell/Aliases/PowershellAliases.cs b/src/Cake.Powershell/Aliases/PowershellAliases.cs index 2c37bdf..acb3019 100644 --- a/src/Cake.Powershell/Aliases/PowershellAliases.cs +++ b/src/Cake.Powershell/Aliases/PowershellAliases.cs @@ -7,6 +7,7 @@ using Cake.Core.Annotations; using System.Management.Automation; +using System.Threading.Tasks; #endregion @@ -109,7 +110,7 @@ public static Collection StartPowershellFile(this ICakeContext context /// The temporary path to download the file to. /// A collection of powershell objects [CakeMethodAlias] - public static Collection StartPowershellDownload(this ICakeContext context, Uri uri, FilePath path) + public static Task> StartPowershellDownload(this ICakeContext context, Uri uri, FilePath path) { return new PowershellRunner(context.Environment, context.Log).Start(uri, path, new PowershellSettings()); } @@ -123,7 +124,7 @@ public static Collection StartPowershellDownload(this ICakeContext con /// The arguments to append. /// A collection of powershell objects [CakeMethodAlias] - public static Collection StartPowershellDownload(this ICakeContext context, Uri uri, FilePath path, Action arguments) + public static Task> StartPowershellDownload(this ICakeContext context, Uri uri, FilePath path, Action arguments) { return new PowershellRunner(context.Environment, context.Log).Start(uri, path, new PowershellSettings().WithArguments(arguments)); } @@ -137,7 +138,7 @@ public static Collection StartPowershellDownload(this ICakeContext con /// The information about the script to start. /// A collection of powershell objects [CakeMethodAlias] - public static Collection StartPowershellDownload(this ICakeContext context, Uri uri, FilePath path, PowershellSettings settings) + public static Task> StartPowershellDownload(this ICakeContext context, Uri uri, FilePath path, PowershellSettings settings) { return new PowershellRunner(context.Environment, context.Log).Start(uri, path, settings); } diff --git a/src/Cake.Powershell/Cake.Powershell.csproj b/src/Cake.Powershell/Cake.Powershell.csproj index 9afde39..5ef3f16 100644 --- a/src/Cake.Powershell/Cake.Powershell.csproj +++ b/src/Cake.Powershell/Cake.Powershell.csproj @@ -5,7 +5,7 @@ Cake.Powershell Library - net46;netcoreapp3.1;net5.0 + net60; false false @@ -19,10 +19,11 @@ - + - - + + + diff --git a/src/Cake.Powershell/Interfaces/IPowershellRunner.cs b/src/Cake.Powershell/Interfaces/IPowershellRunner.cs index 425f199..2d7b7c9 100644 --- a/src/Cake.Powershell/Interfaces/IPowershellRunner.cs +++ b/src/Cake.Powershell/Interfaces/IPowershellRunner.cs @@ -3,7 +3,7 @@ using System.Collections.ObjectModel; using System.Management.Automation; - +using System.Threading.Tasks; using Cake.Core.IO; #endregion @@ -40,7 +40,7 @@ public interface IPowershellRunner /// The temporary path to download the file to. /// The information about the process to start. /// Powershell objects. - Collection Start(Uri uri, FilePath path, PowershellSettings settings); + Task> Start(Uri uri, FilePath path, PowershellSettings settings); #endregion } } diff --git a/src/Cake.Powershell/Runner/PowershellRunner.cs b/src/Cake.Powershell/Runner/PowershellRunner.cs index 504f2b3..065fc26 100644 --- a/src/Cake.Powershell/Runner/PowershellRunner.cs +++ b/src/Cake.Powershell/Runner/PowershellRunner.cs @@ -2,12 +2,14 @@ using System; using System.Collections.ObjectModel; using System.Globalization; +using System.IO; using System.Linq; using System.Management.Automation; using System.Management.Automation.Runspaces; using System.Net; +using System.Net.Http; using System.Threading; - +using System.Threading.Tasks; using Cake.Core; using Cake.Core.Diagnostics; using Cake.Core.IO; @@ -145,7 +147,7 @@ public Collection Start(FilePath path, PowershellSettings settings) /// The temporary path to download the file to. /// The information about the process to start. /// Powershell objects. - public Collection Start(Uri uri, FilePath path, PowershellSettings settings) + public async Task> Start(Uri uri, FilePath path, PowershellSettings settings) { if (uri == null) { @@ -163,13 +165,18 @@ public Collection Start(Uri uri, FilePath path, PowershellSettings set string prefix = settings.UseDotSourcing ? ". " : "&"; string fullPath = path.MakeAbsolute(settings.WorkingDirectory).FullPath; - string script = prefix + "\"" + fullPath + "\""; + string script = $"{prefix}\\{fullPath}\\temp.ps1"; //Download Script - WebClient client = new WebClient(); - client.DownloadFile(uri, fullPath); + var client = new HttpClient(); + using (var stream = await client.GetStreamAsync(uri).ConfigureAwait(false)) + using (var fileStream = new FileStream(script, FileMode.CreateNew)) + { + await stream.CopyToAsync(fileStream); + } + LogExecutingCommand(settings, script); @@ -179,7 +186,7 @@ public Collection Start(Uri uri, FilePath path, PowershellSettings set //Call script = this.AppendArguments(script, settings.Arguments, false); - return this.Invoke(script, settings); + return await Task.FromResult(this.Invoke(script, settings)); }