From d66394e8d99fdba815e05f4587093836773cb753 Mon Sep 17 00:00:00 2001 From: Eric Marquez Date: Wed, 9 Apr 2025 07:59:14 -0700 Subject: [PATCH 1/5] gitignore added out directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 35063fc..0bb7291 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ bld/ [Oo]bj/ [Ll]og/ [Ll]ogs/ +[Oo]ut/ # .NET Core project.lock.json From 52e762e64c70e98851ce4c6f8ca650ceb14f219a Mon Sep 17 00:00:00 2001 From: Eric Marquez Date: Fri, 11 Apr 2025 13:44:39 -0700 Subject: [PATCH 2/5] Add .sln file to .gitignore to exclude Visual Studio solution files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 0bb7291..a0ed3f9 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,9 @@ ScaffoldingReadMe.txt *.nupkg # NuGet Symbol Packages *.snupkg +# ignore sln file generated by vscode. +*.sln + # Others ~$* From d5f95b0c0cefb78106ec43764c4e1b7febef02ce Mon Sep 17 00:00:00 2001 From: Eric Marquez Date: Fri, 11 Apr 2025 13:44:54 -0700 Subject: [PATCH 3/5] Add script to update ModuleVersion in PowerShell module manifests --- util/update-versionnumber.ps1 | 71 +++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 util/update-versionnumber.ps1 diff --git a/util/update-versionnumber.ps1 b/util/update-versionnumber.ps1 new file mode 100644 index 0000000..c54554a --- /dev/null +++ b/util/update-versionnumber.ps1 @@ -0,0 +1,71 @@ +<# +.SYNOPSIS +This script updates the `ModuleVersion` field in PowerShell module manifest files (*.psd1). + +.DESCRIPTION +The script performs a recursive search for PowerShell module manifest files (*.psd1) in the specified directory. +It updates the `ModuleVersion` field in each file with the provided version number. + +.PARAMETER Version +The new version number to set in the `ModuleVersion` field. Must conform to the [version] type. + +.PARAMETER Directory +The directory to search for *.psd1 files. The search is recursive. + +.EXAMPLE +.\update-versionnumber.ps1 -Version "1.2.3" -Directory "C:\Modules" + +This command updates the `ModuleVersion` field in all *.psd1 files under "C:\Modules" to "1.2.3". + +.EXAMPLE +.\update-versionnumber.ps1 -Version "2.0.0" -Directory "." + +This command updates the `ModuleVersion` field in all *.psd1 files in the current directory and its subdirectories to "2.0.0". + +.NOTES +- Ensure you have write permissions for the files being updated. +- Use semantic versioning for the version number (e.g., "1.0.0"). +#> + +param ( + [Parameter(Mandatory = $true)] + [version]$Version, # Enforces the [version] type for the parameter + + [Parameter(Mandatory = $true)] + [string]$Directory +) + +# Validate the directory +if (-not (Test-Path -Path $Directory)) { + Write-Error "The specified directory does not exist: $Directory" + exit 1 +} + +# Perform a recursive search for *.psd1 files +$psd1Files = Get-ChildItem -Path $Directory -Recurse -Filter "*.psd1" + +if ($psd1Files.Count -eq 0) { + Write-Host "No *.psd1 files found in the specified directory: $Directory" + exit 0 +} + +# Update the ModuleVersion in each *.psd1 file +foreach ($file in $psd1Files) { + try { + # Import the .psd1 file as a hashtable + $moduleData = Import-PowerShellDataFile -Path $file.FullName + + # Update the ModuleVersion field + $moduleData.ModuleVersion = $Version.ToString() + + # Write the updated hashtable back to the file + $moduleData | Out-File -FilePath $file.FullName -Encoding UTF8 + + Write-Host "Updated ModuleVersion in file: $($file.FullName)" -ForegroundColor Green + } + catch { + Write-Error "Failed to update file: $($file.FullName). Error: $_" + } +} + +Write-Host "ModuleVersion update completed." -ForegroundColor Cyan \ No newline at end of file From 4f57f25b672a090b25b687c41b6d68d0df7e5c5c Mon Sep 17 00:00:00 2001 From: Eric Marquez Date: Fri, 11 Apr 2025 16:51:48 -0700 Subject: [PATCH 4/5] Enhance project structure: update .gitignore to exclude package directories, add set-nuspecfile.ps1 for NuGet package generation, and improve update-versionnumber.ps1 with detailed logging. --- .gitignore | 2 + ...soft.AzureStack.Util.ConvertNetwork.csproj | 52 +++++++++++++++++-- util/set-nuspecfile.ps1 | 48 +++++++++++++++++ util/update-versionnumber.ps1 | 25 +++++---- 4 files changed, 111 insertions(+), 16 deletions(-) create mode 100644 util/set-nuspecfile.ps1 diff --git a/.gitignore b/.gitignore index a0ed3f9..c4e9109 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,8 @@ ScaffoldingReadMe.txt *.snupkg # ignore sln file generated by vscode. *.sln +[pP]ackages/ +[pP]owerShell/[mM]odules/ # Others diff --git a/Microsoft.AzureStack.Util.ConvertNetwork.csproj b/Microsoft.AzureStack.Util.ConvertNetwork.csproj index 463451c..220a1a3 100644 --- a/Microsoft.AzureStack.Util.ConvertNetwork.csproj +++ b/Microsoft.AzureStack.Util.ConvertNetwork.csproj @@ -7,17 +7,46 @@ 1.0.0 Debug $(MSBuildProjectDirectory)\out - $(MSBuildProjectDirectory)\out\packages - 5.2.0 - - $(MSBuildProjectDirectory)\out\packages + 5.2.0 + $(MSBuildProjectDirectory)\packages + false + AzureStack, Utility, Network, Subneting + https://github.com/microsoft/$(ProjectName) + Microsoft.AzureStack.Util.ConvertNetwork is a PowerShell module that provides utilities for working with IPv4 networks. It includes functions to calculate subnet masks, CIDR values, broadcast addresses, and more. This project is designed to simplify network-related operations for developers and IT professionals. + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -27,7 +56,20 @@ - + + + + + + + + + + + + + + diff --git a/util/set-nuspecfile.ps1 b/util/set-nuspecfile.ps1 new file mode 100644 index 0000000..5dccfa7 --- /dev/null +++ b/util/set-nuspecfile.ps1 @@ -0,0 +1,48 @@ +param ( + [Parameter(Mandatory = $true)] + [string]$DirectoryPath, # Root directory path where the package is located + + [Parameter(Mandatory = $true)] + [string]$PackageName, # Name of the NuGet package + + [Parameter(Mandatory = $true)] + [string]$Version, # Version of the NuGet package (e.g., 1.0.0) + + [Parameter(Mandatory = $true)] + [string]$RepoUrl, + + [Parameter(Mandatory = $true)] + [string]$Description # Description of the NuGet package +) + +# Define the output directory for the nuspec file +$NuspecFilePath = Join-Path -Path $DirectoryPath -ChildPath "$PackageName.nuspec" + +# Generate the .nuspec content +$NuspecContent = @" + + + + $PackageName + $Version + Microsoft + Microsoft + MIT + false + $RepoUrl + $Description + AzureStack, Utility, Network, Subneting + Copyright © $(Get-Date -Format yyyy) + + + + + + +"@ + +# Write the .nuspec file +Write-Host "$($MyInvocation.MyCommand.Name) - Generating .nuspec file at: $NuspecFilePath" +$NuspecContent | Set-Content -Path $NuspecFilePath -Encoding UTF8 + +Write-Host "$($MyInvocation.MyCommand.Name) - NuSpec file generated successfully!" \ No newline at end of file diff --git a/util/update-versionnumber.ps1 b/util/update-versionnumber.ps1 index c54554a..6386b7a 100644 --- a/util/update-versionnumber.ps1 +++ b/util/update-versionnumber.ps1 @@ -37,7 +37,7 @@ param ( # Validate the directory if (-not (Test-Path -Path $Directory)) { - Write-Error "The specified directory does not exist: $Directory" + Write-Error "$($MyInvocation.MyCommand.Name) - The specified directory does not exist: $Directory" exit 1 } @@ -45,27 +45,30 @@ if (-not (Test-Path -Path $Directory)) { $psd1Files = Get-ChildItem -Path $Directory -Recurse -Filter "*.psd1" if ($psd1Files.Count -eq 0) { - Write-Host "No *.psd1 files found in the specified directory: $Directory" + Write-Host "$($MyInvocation.MyCommand.Name) -No *.psd1 files found in the specified directory: $Directory" exit 0 } # Update the ModuleVersion in each *.psd1 file foreach ($file in $psd1Files) { try { - # Import the .psd1 file as a hashtable - $moduleData = Import-PowerShellDataFile -Path $file.FullName + Write-Host "$($MyInvocation.MyCommand.Name) - Processing file: $($file.FullName)" -ForegroundColor Yellow - # Update the ModuleVersion field - $moduleData.ModuleVersion = $Version.ToString() + # Read the file content as an array of lines + $fileContent = Get-Content -Path $file.FullName - # Write the updated hashtable back to the file - $moduleData | Out-File -FilePath $file.FullName -Encoding UTF8 + # Update the ModuleVersion line + $updatedContent = $fileContent -replace "ModuleVersion\s*=\s*[`"|\'](.*?)[`"|\']", "ModuleVersion = '$Version'" - Write-Host "Updated ModuleVersion in file: $($file.FullName)" -ForegroundColor Green + # Write the updated content back to the file + $updatedContent | Set-Content -Path $file.FullName -Encoding UTF8 + + Write-Host "$($MyInvocation.MyCommand.Name) - Updated ModuleVersion in file: $($file.FullName)" -ForegroundColor Green + Write-Host "$($MyInvocation.MyCommand.Name) - New ModuleVersion: $Version" -ForegroundColor Green } catch { - Write-Error "Failed to update file: $($file.FullName). Error: $_" + Write-Error "$($MyInvocation.MyCommand.Name) - Failed to update file: $($file.FullName). Error: $_" } } -Write-Host "ModuleVersion update completed." -ForegroundColor Cyan \ No newline at end of file +Write-Host "$($MyInvocation.MyCommand.Name) - ModuleVersion update completed." -ForegroundColor Cyan \ No newline at end of file From 38e3e0bbb66d086f299852226c6a8b823508470f Mon Sep 17 00:00:00 2001 From: Eric Marquez Date: Fri, 11 Apr 2025 16:59:19 -0700 Subject: [PATCH 5/5] updated the unit-test helper to check in the new directory. --- tests/setupTest.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/setupTest.ps1 b/tests/setupTest.ps1 index e2e2ec1..bc57be1 100644 --- a/tests/setupTest.ps1 +++ b/tests/setupTest.ps1 @@ -3,7 +3,7 @@ $parentPath = (Get-Item $PSScriptRoot).Parent.FullName Remove-Module Pester -Force -ErrorAction SilentlyContinue -Import-Module (Join-Path -Path $parentPath -ChildPath 'out\PowerShell\Modules\Pester') -Force +Import-Module (Join-Path -Path $parentPath -ChildPath 'PowerShell\Modules\Pester') -Force New-Item -Path (Join-Path -Path $parentPath -ChildPath 'out\Tests') -ItemType Directory -Force | Out-Null $config = New-PesterConfiguration