diff --git a/.gitignore b/.gitignore index 0bb7291..c4e9109 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,11 @@ ScaffoldingReadMe.txt *.nupkg # NuGet Symbol Packages *.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/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 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 new file mode 100644 index 0000000..6386b7a --- /dev/null +++ b/util/update-versionnumber.ps1 @@ -0,0 +1,74 @@ +<# +.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 "$($MyInvocation.MyCommand.Name) - 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 "$($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 { + Write-Host "$($MyInvocation.MyCommand.Name) - Processing file: $($file.FullName)" -ForegroundColor Yellow + + # Read the file content as an array of lines + $fileContent = Get-Content -Path $file.FullName + + # Update the ModuleVersion line + $updatedContent = $fileContent -replace "ModuleVersion\s*=\s*[`"|\'](.*?)[`"|\']", "ModuleVersion = '$Version'" + + # 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 "$($MyInvocation.MyCommand.Name) - Failed to update file: $($file.FullName). Error: $_" + } +} + +Write-Host "$($MyInvocation.MyCommand.Name) - ModuleVersion update completed." -ForegroundColor Cyan \ No newline at end of file