@@ -670,7 +670,20 @@ function Add-Module {
670
670
$moduleSourcePath = Join-Path - Path $Path - ChildPath $moduleManifest
671
671
$file = Get-Item $moduleSourcePath
672
672
Import-LocalizedData - BindingVariable ModuleMetadata - BaseDirectory $file.DirectoryName - FileName $file.Name
673
+
674
+ $moduleVersion = $ModuleMetadata.ModuleVersion.ToString ()
675
+ if ((! $IsNetCore ) -and ($ModuleMetadata.PrivateData.PSData.Prerelease -ne $null )) {
676
+ $moduleVersion += (" -" + $ModuleMetadata.PrivateData.PSData.Prerelease -replace " --" , " -" )
677
+ }
673
678
679
+ if (Find-Module - Name $moduleName - Repository $TempRepo - RequiredVersion $moduleVersion - AllowPrerelease - ErrorAction SilentlyContinue)
680
+ {
681
+ Write-Output " Existing module found: $moduleName "
682
+ $moduleNupkgPath = Join-Path - Path $TempRepoPath - ChildPath ($moduleName + " ." + $moduleVersion + " .nupkg" )
683
+ Write-Output " Deleting the module: $moduleNupkgPath "
684
+ Remove-Item - Path $moduleNupkgPath - Force
685
+ }
686
+
674
687
Write-Output " Publishing the module $moduleName "
675
688
Publish-Module - Path $Path - Repository $TempRepo - Force | Out-Null
676
689
Write-Output " $moduleName published"
@@ -683,11 +696,6 @@ function Add-Module {
683
696
}
684
697
Write-Output " No root module found, creating"
685
698
686
- $moduleVersion = $ModuleMetadata.ModuleVersion.ToString ()
687
- if ((! $IsNetCore ) -and ($ModuleMetadata.PrivateData.PSData.Prerelease -ne $null )) {
688
- $moduleVersion += (" -" + $ModuleMetadata.PrivateData.PSData.Prerelease -replace " --" , " -" )
689
- }
690
-
691
699
Write-Output " Changing to local repository directory for module modifications $TempRepoPath "
692
700
Push-Location $TempRepoPath
693
701
0 commit comments