DSC icon indicating copy to clipboard operation
DSC copied to clipboard

.NET string formatting in bicep is not supported (only rust style is)

Open Gijsreyn opened this issue 3 months ago • 1 comments

Prerequisites

  • [x] Write a descriptive title.
  • [x] Make sure you are able to repro it on the latest version
  • [x] Search the existing issues.

Summary

As a user coming from the Bicep world, I would expect the following .NET notation to work (but it doesn't):

output: format('Hex formats: lowercase {0:x2}, uppercase {1:X2}, decimal {2:N0}', hexNumber, hexNumber, hexNumber)

Instead, we have to use:

output: format('Hex formats: lowercase {0:x}, uppercase {1:X}, decimal {2}', hexNumber, hexNumber, hexNumber)

For a full example, see:

targetScope = 'desiredStateConfiguration'

// Parameters for customizing the configuration
@description('Hexadecimal number for precision example')
param hexNumber int = 255

// Echo resource demonstrating precision with .NET-style formatting
resource precisionEcho 'Microsoft.DSC.Debug/Echo@2025-08-27' = {
  name: 'precisionExample'
  properties: {
    output: format('Hex formats: lowercase {0:x2}, uppercase {1:X2}, decimal {2:N0}', hexNumber, hexNumber, hexNumber)
  }
}

Versus:

targetScope = 'desiredStateConfiguration'

// Parameters for customizing the configuration
@description('Hexadecimal number for precision example')
param hexNumber int = 255

// Echo resource demonstrating precision with hexadecimal formatting
resource precisionEcho 'Microsoft.DSC.Debug/Echo@2025-08-27' = {
  name: 'precisionExample'
  properties: {
    output: format('Hex formats: lowercase {0:x}, uppercase {1:X}, decimal {2}', hexNumber, hexNumber, hexNumber)
  }
}

I wasn't sure if this was an issue or a feature request. But if it is possible, I prefer to align with the .NET style or document it somewhere.

Steps to reproduce

N/A.

Expected behavior

N/A.

Actual behavior

N/A.

Error details


Environment data

Name                           Value
----                           -----
PSVersion                      7.5.3
PSEdition                      Core
GitCommitId                    7.5.3
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

dsc 3.2.0-preview.5

Visuals

No response

Gijsreyn avatar Sep 18 '25 06:09 Gijsreyn

The challenge is that Bicep simply leverages .NET formatting. DSC has to reimplement it. We have to go case by case to implement the necessary ones that people use.

SteveL-MSFT avatar Oct 01 '25 22:10 SteveL-MSFT