Clear-Solution.psm1
<#
.Synopsis Automatic Publish Tool (APT) .DESCRIPTION Clear solution .EXAMPLE Clear-Solution Project.sln .EXAMPLE Clear-Solution Project.sln -ClearNugetCache -ClearVisualStudio .NOTES Author: Imrich Szolik #> function Clear-Solution { [CmdletBinding()] param ( [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$false, HelpMessage="Solution bin, obj, packages & output folders")] [string] $SolutionPath, [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$false, HelpMessage="Solution bin, obj, packages & output folders")] [string] $OutputPath, [switch] [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$false, HelpMessage="Clear nuget local package cache")] $ClearNugetCache, [switch] [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$false, HelpMessage="Clear VisualStudio .vs folder")] $ClearVisualStudio, [switch] [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$false, HelpMessage="Stop all builder process")] $ClearBuilder ) begin { if ($null -eq (Get-Command nuget -ErrorAction SilentlyContinue)) { throw "Please install nuget CLI. [ Download https://www.nuget.org/downloads & add copy nuget.exe to %userprofile%\.dotnet\tools ]" } } process { # if($ClearBuilder.IsPresent -or $ClearNugetCache.IsPresent){ ##remove process for comlilation before clear Write-Verbose "Builder cleanup..." Get-Process | Where-Object { $_.Name -eq 'dotnet' } | Stop-Process -ErrorAction SilentlyContinue Get-Process | Where-Object { $_.Name -eq 'MSBuild' } | Stop-Process -ErrorAction SilentlyContinue } # if($ClearNugetCache.IsPresent){ Write-Host "#### APT CLR [nugets] ####" Write-Verbose "Nuget cache cleanup..." nuget locals all -clear } Write-Host "#### APT CLR [$SolutionPath] ####" #soluton cleanup if($ClearVisualStudio.IsPresent){ Write-Verbose "Removing '.vs' folder..." Remove-Item -Path "$SolutionPath/.vs" -Force -Recurse -ErrorAction SilentlyContinue } # Write-Verbose "Removing 'packages' folder..." Remove-Item -Path "$SolutionPath/packages" -Force -Recurse -ErrorAction SilentlyContinue Get-ChildItem $SolutionPath -Recurse -File -Filter packages.lock.json | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue # Write-Verbose "Removing 'obj' folders..." Get-ChildItem $SolutionPath -Recurse -Directory -Filter obj | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue # Write-Verbose "Removing 'bin' folders..." Get-ChildItem $SolutionPath -Recurse -Directory -Filter bin | Where-Object -Property FullName -NotMatch node_modules | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue #output cleanup if(-not [string]::IsNullOrEmpty($OutputPath)){ Write-Verbose "Removing 'output' folder..." Remove-Item -Path $OutputPath -Force -Recurse -ErrorAction SilentlyContinue } } end { } } Export-ModuleMember -Function Clear-Solution # SIG # Begin signature block # MIIIEwYJKoZIhvcNAQcCoIIIBDCCCAACAQExDzANBglghkgBZQMEAgEFADB5Bgor # BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG # KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCANUL6Zp7CDkkgg # 7F0qvGzhvUvMTao8MnblMKtT2ZxW36CCBQ8wggULMIIC86ADAgECAgIApTANBgkq # hkiG9w0BAQsFADCBoDELMAkGA1UEBhMCU0sxETAPBgNVBAgTCFNsb3Zha2lhMRMw # EQYDVQQHEwpCcmF0aXNsYXZhMRMwEQYDVQQKEwpMb210ZWMuY29tMSswKQYDVQQD # EyJMb210ZWMuY29tIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MScwJQYJKoZIhvcN # AQkBFhhJbXJpY2guU3pvbGlrQGxvbXRlYy5jb20wHhcNMTkwMzI2MTUwNDQzWhcN # MzAwMTAxMDAwMDAwWjCBkzELMAkGA1UEBhMCU0sxETAPBgNVBAgTCFNsb3Zha2lh # MRMwEQYDVQQHEwpCcmF0aXNsYXZhMRMwEQYDVQQKEwpMb210ZWMuY29tMR4wHAYD # VQQDExVMb210ZWMuY29tIFBvd2Vyc2hlbGwxJzAlBgkqhkiG9w0BC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hNNRoiVlQgJ7NgO0UV+vU2lgiscpUSxEt # xKN+450r49su06NA6zsyn3CELUmVkPyjx5fyizwt9KxVuYOUSEb32Y7QCffHJ1qt # F6SuQrKbgb/24y7cCDW6PDVRvPOySUlKu9sPykICDjvzXBvjYEILM7AmtYCIBGQg # imBsQvTEoXJXiwAOi1XNz3LxcjQHQ/ZM4zGCAlowggJWAgEBMIGnMIGgMQswCQYD # VQQGEwJTSzERMA8GA1UECBMIU2xvdmFraWExEzARBgNVBAcTCkJyYXRpc2xhdmEx # EzARBgNVBAoTCkxvbXRlYy5jb20xKzApBgNVBAMTIkxvbXRlYy5jb20gQ2VydGlm # aWNhdGlvbiBBdXRob3JpdHkxJzAlBgkqhkiG9w0BCQEWGEltcmljaC5Tem9saWtA # bG9tdGVjLmNvbQICAKUwDQYJYIZIAWUDBAIBBQCggYQwGAYKKwYBBAGCNwIBDDEK # MAigAoAAoQKAADAZBgkqhkiG9w0BCQMxDAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3 # AgELMQ4wDAYKKwYBBAGCNwIBFjAvBgkqhkiG9w0BCQQxIgQglVxyPwjkMs/8Wdsf # Jv0c9KYGQ4P/EpGUuuR6/EicPGowDQYJKoZIhvcNAQEBBQAEggEAfyAKzafWeD4v # BEEQYA0P8A6YZOPqkZhI72foAXnKt9NsHPYLeLQxMTQMGhYaTXhYO6yECsgopAti # w5tTNifaLYdzRLI9UDmtaN9b9S90WYWSkpseKrD+OdC8H+HjPJFMcxDVncwug/EI # IRHN+Nx4MRib7ofCSBn8bV7CNrFTQAVUGvjfjErykg2j+t3/JaRKWVo+INuZTsIe # tlqNzr+0YrW1TQv7ob0tmbCo1Ba0NzfjvTPNWNjmaV+mLlmhxw/g1F/8d7IYu/zx # kvAA6DNIT5Qerio6CDy6nkSNzcDlaodA5cENnPQw9n1L1ZgXhLoYq2uDGlW+Iclm # 316xVQmXIA== # SIG # End signature block |