BicepNet is a thin wrapper around bicep that solves the problem with conflicting assemblies. The techique is sourced from this blog post: Resolving PowerShell module assembly dependency conflicts
BicepNet has two parts, BicepNet.Core and BicepNet.PS.
BicepNet.PS is a PowerShell module written i C# that creates an assembly load context and loads any dependencies of BicepNet.Core into that context. This will resolve any conflicts with other PowerShell modules that depends on different versions of the same DLL-files as Bicep does.
The goal of BicepNet.PS is also to translate any functionality exposed by BicepNet.Core as PowerShell cmdlets.
Each cmdlet is defined in a separate file in the Commands folder. The more generic load context code is in the LoadContext folder.
BicepNet.Core will have all it's dependencies loaded into the assembly load context created by BicepNet.PS. That means that PowerShell will not be able to access anything defined directly in bicep or any of it's dependencies. To solve this, BicepNet.Core has to implement and expose any functionallity we want to use from bicep. We have chosen to expose these as static methods in the class BicepNet.Core.BicepWrapper. Each method is implemented in it's own file in the BicepNet.Core folder root.
Any class needed for data returned to BicepNet.PS needs to be defined in the BicepNet.Core as well. These are defined as classes in the Modules folder of BicepNet.Core.
The project ships with a dev container, it should contain everything needed.
The container build process will clone and build Bicep which takes some time, please be patient.
Known Issues:
- There might be an error stating that it failed to restore projects. This is because the language servers tries to restore the project before the dependencies are downloaded. Just ignore the error and restart the container or reload the workspace and it should work as expected.
- git (Download)
- dotnet 7 SDK (Download)
- Visual Studio Code (Download)
- (optional) gitversion (Download)
- Make sure your execution policy allows execution of PowerShell scripts.
Set-ExecutionPolicy -ExecutionPolicy 'Unrestricted' -Scope 'CurrentUser' -Force
- Clone BicepNet repository to your local machine.
git clone https://github.com/PSBicep/BicepNet.git
- Run
./build.ps1 -ResolveDependency
to download any dependencies. This will download the Bicep source code and a few PowerShell modules used for building.
To checkout a specific version of bicep, update the value for entry 'Azure/Bicep' inRequiredModules.psd1
with desired git tag, branch or commit hash. - Build the project by running
./build.ps1
, this will build the module to output/BicepNet.PS and execute all tests.
Now you are ready to start coding!
We are running an autogenerated test suite intended to pick up on breaking changes on parameters. The current parameter configuration is defined in 'BicepNet.PS/tests/BicepNet.PS.ParameterTests.json'. There is a build task that updates this file to current parameter configuration. If a parameter is changed, added or deleted, re-generate this file by running the command ./build.ps1 GenerateTestCases
To build BicepNet, run the script ./build.ps1 build
.
This will create the folder 'output' containing a BicepNet.PS module that is ready to be loaded.
To use the new version of BicepNet in PSBicep, copy the module to the PSBicep module folder.