in src/PSRule.Rules.Azure/Data/Bicep/BicepHelper.cs [86:119]
private static string GetVersionInfo(string binPath, bool useAzCLI)
{
try
{
var args = GetBicepVersionArgs(useAzCLI);
var versionStartInfo = new ProcessStartInfo(binPath, args)
{
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
WorkingDirectory = PSRuleOption.GetWorkingPath(),
};
var bicep = new BicepProcess(Process.Start(versionStartInfo), 5);
try
{
if (bicep.WaitForExit(out _))
return TrimVersion(bicep.GetOutput());
}
finally
{
bicep.Dispose();
}
return null;
}
catch (Exception ex)
{
if (ex is Win32Exception win32 && win32.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
throw new BicepCompileException(PSRuleResources.BicepNotFound, ex);
}
throw new BicepCompileException(string.Format(Thread.CurrentThread.CurrentCulture, PSRuleResources.BicepCommandError, ex.Message), ex);
}
}