diff --git a/dsc/src/subcommand.rs b/dsc/src/subcommand.rs index 1c308ad0e..8c7b732d9 100644 --- a/dsc/src/subcommand.rs +++ b/dsc/src/subcommand.rs @@ -319,6 +319,8 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option, parame } }; + configurator.context.dsc_version = Some(env!("CARGO_PKG_VERSION").to_string()); + if let ConfigSubCommand::Set { what_if , .. } = subcommand { if *what_if { configurator.context.execution_type = ExecutionKind::WhatIf; diff --git a/dsc/tests/dsc_version.tests.ps1 b/dsc/tests/dsc_version.tests.ps1 new file mode 100644 index 000000000..b3e7a7e93 --- /dev/null +++ b/dsc/tests/dsc_version.tests.ps1 @@ -0,0 +1,20 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +Describe 'tests for metadata versioning' { + It 'returns the correct dsc semantic version in metadata' { + $config_yaml = @" + `$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json + resources: + - name: Echo + type: Microsoft.DSC.Debug/Echo + properties: + output: 'Hello, World!' +"@ + $out = $config_yaml | dsc config get -f - | ConvertFrom-Json + $version = $out.metadata.'Microsoft.DSC'.version -as [System.Management.Automation.SemanticVersion] + $version | Should -Not -BeNullOrEmpty + $dscVersion = (dsc --version).Split(" ")[1] + $version | Should -Be $dscVersion + } +} \ No newline at end of file diff --git a/dsc_lib/src/configure/context.rs b/dsc_lib/src/configure/context.rs index 9b16d4fd8..ab7b6cb78 100644 --- a/dsc_lib/src/configure/context.rs +++ b/dsc_lib/src/configure/context.rs @@ -21,6 +21,7 @@ pub struct Context { pub restart_required: Option>, pub process_expressions: bool, pub processing_parameter_defaults: bool, + pub dsc_version: Option, } impl Context { @@ -41,6 +42,7 @@ impl Context { restart_required: None, process_expressions: true, processing_parameter_defaults: false, + dsc_version: None, } } } diff --git a/dsc_lib/src/configure/mod.rs b/dsc_lib/src/configure/mod.rs index 946b91646..3afdcde33 100644 --- a/dsc_lib/src/configure/mod.rs +++ b/dsc_lib/src/configure/mod.rs @@ -800,10 +800,15 @@ impl Configurator { fn get_result_metadata(&self, operation: Operation) -> Metadata { let end_datetime = chrono::Local::now(); + let version = self + .context + .dsc_version + .clone() + .unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string()); Metadata { microsoft: Some( MicrosoftDscMetadata { - version: Some(env!("CARGO_PKG_VERSION").to_string()), + version: Some(version), operation: Some(operation), execution_type: Some(self.context.execution_type.clone()), start_datetime: Some(self.context.start_datetime.to_rfc3339()),