diff --git a/src/Bicep.Cli.IntegrationTests/BuildParamsCommandTests.cs b/src/Bicep.Cli.IntegrationTests/BuildParamsCommandTests.cs index 9f6ce57a997..25e34542c5e 100644 --- a/src/Bicep.Cli.IntegrationTests/BuildParamsCommandTests.cs +++ b/src/Bicep.Cli.IntegrationTests/BuildParamsCommandTests.cs @@ -428,6 +428,32 @@ public async Task Build_params_returns_intuitive_error_if_invoked_with_bicep_fil result.Should().Fail().And.HaveStderrMatch($"Bicep file * provided with --bicep-file can only be used if the Bicep parameters \"using\" declaration refers to a Bicep file on disk.*"); } + [TestMethod] + [TestCategory(BaselineHelper.BaselineTestCategory)] + public async Task Build_params_works_with_using_none() + { + var outputPath = FileHelper.GetUniqueTestOutputPath(TestContext); + + var bicepFile = FileHelper.SaveResultFile(TestContext, "main.bicep", @" + param unusedParam int + ", outputPath); + + var inputFile = FileHelper.SaveResultFile(TestContext, "main.bicepparam", @" + using none + + param unusedParam = 3 + ", outputPath); + + var (output, error, result) = await Bicep(["build-params", inputFile, "--bicep-file", bicepFile]); + + var expectedOutputFile = FileHelper.GetResultFilePath(TestContext, "main.json", outputPath); + + File.Exists(expectedOutputFile).Should().BeTrue(); + output.Should().BeEmpty(); + error.Should().BeEmpty(); + result.Should().Be(0); + } + [TestMethod] [EmbeddedFilesTestData(@"Files/BuildParamsCommandTests/Registry/main\.bicepparam")] [TestCategory(BaselineHelper.BaselineTestCategory)] diff --git a/src/Bicep.Cli/Commands/BuildParamsCommand.cs b/src/Bicep.Cli/Commands/BuildParamsCommand.cs index d5db02bfb42..ddad2b83f3e 100644 --- a/src/Bicep.Cli/Commands/BuildParamsCommand.cs +++ b/src/Bicep.Cli/Commands/BuildParamsCommand.cs @@ -63,14 +63,17 @@ public async Task RunAsync(BuildParamsArguments args) if (bicepFileUri is not null && compilation.GetEntrypointSemanticModel().Root.TryGetBicepFileSemanticModelViaUsing().IsSuccess(out var usingModel)) { - if (usingModel is not SemanticModel bicepSemanticModel) + if (usingModel is not EmptySemanticModel) { - throw new CommandLineException($"Bicep file {bicepFileUri.LocalPath} provided with --bicep-file can only be used if the Bicep parameters \"using\" declaration refers to a Bicep file on disk."); - } - - if (!bicepSemanticModel.Root.FileUri.Equals(bicepFileUri)) - { - throw new CommandLineException($"Bicep file {bicepFileUri.LocalPath} provided with --bicep-file option doesn't match the Bicep file {bicepSemanticModel.Root.Name} referenced by the \"using\" declaration in the parameters file."); + if (usingModel is not SemanticModel bicepSemanticModel) + { + throw new CommandLineException($"Bicep file {bicepFileUri.LocalPath} provided with --bicep-file can only be used if the Bicep parameters \"using\" declaration refers to a Bicep file on disk."); + } + + if (!bicepSemanticModel.Root.FileUri.Equals(bicepFileUri)) + { + throw new CommandLineException($"Bicep file {bicepFileUri.LocalPath} provided with --bicep-file option doesn't match the Bicep file {bicepSemanticModel.Root.Name} referenced by the \"using\" declaration in the parameters file."); + } } }