Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
~$*
Expand Down
52 changes: 47 additions & 5 deletions Microsoft.AzureStack.Util.ConvertNetwork.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,46 @@
<Version Condition="'$(Version)'==''">1.0.0</Version>
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
<BinariesBuildDirectory>$(MSBuildProjectDirectory)\out</BinariesBuildDirectory>
<Package>$(MSBuildProjectDirectory)\out\packages</Package>
<PesterVersion>5.2.0</PesterVersion>
<!-- Set the custom NuGet packages directory -->
<RestorePackagesPath>$(MSBuildProjectDirectory)\out\packages</RestorePackagesPath>
<PesterVersion>5.2.0</PesterVersion> <!--Used for Unit-Testing only -->
<RestorePackagesPath>$(MSBuildProjectDirectory)\packages</RestorePackagesPath>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageTags>AzureStack, Utility, Network, Subneting</PackageTags>
<RepositoryUrl>https://github.com/microsoft/$(ProjectName)</RepositoryUrl>
<Description>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.</Description>
</PropertyGroup>

<ItemGroup>
<!-- NuGet Import -->
<PackageReference Include="Pester" Version="$(PesterVersion)" />
</ItemGroup>

<Target Name="LogNuGetPackages" AfterTargets="Restore">
<ItemGroup>
<!-- Collect all restored NuGet packages -->
<RestoredPackages Include="$(RestorePackagesPath)\**\*.nupkg" />
</ItemGroup>
<Message Text="[LogNuGetPackages] Restored NuGet Package: %(RestoredPackages.Identity)" Importance="high" />
</Target>

<Target Name="CustomClean" BeforeTargets="Clean">
<Message Text="Cleaning up the project...$(BinariesBuildDirectory)" Importance="high" Condition="Exists('$(BinariesBuildDirectory)')" />
<Message Text="Cleaning up the project...$(RestorePackagesPath)" Importance="high" Condition="Exists('$(RestorePackagesPath)')" />
<Message Text="Cleaning up the project...$(MSBuildProjectDirectory)\PowerShell" Importance="high" Condition="Exists('$(MSBuildProjectDirectory)\PowerShell')" />
<Message Text="Cleaning up the project...$(MSBuildProjectDirectory)\temp" Importance="high" Condition="Exists('$(MSBuildProjectDirectory)\temp')" />
<Message Text="Cleaning up the project...$(MSBuildProjectDirectory)\obj" Importance="high" Condition="Exists('$(MSBuildProjectDirectory)\obj')" />
<Message Text="Cleaning up the project...$(MSBuildProjectDirectory)\bin" Importance="high" Condition="Exists('$(MSBuildProjectDirectory)\bin')" />

<RemoveDir Directories="$(BinariesBuildDirectory)" Condition="Exists('$(BinariesBuildDirectory)')" />
<RemoveDir Directories="$(RestorePackagesPath)" Condition="Exists('$(RestorePackagesPath)')" />
<RemoveDir Directories="$(MSBuildProjectDirectory)\PowerShell" Condition="Exists('$(MSBuildProjectDirectory)\PowerShell')" />
<RemoveDir Directories="$(MSBuildProjectDirectory)\temp" Condition="Exists('$(MSBuildProjectDirectory)\temp')" />
<RemoveDir Directories="$(MSBuildProjectDirectory)\obj" Condition="Exists('$(MSBuildProjectDirectory)\obj')" />
<RemoveDir Directories="$(MSBuildProjectDirectory)\bin" Condition="Exists('$(MSBuildProjectDirectory)\bin')" />
</Target>

<Target Name="PlaceFiles" AfterTargets="Build">
<Message Text="[PlaceFiles] Copying files to $(BinariesBuildDirectory)\$(ProjectName)\Microsoft.AzureStack.Util.ConvertNetwork.psd1" Importance="high" />
<Message Text="[PlaceFiles] Copying files to $(BinariesBuildDirectory)\$(ProjectName)\Microsoft.AzureStack.Util.ConvertNetwork.psm1" Importance="high" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\src\Microsoft.AzureStack.Util.ConvertNetwork.psd1" DestinationFolder="$(BinariesBuildDirectory)\$(ProjectName)" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\src\Microsoft.AzureStack.Util.ConvertNetwork.psm1" DestinationFolder="$(BinariesBuildDirectory)\$(ProjectName)" />
</Target>
Expand All @@ -27,7 +56,20 @@
<ItemGroup>
<PesterFiles Include="$(RestorePackagesPath)\pester\$(PesterVersion)\tools\**\*" Exclude="*.nupkg;*.nuspec" />
</ItemGroup>
<Copy SourceFiles="@(PesterFiles)" DestinationFolder="$(BinariesBuildDirectory)\PowerShell\Modules\Pester\$(PesterVersion)\%(RecursiveDir)" />
<Copy SourceFiles="@(PesterFiles)" DestinationFolder="$(MSBuildProjectDirectory)\PowerShell\Modules\Pester\$(PesterVersion)\%(RecursiveDir)" />
<Message Text="[CopyPester] Copying Pester files to $(MSBuildProjectDirectory)\PowerShell\Modules\Pester\$(PesterVersion)" Importance="high" Condition="Exists('$(RestorePackagesPath)\pester')" />
</Target>

<Target Name="UpdateVersionNumber" AfterTargets="PlaceFiles">
<Message Text="[UpdateVersionNumber] Running update-versionnumber.ps1" Importance="high" Condition="Exists('$(MSBuildProjectDirectory)\util\update-versionnumber.ps1')" />
<Exec Command="pwsh -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command &quot;&amp; { &amp; '$(MSBuildProjectDirectory)\util\update-versionnumber.ps1' -Directory '$(BinariesBuildDirectory)\$(ProjectName)' -Version '$(Version)' }&quot;" />
<Message Text="[UpdateVersionNumber] Finished running update-versionnumber.ps1" Importance="high" Condition="Exists('$(MSBuildProjectDirectory)\util\update-versionnumber.ps1')" />
</Target>

<Target Name="NuSpecJob" AfterTargets="UpdateVersionNumber">
<Message Text="[NuSpecJob] Running set-nuspecfile.ps1" Importance="high" Condition="Exists('$(MSBuildProjectDirectory)\util\set-nuspecfile.ps1')" />
<Exec Command="pwsh -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command &quot;&amp; { &amp; '$(MSBuildProjectDirectory)\util\set-nuspecfile.ps1' -DirectoryPath '$(BinariesBuildDirectory)\$(ProjectName)' -PackageName '$(ProjectName)' -Version '$(Version)' -RepoUrl '$(RepositoryUrl)' -Description '$(Description)'}&quot;" />
<Message Text="[NuSpecJob] Generating NuGet spec file" Importance="high" Condition="Exists('$(BinariesBuildDirectory)\$(ProjectName)\$(ProjectName).nuspec')" />
</Target>

</Project>
2 changes: 1 addition & 1 deletion tests/setupTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions util/set-nuspecfile.ps1
Original file line number Diff line number Diff line change
@@ -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 = @"
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>$PackageName</id>
<version>$Version</version>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<license type="expression">MIT</license>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<projectUrl>$RepoUrl</projectUrl>
<description>$Description</description>
<tags>AzureStack, Utility, Network, Subneting</tags>
<copyright>Copyright © $(Get-Date -Format yyyy)</copyright>
<repository url="$RepoUrl" type="git" commit="$(git rev-parse HEAD)" />
</metadata>
<files>
<file src="$($DirectoryPath)\*" target="content" exclude="**\*.nupkg;**\*.nuspec" />
</files>
</package>
"@

# 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!"
74 changes: 74 additions & 0 deletions util/update-versionnumber.ps1
Original file line number Diff line number Diff line change
@@ -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