Repository: microsoft/winget-dsc
Pull request #170: Add DSC Resource for enabling long path support
Author: login: Trenly
Created: 2025-04-02T21:23:14Z | Merged: 2025-04-02T22:41:40Z

<!-- To check a checkbox place an "x" between the brackets. e.g: [x] -->

- [x] I have signed the [Contributor License Agreement](https://cla.opensource.microsoft.com/microsoft/winget-dsc).
- [x] This pull request is related to an issue.
  - https://github.com/microsoft/winget-dsc/issues/168
 
Apologies for the automatic linting on the tests file.

-----

 ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/winget-dsc/pull/170)


Diff:
diff --git a/resources/Microsoft.Windows.Developer/Microsoft.Windows.Developer.psd1 b/resources/Microsoft.Windows.Developer/Microsoft.Windows.Developer.psd1
index 9c330f92..c1a65446 100644
--- a/resources/Microsoft.Windows.Developer/Microsoft.Windows.Developer.psd1
+++ b/resources/Microsoft.Windows.Developer/Microsoft.Windows.Developer.psd1
@@ -15,7 +15,8 @@
         'Taskbar',
         'WindowsExplorer',
         'UserAccessControl',
-        'EnableRemoteDesktop'
+        'EnableRemoteDesktop',
+        'EnableLongPathSupport'
     )
     PrivateData          = @{
         PSData = @{
@@ -28,13 +29,14 @@
                 'PSDscResource_Taskbar',
                 'PSDscResource_WindowsExplorer',
                 'PSDscResource_UserAccessControl',
-                'PSDscResource_EnableRemoteDesktop'
+                'PSDscResource_EnableRemoteDesktop',
+                'PSDscResource_EnableLongPathSupport'
             )
 
             # Prerelease string of this module
             Prerelease = 'alpha'
 
-             # A URL to the license for this module.
+            # A URL to the license for this module.
             LicenseUri = 'https://github.com/microsoft/winget-dsc/blob/main/LICENSE'
 
             # A URL to the main website for this project.
diff --git a/resources/Microsoft.Windows.Developer/Microsoft.Windows.Developer.psm1 b/resources/Microsoft.Windows.Developer/Microsoft.Windows.Developer.psm1
index 40fd1ecd..e7f00713 100644
--- a/resources/Microsoft.Windows.Developer/Microsoft.Windows.Developer.psm1
+++ b/resources/Microsoft.Windows.Developer/Microsoft.Windows.Developer.psm1
@@ -135,8 +135,9 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) {
     $global:SearchRegistryPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Search\'
     $global:UACRegistryPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\'
     $global:RemoteDesktopRegistryPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server'
+    $global:LongPathsRegistryPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem\'
 } else {
-    $global:ExplorerRegistryPath = $global:PersonalizeRegistryPath = $global:SearchRegistryPath = $global:UACRegistryPath = $global:RemoteDesktopRegistryPath = $env:TestRegistryPath
+    $global:ExplorerRegistryPath = $global:PersonalizeRegistryPath = $global:SearchRegistryPath = $global:UACRegistryPath = $global:RemoteDesktopRegistryPath = $global:LongPathsRegistryPath = $env:TestRegistryPath
 }
 
 [DSCResource()]
@@ -556,6 +557,47 @@ class EnableRemoteDesktop {
         Set-ItemProperty -Path $global:RemoteDesktopRegistryPath -Name $this.RemoteDesktopKey -Value $value
     }
 }
+
+[DSCResource()]
+class EnableLongPathSupport {
+    # Key required. Do not set.
+    [DscProperty(Key)]
+    [string]$SID
+
+    [DscProperty()]
+    [Ensure] $Ensure = [Ensure]::Present
+
+    hidden [string] $LongPathsKey = 'LongPathsEnabled'
+
+    [EnableLongPathSupport] Get() {
+        $exists = DoesRegistryKeyPropertyExist -Path $global:LongPathsRegistryPath -Name $this.LongPathsKey
+
+        # If the registry key does not exist, we assume long path support is not enabled.
+        if (-not($exists)) {
+            return @{
+                Ensure = [Ensure]::Absent
+            }
+        }
+
+        $registryValue = Get-ItemPropertyValue -Path $global:LongPathsRegistryPath -Name $this.LongPathsKey
+
+        # 1 == enabled == Present // 0 == disabled == Absent
+        return @{
+            Ensure = $registryValue ? [Ensure]::Present : [Ensure]::Absent
+        }
+    }
+
+    [bool] Test() {
+        $currentState = $this.Get()
+        return $currentState.Ensure -eq $this.Ensure
+    }
+
+    [void] Set() {
+        # 1 == enabled == Present // 0 == disabled == Absent
+        $value = ($this.Ensure -eq [Ensure]::Present) ? 1 : 0
+        Set-ItemProperty -Path $global:LongPathsRegistryPath -Name $this.LongPathsKey -Value $value
+    }
+}
 #endregion DSCResources
 
 #region Functions
diff --git a/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 b/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1
index c72b4253..416a5509 100644
--- a/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1
+++ b/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1
@@ -2,7 +2,7 @@
 # Licensed under the MIT License.
 using module Microsoft.Windows.Developer
 
-$ErrorActionPreference = "Stop"
+$ErrorActionPreference = 'Stop'
 Set-StrictMode -Version Latest
 
 <#
@@ -17,14 +17,14 @@ BeforeAll {
    # Create test registry path.
    New-Item -Path TestRegistry:\ -Name TestKey
    # Set-ItemProperty requires the PSDrive to be in the format 'HKCU:'.
-   $env:TestRegistryPath = ((Get-Item -Path TestRegistry:\).Name).replace("HKEY_CURRENT_USER", "HKCU:")
+   $env:TestRegistryPath = ((Get-Item -Path TestRegistry:\).Name).replace('HKEY_CURRENT_USER', 'HKCU:')
 }
 
 Describe 'List available DSC resources' {
    It 'Shows DSC Resources' {
-      $expectedDSCResources = "DeveloperMode", "OsVersion", "ShowSecondsInClock", "EnableDarkMode", "Taskbar", "UserAccessControl", "WindowsExplorer", "EnableRemoteDesktop"
+      $expectedDSCResources = 'DeveloperMode', 'OsVersion', 'ShowSecondsInClock', 'EnableDarkMode', 'Taskbar', 'UserAccessControl', 'WindowsExplorer', 'EnableRemoteDesktop', 'EnableLongPathSupport'
       $availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Developer).Name
-      $availableDSCResources.length | Should -Be 8
+      $availableDSCResources.length | Should -Be 9
       $availableDSCResources | Where-Object { $expectedDSCResources -notcontains $_ } | Should -BeNullOrEmpty -ErrorAction Stop
    }
 }
@@ -34,10 +34,10 @@ Describe 'Taskbar' {
       $initialState = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Get -Property @{}
 
       $parameters = @{
-         Alignment      = 'KeepCurrentValue';
-         HideLabelsMode = 'KeepCurrentValue';
-         SearchboxMode  = 'KeepCurrentValue';
-         TaskViewButton = 'KeepCurrentValue';
+         Alignment      = 'KeepCurrentValue'
+         HideLabelsMode = 'KeepCurrentValue'
+         SearchboxMode  = 'KeepCurrentValue'
+         TaskViewButton = 'KeepCurrentValue'
          WidgetsButton  = 'KeepCurrentValue'
       }
 
@@ -61,10 +61,10 @@ Describe 'Taskbar' {
       $desiredTaskViewButton = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1)
       $desiredWidgetsButton = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1)
 
-      $desiredState = @{ Alignment = $desiredAlignment;
-         HideLabelsMode            = $desiredHideLabelsMode;
-         SearchboxMode             = $desiredSearchboxMode;
-         TaskViewButton            = $desiredTaskViewButton;
+      $desiredState = @{ Alignment = $desiredAlignment
+         HideLabelsMode            = $desiredHideLabelsMode
+         SearchboxMode             = $desiredSearchboxMode
+         TaskViewButton            = $desiredTaskViewButton
          WidgetsButton             = $desiredWidgetsButton
       }
 
@@ -84,8 +84,8 @@ Describe 'WindowsExplorer' {
       $initialState = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Get -Property @{}
 
       $parameters = @{
-         FileExtensions = 'KeepCurrentValue';
-         HiddenFiles    = 'KeepCurrentValue';
+         FileExtensions = 'KeepCurrentValue'
+         HiddenFiles    = 'KeepCurrentValue'
          ItemCheckBoxes = 'KeepCurrentValue'
       }
 
@@ -107,8 +107,8 @@ Describe 'WindowsExplorer' {
       $desiredItemCheckBoxes = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1)
 
       $desiredState = @{
-         FileExtensions = $desiredFileExtensions;
-         HiddenFiles    = $desiredHiddenFiles;
+         FileExtensions = $desiredFileExtensions
+         HiddenFiles    = $desiredHiddenFiles
          ItemCheckBoxes = $desiredItemCheckBoxes
       }
 
@@ -171,6 +171,28 @@ Describe 'EnableRemoteDesktop' {
    }
 }
 
+Describe 'EnableLongPathSupport' {
+   It 'Sets Enabled' {
+      $desiredLongPathsBehavior = [Ensure]::Present
+      $desiredState = @{ Ensure = $desiredLongPathsBehavior }
+
+      Invoke-DscResource -Name EnableLongPathSupport -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState
+
+      $finalState = Invoke-DscResource -Name EnableLongPathSupport -ModuleName Microsoft.Windows.Developer -Method Get -Property @{}
+      $finalState.Ensure | Should -Be $desiredLongPathsBehavior
+   }
+
+   It 'Sets Disabled' {
+      $desiredLongPathsBehavior = [Ensure]::Absent
+      $desiredState = @{ Ensure = $desiredLongPathsBehavior }
+
+      Invoke-DscResource -Name EnableLongPathSupport -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState
+
+      $finalState = Invoke-DscResource -Name EnableLongPathSupport -ModuleName Microsoft.Windows.Developer -Method Get -Property @{}
+      $finalState.Ensure | Should -Be $desiredLongPathsBehavior
+   }
+}
+
 AfterAll {
-   $env:TestRegistryPath = ""
+   $env:TestRegistryPath = ''
 }


Reviews:
user: login: AmelBawa-msft
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-02T21:30:51Z
user: login: Trenly
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-02T21:34:24Z
user: login: AmelBawa-msft
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-02T22:13:30Z
user: login: Trenly
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-02T22:18:14Z
user: login: AmelBawa-msft
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-02T22:41:31Z

Review comments:
diff_hunk: @@ -171,6 +171,28 @@ Describe 'EnableRemoteDesktop' {
    }
 }
 
+Describe 'EnableLongPathSupport' {
+   It 'Sets Enabled' {
+      $desiredLongPathsBehavior = [Ensure]::Present
+      $desiredState = @{ Ensure = $desiredLongPathsBehavior }
+
+      Invoke-DscResource -Name EnableRemoteDesktop -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState
path: tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1
user: login: AmelBawa-msft
body: Should this be `EnableLongPathSupport`?
created_at: 2025-04-02T21:30:50Z
author_association: CONTRIBUTOR
diff_hunk: @@ -171,6 +171,28 @@ Describe 'EnableRemoteDesktop' {
    }
 }
 
+Describe 'EnableLongPathSupport' {
+   It 'Sets Enabled' {
+      $desiredLongPathsBehavior = [Ensure]::Present
+      $desiredState = @{ Ensure = $desiredLongPathsBehavior }
+
+      Invoke-DscResource -Name EnableRemoteDesktop -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState
path: tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1
user: login: Trenly
body: Yep
created_at: 2025-04-02T21:34:24Z
author_association: CONTRIBUTOR
diff_hunk: @@ -135,6 +135,7 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) {
     $global:SearchRegistryPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Search\'
     $global:UACRegistryPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\'
     $global:RemoteDesktopRegistryPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server'
+    $global:LongPathsRegistryPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem\'
path: resources/Microsoft.Windows.Developer/Microsoft.Windows.Developer.psm1
user: login: AmelBawa-msft
body: We need to add `$global:LongPathsRegistryPath` in the else statement to unblock the new unit tests 😉
created_at: 2025-04-02T22:13:30Z
author_association: CONTRIBUTOR
diff_hunk: @@ -135,6 +135,7 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) {
     $global:SearchRegistryPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Search\'
     $global:UACRegistryPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\'
     $global:RemoteDesktopRegistryPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server'
+    $global:LongPathsRegistryPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem\'
path: resources/Microsoft.Windows.Developer/Microsoft.Windows.Developer.psm1
user: login: Trenly
body: Yep; moving too fast for my own good
created_at: 2025-04-02T22:18:14Z
author_association: CONTRIBUTOR

PR comments:
user: login: AmelBawa-msft
created_at: 2025-04-02T21:37:06Z
body: /azp run
author_association: CONTRIBUTOR
user: login: azure-pipelines[bot]
created_at: 2025-04-02T21:37:16Z
body: <samp>
Azure Pipelines successfully started running 1 pipeline(s).<br>

</samp>
author_association: NONE
user: login: AmelBawa-msft
created_at: 2025-04-02T22:28:41Z
body: /azp run
author_association: CONTRIBUTOR
user: login: azure-pipelines[bot]
created_at: 2025-04-02T22:28:51Z
body: <samp>
Azure Pipelines successfully started running 1 pipeline(s).<br>

</samp>
author_association: NONE