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/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' 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 9e9b79a..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 @@ -15,13 +15,15 @@ - 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 3d66770..9d59edf 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); } @@ -91,6 +92,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; } @@ -157,6 +159,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); } @@ -181,6 +184,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); } @@ -204,6 +208,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 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)); } 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")]