-
Looking to do some buildout automation where we can parse/consume bicep files so that we can get the values off of a bicep object. Then, do some additional operations on them before deploying them. Is this possible? Somehow to consume the bicep objects in either dotnet or C# projects or in F#? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
You could look at how the Bicep PowerShell module does it by rebuilding parts of the bicep project and including it. Might even be able to use the BicepNet module as it already does some magic with outputting objects I believe. |
Beta Was this translation helpful? Give feedback.
-
We do have a NuGet package that is used by the CLI and language server to parse Bicep files: https://www.nuget.org/packages/Azure.Bicep.Core. It's not very well documented, but there are many examples of tests in this repo invoking code in that assembly. |
Beta Was this translation helpful? Give feedback.
-
for Azure.Bicep.Core 0.26.54: var host = Host.CreateDefaultBuilder().ConfigureServices(services =>
{
services.AddSingleton<IFileSystem, FileSystem>();
services.AddSingleton<INamespaceProvider, DefaultNamespaceProvider>();
services.AddSingleton<IResourceTypeProviderFactory, ResourceTypeProviderFactory>();
services.AddSingleton<IContainerRegistryClientFactory, ContainerRegistryClientFactory>();
services.AddSingleton<ITemplateSpecRepositoryFactory, TemplateSpecRepositoryFactory>();
services.AddSingleton<IModuleDispatcher, ModuleDispatcher>();
services.AddSingleton<IArtifactRegistryProvider, DefaultArtifactRegistryProvider>();
services.AddSingleton<ITokenCredentialFactory, TokenCredentialFactory>();
services.AddSingleton<IFileResolver, FileResolver>();
services.AddSingleton<IEnvironment, Environment>();
services.AddSingleton<IConfigurationManager, ConfigurationManager>();
services.AddSingleton<IBicepAnalyzer, LinterAnalyzer>();
services.AddSingleton<IFeatureProviderFactory, FeatureProviderFactory>();
services.AddSingleton<ILinterRulesProvider, LinterRulesProvider>();
services.AddSingleton<BicepCompiler>();
}).Build();
var bicepCompiler = host.Services.GetRequiredService<BicepCompiler>();
var compilation = bicepCompiler.CreateCompilationWithoutRestore(new Uri("path-to-bicep-file", UriKind.Absolute));
Console.WriteLine(compilation.Emitter.Template().Template); |
Beta Was this translation helpful? Give feedback.
We do have a NuGet package that is used by the CLI and language server to parse Bicep files: https://www.nuget.org/packages/Azure.Bicep.Core. It's not very well documented, but there are many examples of tests in this repo invoking code in that assembly.