diff --git a/src/Accounts/Authentication.ResourceManager/Properties/Resources.Designer.cs b/src/Accounts/Authentication.ResourceManager/Properties/Resources.Designer.cs index a3271b6a208b..c90ec74ced1f 100644 --- a/src/Accounts/Authentication.ResourceManager/Properties/Resources.Designer.cs +++ b/src/Accounts/Authentication.ResourceManager/Properties/Resources.Designer.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -19,7 +19,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.ResourceManager.Propert // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/src/Resources/ResourceManager/Implementation/CmdletBase/ResourceWithParameterCmdletBase.cs b/src/Resources/ResourceManager/Implementation/CmdletBase/ResourceWithParameterCmdletBase.cs index b4125c3e6dd9..df153a927003 100644 --- a/src/Resources/ResourceManager/Implementation/CmdletBase/ResourceWithParameterCmdletBase.cs +++ b/src/Resources/ResourceManager/Implementation/CmdletBase/ResourceWithParameterCmdletBase.cs @@ -436,7 +436,7 @@ protected string[] GetStaticParameterNames() protected void BuildAndUseBicepTemplate() { - TemplateFile = BicepUtility.BuildFile(this.ExecuteScript, this.ResolvePath(TemplateFile)); + TemplateFile = BicepUtility.BuildFile(this.ResolvePath(TemplateFile), this.WriteVerbose); } } } diff --git a/src/Resources/ResourceManager/Utilities/BicepUtility.cs b/src/Resources/ResourceManager/Utilities/BicepUtility.cs index c0c4ae144d93..cd73d9409056 100644 --- a/src/Resources/ResourceManager/Utilities/BicepUtility.cs +++ b/src/Resources/ResourceManager/Utilities/BicepUtility.cs @@ -27,38 +27,30 @@ internal static class BicepUtility { public static bool IsBicepExecutable { get; private set; } = false; - public static string MinimalVersionRequirement = "0.3.1"; + public static string MinimalVersionRequirement { get; private set; } = "0.3.1"; public static bool IsBicepFile(string templateFilePath) { return ".bicep".Equals(Path.GetExtension(templateFilePath), System.StringComparison.OrdinalIgnoreCase); } - public delegate List ScriptExecutor(string script); - - public static bool CheckBicepExecutable(ScriptExecutor executeScript) + public static bool CheckBicepExecutable() { - try - { - executeScript("get-command bicep"); - } - catch - { - IsBicepExecutable = false; - return IsBicepExecutable; - } - IsBicepExecutable = true; + System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create(); + powershell.AddScript("Get-Command bicep"); + powershell.Invoke(); + IsBicepExecutable = powershell.HadErrors ? false : true; return IsBicepExecutable; } - private static bool CheckMinimalVersionRequirement(string checkMinumVersionRequirement) + private static string CheckMinimalVersionRequirement(string minimalVersionRequirement) { - - if (Version.Parse(checkMinumVersionRequirement).CompareTo(Version.Parse(GetBicepVesion())) > 0) + string currentBicepVersion = GetBicepVesion(); + if (Version.Parse(minimalVersionRequirement).CompareTo(Version.Parse(currentBicepVersion)) > 0) { - throw new AzPSApplicationException(string.Format(Properties.Resources.BicepVersionRequirement, checkMinumVersionRequirement)); + throw new AzPSApplicationException(string.Format(Properties.Resources.BicepVersionRequirement, minimalVersionRequirement)); }; - return true; + return currentBicepVersion; } public static string GetBicepVesion() @@ -71,14 +63,16 @@ public static string GetBicepVesion() return bicepVersion; } - public static string BuildFile(ScriptExecutor executeScript, string bicepTemplateFilePath) + public delegate void OutputMethod(string msg); + + public static string BuildFile(string bicepTemplateFilePath, OutputMethod outputMethod = null) { - if (!IsBicepExecutable && !CheckBicepExecutable(executeScript)) + if (!IsBicepExecutable && !CheckBicepExecutable()) { throw new AzPSApplicationException(Properties.Resources.BicepNotFound); } - CheckMinimalVersionRequirement(MinimalVersionRequirement); + string currentBicepVersion = CheckMinimalVersionRequirement(MinimalVersionRequirement); string tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempDirectory); @@ -87,7 +81,12 @@ public static string BuildFile(ScriptExecutor executeScript, string bicepT { System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create(); powershell.AddScript($"bicep build '{bicepTemplateFilePath}' --outdir '{tempDirectory}'"); - powershell.Invoke(); + var result = powershell.Invoke(); + if (outputMethod != null) + { + outputMethod(string.Format("Using Bicep v{0}", currentBicepVersion)); + result.ForEach(r => outputMethod(r.ToString())); + } if (powershell.HadErrors) { string errorMsg = string.Empty; diff --git a/src/Resources/Resources.Test/UnitTests/Utilities/TestBicepUtility.cs b/src/Resources/Resources.Test/UnitTests/Utilities/TestBicepUtility.cs index 9e8a574a07cd..692f19fa71dd 100644 --- a/src/Resources/Resources.Test/UnitTests/Utilities/TestBicepUtility.cs +++ b/src/Resources/Resources.Test/UnitTests/Utilities/TestBicepUtility.cs @@ -1,10 +1,6 @@ using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using System; -using System.Collections.Generic; -using System.Text; - using Xunit; namespace Microsoft.Azure.Commands.Resources.Test.UnitTests.Utilities @@ -18,23 +14,5 @@ public void TestIsBicepFile() Assert.True(BicepUtility.IsBicepFile("test.bicep")); Assert.False(BicepUtility.IsBicepFile("test.json")); } - - [Fact] - [Trait(Category.AcceptanceType, Category.CheckIn)] - public void TestCheckBicepExecutable() - { - Assert.True(BicepUtility.CheckBicepExecutable(FakeTrueScriptExcutor)); - Assert.False(BicepUtility.CheckBicepExecutable(FakeFalseScriptExcutor)); - } - - private List FakeTrueScriptExcutor(string script) - { - return null; - } - - private List FakeFalseScriptExcutor(string script) - { - throw new Exception("fake exception"); - } } } diff --git a/src/Resources/Resources/ChangeLog.md b/src/Resources/Resources/ChangeLog.md index fba0b5873383..ef1275446d25 100644 --- a/src/Resources/Resources/ChangeLog.md +++ b/src/Resources/Resources/ChangeLog.md @@ -19,7 +19,8 @@ --> ## Upcoming Release -* Removed the logic of coping Bicep template file to temp folder. +* Redirected bicep message to verbose stream +* Removed the logic of copying Bicep template file to temp folder. ## Version 3.3.0 * Added support for Azure resources deployment in Bicep language