diff --git a/scripts/Modules/Saritasa.Build/1.15.0/PSGetModuleInfo.xml b/scripts/Modules/Saritasa.Build/1.16.0/PSGetModuleInfo.xml similarity index 93% rename from scripts/Modules/Saritasa.Build/1.15.0/PSGetModuleInfo.xml rename to scripts/Modules/Saritasa.Build/1.16.0/PSGetModuleInfo.xml index 6d4b355e..c771ea72 100644 Binary files a/scripts/Modules/Saritasa.Build/1.15.0/PSGetModuleInfo.xml and b/scripts/Modules/Saritasa.Build/1.16.0/PSGetModuleInfo.xml differ diff --git a/scripts/Modules/Saritasa.Build/1.15.0/Saritasa.Build.psd1 b/scripts/Modules/Saritasa.Build/1.16.0/Saritasa.Build.psd1 similarity index 99% rename from scripts/Modules/Saritasa.Build/1.15.0/Saritasa.Build.psd1 rename to scripts/Modules/Saritasa.Build/1.16.0/Saritasa.Build.psd1 index 182e0556..247ccd57 100644 --- a/scripts/Modules/Saritasa.Build/1.15.0/Saritasa.Build.psd1 +++ b/scripts/Modules/Saritasa.Build/1.16.0/Saritasa.Build.psd1 @@ -12,7 +12,7 @@ RootModule = 'Saritasa.Build' # Version number of this module. -ModuleVersion = '1.15.0' +ModuleVersion = '1.16.0' # ID used to uniquely identify this module GUID = '5d34804a-169a-4fb1-bc0d-cc81f925f992' diff --git a/scripts/Modules/Saritasa.Build/1.15.0/Saritasa.Build.psm1 b/scripts/Modules/Saritasa.Build/1.16.0/Saritasa.Build.psm1 similarity index 72% rename from scripts/Modules/Saritasa.Build/1.15.0/Saritasa.Build.psm1 rename to scripts/Modules/Saritasa.Build/1.16.0/Saritasa.Build.psm1 index cc579381..ce7e1090 100644 --- a/scripts/Modules/Saritasa.Build/1.15.0/Saritasa.Build.psm1 +++ b/scripts/Modules/Saritasa.Build/1.16.0/Saritasa.Build.psm1 @@ -1,6 +1,11 @@ <# .SYNOPSIS -Downloads nuget.exe to specified location. +Downloads latest nuget.exe to specified location. + +.EXAMPLE +Install-NugetCli . + +Install nuget into current directory #> function Install-NugetCli { @@ -26,17 +31,28 @@ function Install-NugetCli <# .SYNOPSIS Restores packages for solution, project or packages.config. + +.EXAMPLE +Invoke-NugetRestore .\..\myapp.sln + +Restores all packages for myapp solution. + +.NOTES +If nuget command is not found - it will be downloaded to current directory. #> function Invoke-NugetRestore { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, HelpMessage = 'Path to solution. All NuGet packages from included projects will be restored.', ParameterSetName = 'Solution')] + # Path to solution. All NuGet packages from included projects will be restored. + [Parameter(Mandatory = $true, ParameterSetName = 'Solution')] [string] $SolutionPath, - [Parameter(Mandatory = $true, HelpMessage = 'Path to project or packages.config.', ParameterSetName = 'Project')] + # Path to project or packages.config. + [Parameter(Mandatory = $true, ParameterSetName = 'Project')] [string] $ProjectPath, - [Parameter(Mandatory = $true, HelpMessage = 'Path to the solution directory. Not valid when restoring packages for a solution.', ParameterSetName = 'Project')] + # Path to the solution directory. Not valid when restoring packages for a solution. + [Parameter(Mandatory = $true, ParameterSetName = 'Project')] [string] $SolutionDirectory ) @@ -71,14 +87,22 @@ function Invoke-NugetRestore } } +<# +.SYNOPSIS +Builds solution. + +.EXAMPLE +Invoke-SolutionBuild .\..\myapp.sln -Configuration Debug +#> function Invoke-SolutionBuild { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, HelpMessage = 'Path to solution.')] + # Path to solution. + [Parameter(Mandatory = $true)] [string] $SolutionPath, - [Parameter(HelpMessage = 'Build configuration (Release, Debug, etc.)')] + # Build configuration (Release, Debug, etc.) [string] $Configuration ) @@ -87,16 +111,32 @@ function Invoke-SolutionBuild Invoke-ProjectBuild $SolutionPath $Configuration } +<# +.SYNOPSIS +Builds project. + +.PARAMETER Target +Build the specified targets in the project. +Use a semicolon or comma to separate multiple targets. + +.EXAMPLE +Invoke-ProjectBuild .\..\Web\Web.csproj -Configuration 'Release' + +.NOTES +For more information about Target and BuildParams parameters, see MSBuild documentation. +#> function Invoke-ProjectBuild { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, HelpMessage = 'Path to project.')] + # Path to project. + [Parameter(Mandatory = $true)] [string] $ProjectPath, - [Parameter(HelpMessage = 'Build configuration (Release, Debug, etc.)')] + # Build configuration (Release, Debug, etc.) [string] $Configuration, [string] $Target = 'Build', + # Additional build parameters. [string[]] $BuildParams ) @@ -113,6 +153,12 @@ function Invoke-ProjectBuild .SYNOPSIS Update version numbers of AssemblyInfo.cs and AssemblyInfo.vb. +.DESCRIPTION +Updates version numbers in AssemblyInfo files located in current directory and all subdirectories. + +.EXAMPLE +Update-AssemblyInfoFile '6.3.1.1' + .NOTES Based on SetVersion script. http://www.luisrocha.net/2009/11/setting-assembly-version-with-windows.html @@ -123,7 +169,8 @@ function Update-AssemblyInfoFile [CmdletBinding(SupportsShouldProcess = $true)] param ( - [Parameter(Mandatory = $true, HelpMessage = 'Version string in major.minor.build.revision format.')] + # Version string in major.minor.build.revision format. + [Parameter(Mandatory = $true)] [string] $Version ) @@ -136,7 +183,7 @@ function Update-AssemblyInfoFile Get-ChildItem -r -Include AssemblyInfo.cs, AssemblyInfo.vb | ForEach-Object ` { - $filename = $_.Directory.ToString() + '\' + $_.Name + $filename = $_.FullName # If you are using a source control that requires to check-out files before # modifying them, make sure to check-out the file here. @@ -147,21 +194,34 @@ function Update-AssemblyInfoFile { (Get-Content $filename) | ForEach-Object ` { - ForEach-Object { $_ -replace $assemblyVersionPattern, $assemblyVersion } | - ForEach-Object { $_ -replace $fileVersionPattern, $fileVersion } + ($_ -replace $assemblyVersionPattern, $assemblyVersion) ` + -replace $fileVersionPattern, $fileVersion } | Set-Content $filename -Encoding UTF8 - Write-Information ($filename + ' -> ' + $Version) + Write-Information "$filename -> $Version" } } } +<# +.SYNOPSIS +Creates file from a template. + +.DESCRIPTION +Creates a config file from it's template. If file already exists, it will not be overridden. + +.EXAMPLE +Copy-DotnetConfig .\..\Web\Web.config.template + +Creates a Web.config file in Web folder from template. +#> function Copy-DotnetConfig { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, HelpMessage = 'Path to App.config.template or Web.config.template file.')] + # Path to App.config.template or Web.config.template file. + [Parameter(Mandatory = $true)] [string] $TemplateFilename ) @@ -178,6 +238,11 @@ function Copy-DotnetConfig .SYNOPSIS Run Entity Framework migrations. +.EXAMPLE +Invoke-EFMigrate ..\..\Domain\bin\Debug\Domain.dll + +Runs all migrations declared in Domain.dll file, using Domain.dll.config as configuration file + .NOTES In essential this command tries to find migrate.exe in packages and run it against specified configuration file. @@ -187,9 +252,10 @@ function Invoke-EFMigrate [CmdletBinding()] param ( - [Parameter(Mandatory = $true, HelpMessage = 'Path to assembly file with migrations.')] + # Path to assembly file with migrations. + [Parameter(Mandatory = $true)] [string] $MigrationAssembly, - [Parameter(HelpMessage = 'Path to assembly .config file. If not specified default or parent Web.config will be used.')] + # Path to assembly .config file. If not specified default or parent Web.config will be used. [string] $ConfigFilename ) @@ -220,7 +286,7 @@ function Invoke-EFMigrate { throw 'Cannot find packages directory.' } - Write-Information "Found $packagesDirectory.FullName" + Write-Information "Found $($packagesDirectory.FullName)" $migrateExeDirectory = Get-ChildItem $packagesDirectory.FullName 'EntityFramework.*' | Sort-Object { $_.Name } | Select-Object -Last 1 if (!$migrateExeDirectory) @@ -228,7 +294,7 @@ function Invoke-EFMigrate throw 'Cannot find entity framework package.' } $migrateExe = Join-Path $migrateExeDirectory.FullName '.\tools\migrate.exe' - Write-Information "Found $migrateExeDirectory.FullName" + Write-Information "Found $($migrateExeDirectory.FullName)" # Run migrate $workingDirectory = Get-Location @@ -247,6 +313,7 @@ function Invoke-EFMigrate <# .SYNOPSIS Replaces placeholders $(UserName) with values from hashtable. + .EXAMPLE Update-VariablesInFile -Path Config.xml @{UserName='sa'} #> @@ -303,14 +370,16 @@ function Initialize-MSBuild $msbuildPath = Join-Path $vsPath 'MSBuild\15.0\Bin' } - $env:Path = $msbuildPath + ";$env:Path" + $env:Path = "$msbuildPath;$env:Path" } <# .SYNOPSIS -Loads packages from many packages.config and saves to a single file. +Loads packages from multiple packages.config and saves to a single file. + .EXAMPLE Merge-PackageConfigs -SolutionDirectory .\src -OutputPath .\src\packages.merged.config + .EXAMPLE Merge-PackageConfigs -SolutionDirectory .\src -OutputPath .\src\packages.merged.net40.config -Framework net40 Merge-PackageConfigs -SolutionDirectory .\src -OutputPath .\src\packages.merged.net452.config -Framework net452 @@ -320,24 +389,26 @@ function Merge-PackageConfigs [CmdletBinding()] param ( + # Directory in which to look for packages.config files. [Parameter(Mandatory = $true)] [string] $SolutionDirectory, + # Path to file in which results should be saved. If file exists, it will be overridden. [Parameter(Mandatory = $true)] [string] $OutputPath, - [Parameter] + # If specified, only packages with this framework will be included in the results. [string] $Framework ) Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState - $files = Get-ChildItem $src -Recurse packages.config + $files = Get-ChildItem $SolutionDirectory -Recurse packages.config $packagesSet = New-Object 'System.Collections.Generic.HashSet[string]' foreach ($file in $files) { [xml] $xml = Get-Content $file.FullName - $xml.packages.package | % ` + $xml.packages.package | ForEach-Object ` { if (!$Framework -or $_.targetFramework -eq $Framework) { diff --git a/scripts/Modules/Saritasa.Build/1.16.0/Saritasa.Build.psm1.orig b/scripts/Modules/Saritasa.Build/1.16.0/Saritasa.Build.psm1.orig new file mode 100644 index 00000000..0c47955d --- /dev/null +++ b/scripts/Modules/Saritasa.Build/1.16.0/Saritasa.Build.psm1.orig @@ -0,0 +1,426 @@ +<# +.SYNOPSIS +<<<<<<< HEAD +Downloads nuget.exe to specified location. + +.EXAMPLE +Install-NugetCli . + +Install nuget into current directory +======= +Downloads latest nuget.exe to specified location. +>>>>>>> develop +#> +function Install-NugetCli +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [string] $Destination + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + $nugetExePath = "$Destination\nuget.exe" + + if (!(Test-Path $nugetExePath)) + { + Write-Information 'Downloading nuget.exe...' + Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile $nugetExePath + Write-Information 'Done.' + } +} + +<# +.SYNOPSIS +Restores packages for solution, project or packages.config. + +.EXAMPLE +Invoke-NugetRestore .\..\myapp.sln + +Restores all packages for myapp solution. + +.NOTES +If nuget command is not found - it will be downloaded to current directory. +#> +function Invoke-NugetRestore +{ + [CmdletBinding()] + param + ( + # Path to solution. All NuGet packages from included projects will be restored. + [Parameter(Mandatory = $true, ParameterSetName = 'Solution')] + [string] $SolutionPath, + # Path to project or packages.config. + [Parameter(Mandatory = $true, ParameterSetName = 'Project')] + [string] $ProjectPath, + # Path to the solution directory. Not valid when restoring packages for a solution. + [Parameter(Mandatory = $true, ParameterSetName = 'Project')] + [string] $SolutionDirectory + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + $nugetCli = Get-Command nuget.exe -ErrorAction SilentlyContinue + + if ($nugetCli) + { + $nugetExePath = $nugetCli.Source + } + else + { + Install-NugetCli -Destination $PSScriptRoot + $nugetExePath = "$PSScriptRoot\nuget.exe" + } + + $params = @('restore') + if ($SolutionPath) + { + $params += $SolutionPath + } + else + { + $params += @($ProjectPath, '-SolutionDirectory', $SolutionDirectory) + } + + &$nugetExePath $params + if ($LASTEXITCODE) + { + throw 'Nuget restore failed.' + } +} + +<# +.SYNOPSIS +Builds solution. + +.EXAMPLE +Invoke-SolutionBuild .\..\myapp.sln -Configuration Debug +#> +function Invoke-SolutionBuild +{ + [CmdletBinding()] + param + ( + # Path to solution. + [Parameter(Mandatory = $true)] + [string] $SolutionPath, + # Build configuration (Release, Debug, etc.) + [string] $Configuration + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + Invoke-ProjectBuild $SolutionPath $Configuration +} + +<# +.SYNOPSIS +Builds project. + +.PARAMETER Target +Build the specified targets in the project. +Use a semicolon or comma to separate multiple targets. + +.EXAMPLE +Invoke-ProjectBuild .\..\Web\Web.csproj -Configuration 'Release' + +.NOTES +For more information about Target and BuildParams parameters, see MSBuild documentation. +#> +function Invoke-ProjectBuild +{ + [CmdletBinding()] + param + ( + # Path to project. + [Parameter(Mandatory = $true)] + [string] $ProjectPath, + # Build configuration (Release, Debug, etc.) + [string] $Configuration, + [string] $Target = 'Build', + # Additional build parameters + [string[]] $BuildParams + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + msbuild.exe $ProjectPath '/m' "/t:$Target" "/p:Configuration=$Configuration" '/verbosity:normal' $BuildParams + if ($LASTEXITCODE) + { + throw 'Build failed.' + } +} + +<# +.SYNOPSIS +Update version numbers of AssemblyInfo.cs and AssemblyInfo.vb. + +.DESCRIPTION +Updates version numbers in AssemblyInfo files located in current directory and all subdirectories. + +.EXAMPLE +Update-AssemblyInfoFile '6.3.1.1' + +.NOTES +Based on SetVersion script. +http://www.luisrocha.net/2009/11/setting-assembly-version-with-windows.html +Copyright (c) 2009 Luis Rocha +#> +function Update-AssemblyInfoFile +{ + [CmdletBinding(SupportsShouldProcess = $true)] + param + ( + # Version string in major.minor.build.revision format. + [Parameter(Mandatory = $true)] + [string] $Version + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + $assemblyVersionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)' + $fileVersionPattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)' + $assemblyVersion = 'AssemblyVersion("' + $Version + '")'; + $fileVersion = 'AssemblyFileVersion("' + $Version + '")'; + + Get-ChildItem -r -Include AssemblyInfo.cs, AssemblyInfo.vb | ForEach-Object ` + { + $filename = $_.FullName + + # If you are using a source control that requires to check-out files before + # modifying them, make sure to check-out the file here. + # For example, TFS will require the following command: + # tf checkout $filename + + if ($PSCmdlet.ShouldProcess($filename)) + { + (Get-Content $filename) | ForEach-Object ` + { + ($_ -replace $assemblyVersionPattern, $assemblyVersion) ` + -replace $fileVersionPattern, $fileVersion + } | Set-Content $filename -Encoding UTF8 + + Write-Information "$filename -> $Version" + } + } +} + +<# +.SYNOPSIS +Creates file from a template. + +.DESCRIPTION +Creates a config file from it's template. If file already exists, it will not be overridden. + +.EXAMPLE +Copy-DotnetConfig .\..\Web\Web.config.template + +Creates a Web.config file in Web folder from template. +#> +function Copy-DotnetConfig +{ + [CmdletBinding()] + param + ( + # Path to App.config.template or Web.config.template file. + [Parameter(Mandatory = $true)] + [string] $TemplateFilename + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + $configFilename = $TemplateFilename -replace '\.template', '' + if (!(Test-Path $configFilename)) + { + Copy-Item $TemplateFilename $configFilename + } +} + +<# +.SYNOPSIS +Run Entity Framework migrations. + +.EXAMPLE +Invoke-EFMigrate ..\..\Domain\bin\Debug\Domain.dll + +Runs all migrations declared in Domain.dll file, using Domain.dll.config as configuration file + +.NOTES +In essential this command tries to find migrate.exe in packages and run it against specified +configuration file. +#> +function Invoke-EFMigrate +{ + [CmdletBinding()] + param + ( + # Path to assembly file with migrations. + [Parameter(Mandatory = $true)] + [string] $MigrationAssembly, + # Path to assembly .config file. If not specified default or parent Web.config will be used. + [string] $ConfigFilename + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + # Format and validate params + if (!$ConfigFilename) + { + $ConfigFilename = $MigrationAssembly + '.config' + if (!(Test-Path $ConfigFilename)) + { + $ConfigFilename = Join-Path (Split-Path $MigrationAssembly) 'Web.config' + } + } + if (!(Test-Path $ConfigFilename)) + { + throw "$ConfigFilename does not exist." + } + if (!(Test-Path $MigrationAssembly)) + { + throw "$MigrationAssembly does not exist." + } + + # Find migrate.exe + $packagesDirectory = Get-ChildItem 'packages' -Recurse -Depth 3 | + Where-Object { $_.PSIsContainer } | Select-Object -First 1 + if (!$packagesDirectory) + { + throw 'Cannot find packages directory.' + } + Write-Information "Found $($packagesDirectory.FullName)" + $migrateExeDirectory = Get-ChildItem $packagesDirectory.FullName 'EntityFramework.*' | + Sort-Object { $_.Name } | Select-Object -Last 1 + if (!$migrateExeDirectory) + { + throw 'Cannot find entity framework package.' + } + $migrateExe = Join-Path $migrateExeDirectory.FullName '.\tools\migrate.exe' + Write-Information "Found $($migrateExeDirectory.FullName)" + + # Run migrate + $workingDirectory = Get-Location + $args = @( + [System.IO.Path]::GetFileName($MigrationAssembly) + '/startUpDirectory:"{0}"' -f (Join-Path $workingDirectory (Split-Path $MigrationAssembly)) + '/startUpConfigurationFile:"{0}"' -f (Join-Path $workingDirectory $ConfigFilename) + ); + &"$migrateExe" $args + if ($LASTEXITCODE) + { + throw "Migration failed." + } +} + +<# +.SYNOPSIS +Replaces placeholders $(UserName) with values from hashtable. + +.EXAMPLE +Update-VariablesInFile -Path Config.xml @{UserName='sa'} +#> +function Update-VariablesInFile +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [string] $Path, + [Parameter(Mandatory = $true)] + [hashtable] $Variables + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + $content = Get-Content $Path + + foreach ($key in $Variables.Keys) + { + $escapedValue = $Variables[$key] -replace '\$', '$$$$' + $content = $content -ireplace"\`$\($key\)", $escapedValue + } + + $content | Set-Content $Path +} + +<# +.SYNOPSIS +Adds correct path to MSBuild to Path environment variable. +#> +function Initialize-MSBuild +{ + [CmdletBinding()] + param () + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + $vsPath = (@((Get-VSSetupInstance | Select-VSSetupInstance -Version 15.0 -Require Microsoft.Component.MSBuild).InstallationPath, + (Get-VSSetupInstance | Select-VSSetupInstance -Version 15.0 -Product Microsoft.VisualStudio.Product.BuildTools).InstallationPath) -ne $null)[0] + + if (!$vsPath) + { + Write-Information 'VS 2017 not found.' + return + } + + if ([System.IntPtr]::Size -eq 8) + { + $msbuildPath = Join-Path $vsPath 'MSBuild\15.0\Bin\amd64' + } + else + { + $msbuildPath = Join-Path $vsPath 'MSBuild\15.0\Bin' + } + + $env:Path = "$msbuildPath;$env:Path" +} + +<# +.SYNOPSIS +Loads packages from multiple packages.config and saves to a single file. + +.EXAMPLE +Merge-PackageConfigs -SolutionDirectory .\src -OutputPath .\src\packages.merged.config + +.EXAMPLE +Merge-PackageConfigs -SolutionDirectory .\src -OutputPath .\src\packages.merged.net40.config -Framework net40 +Merge-PackageConfigs -SolutionDirectory .\src -OutputPath .\src\packages.merged.net452.config -Framework net452 +#> +function Merge-PackageConfigs +{ + [CmdletBinding()] + param + ( + # Directory in which to look for packages.config files + [Parameter(Mandatory = $true)] + [string] $SolutionDirectory, + # Path to file in which results should be saved. If file exists, it will be overridden + [Parameter(Mandatory = $true)] + [string] $OutputPath, + # If specified, only packages with this framework will be included in the results + [string] $Framework + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + $files = Get-ChildItem $SolutionDirectory -Recurse packages.config + + $packagesSet = New-Object 'System.Collections.Generic.HashSet[string]' + + foreach ($file in $files) + { + [xml] $xml = Get-Content $file.FullName + $xml.packages.package | ForEach-Object ` + { + if (!$Framework -or $_.targetFramework -eq $Framework) + { + $packagesSet.Add($_.OuterXml) | Out-Null + } + } + } + + [xml] $finalXml = '' + $packagesSet + '' + $finalXml.Save($OutputPath) +} diff --git a/scripts/Modules/Saritasa.General/1.1.0/PSGetModuleInfo.xml b/scripts/Modules/Saritasa.General/1.1.0/PSGetModuleInfo.xml deleted file mode 100644 index 26408f85..00000000 Binary files a/scripts/Modules/Saritasa.General/1.1.0/PSGetModuleInfo.xml and /dev/null differ diff --git a/scripts/Modules/Saritasa.General/1.1.0/Saritasa.General.psm1 b/scripts/Modules/Saritasa.General/1.1.0/Saritasa.General.psm1 deleted file mode 100644 index 3a05a362..00000000 --- a/scripts/Modules/Saritasa.General/1.1.0/Saritasa.General.psm1 +++ /dev/null @@ -1,161 +0,0 @@ -<# -.Synopsis - Fetches "Preference" variable values from the caller's scope. -.DESCRIPTION - Script module functions do not automatically inherit their caller's variables, but they can be - obtained through the $PSCmdlet variable in Advanced Functions. This function is a helper function - for any script module Advanced Function; by passing in the values of $ExecutionContext.SessionState - and $PSCmdlet, Get-CallerPreference will set the caller's preference variables locally. -.PARAMETER Cmdlet - The $PSCmdlet object from a script module Advanced Function. -.PARAMETER SessionState - The $ExecutionContext.SessionState object from a script module Advanced Function. This is how the - Get-CallerPreference function sets variables in its callers' scope, even if that caller is in a different - script module. -.PARAMETER Name - Optional array of parameter names to retrieve from the caller's scope. Default is to retrieve all - Preference variables as defined in the about_Preference_Variables help file (as of PowerShell 4.0) - This parameter may also specify names of variables that are not in the about_Preference_Variables - help file, and the function will retrieve and set those as well. -.EXAMPLE - Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState - - Imports the default PowerShell preference variables from the caller into the local scope. -.EXAMPLE - Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState -Name 'ErrorActionPreference','SomeOtherVariable' - - Imports only the ErrorActionPreference and SomeOtherVariable variables into the local scope. -.EXAMPLE - 'ErrorActionPreference','SomeOtherVariable' | Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState - - Same as Example 2, but sends variable names to the Name parameter via pipeline input. -.INPUTS - String -.OUTPUTS - None. This function does not produce pipeline output. -.LINK - about_Preference_Variables -.NOTES - Import Preference variables from the caller of a Script Module function - https://gallery.technet.microsoft.com/scriptcenter/Inherit-Preference-82343b9d - MICROSOFT LIMITED PUBLIC LICENSE -#> -function Get-CallerPreference -{ - [CmdletBinding(DefaultParameterSetName = 'AllVariables')] - param ( - [Parameter(Mandatory = $true)] - [ValidateScript({ $_.GetType().FullName -eq 'System.Management.Automation.PSScriptCmdlet' })] - $Cmdlet, - - [Parameter(Mandatory = $true)] - [System.Management.Automation.SessionState] - $SessionState, - - [Parameter(ParameterSetName = 'Filtered', ValueFromPipeline = $true)] - [string[]] - $Name - ) - - begin - { - $filterHash = @{} - } - - process - { - if ($null -ne $Name) - { - foreach ($string in $Name) - { - $filterHash[$string] = $true - } - } - } - - end - { - # List of preference variables taken from the about_Preference_Variables help file in PowerShell version 4.0 - - $vars = @{ - 'ErrorView' = $null - 'FormatEnumerationLimit' = $null - 'LogCommandHealthEvent' = $null - 'LogCommandLifecycleEvent' = $null - 'LogEngineHealthEvent' = $null - 'LogEngineLifecycleEvent' = $null - 'LogProviderHealthEvent' = $null - 'LogProviderLifecycleEvent' = $null - 'MaximumAliasCount' = $null - 'MaximumDriveCount' = $null - 'MaximumErrorCount' = $null - 'MaximumFunctionCount' = $null - 'MaximumHistoryCount' = $null - 'MaximumVariableCount' = $null - 'OFS' = $null - 'OutputEncoding' = $null - 'ProgressPreference' = $null - 'PSDefaultParameterValues' = $null - 'PSEmailServer' = $null - 'PSModuleAutoLoadingPreference' = $null - 'PSSessionApplicationName' = $null - 'PSSessionConfigurationName' = $null - 'PSSessionOption' = $null - - 'ErrorActionPreference' = 'ErrorAction' - 'DebugPreference' = 'Debug' - 'ConfirmPreference' = 'Confirm' - 'WhatIfPreference' = 'WhatIf' - 'VerbosePreference' = 'Verbose' - 'WarningPreference' = 'WarningAction' - 'InformationPreference' = 'InformationAction' - } - - - foreach ($entry in $vars.GetEnumerator()) - { - if (([string]::IsNullOrEmpty($entry.Value) -or -not $Cmdlet.MyInvocation.BoundParameters.ContainsKey($entry.Value)) -and - ($PSCmdlet.ParameterSetName -eq 'AllVariables' -or $filterHash.ContainsKey($entry.Name))) - { - $variable = $Cmdlet.SessionState.PSVariable.Get($entry.Key) - - if ($null -ne $variable) - { - if ($SessionState -eq $ExecutionContext.SessionState) - { - Set-Variable -Scope 1 -Name $variable.Name -Value $variable.Value -Force -Confirm:$false -WhatIf:$false - } - else - { - $SessionState.PSVariable.Set($variable.Name, $variable.Value) - } - } - } - } - - if ($PSCmdlet.ParameterSetName -eq 'Filtered') - { - foreach ($varName in $filterHash.Keys) - { - if (-not $vars.ContainsKey($varName)) - { - $variable = $Cmdlet.SessionState.PSVariable.Get($varName) - - if ($null -ne $variable) - { - if ($SessionState -eq $ExecutionContext.SessionState) - { - Set-Variable -Scope 1 -Name $variable.Name -Value $variable.Value -Force -Confirm:$false -WhatIf:$false - } - else - { - $SessionState.PSVariable.Set($variable.Name, $variable.Value) - } - } - } - } - } - - } # end - -} # function Get-CallerPreference \ No newline at end of file diff --git a/scripts/Modules/Saritasa.General/1.2.0/PSGetModuleInfo.xml b/scripts/Modules/Saritasa.General/1.3.0/PSGetModuleInfo.xml similarity index 84% rename from scripts/Modules/Saritasa.General/1.2.0/PSGetModuleInfo.xml rename to scripts/Modules/Saritasa.General/1.3.0/PSGetModuleInfo.xml index 0592da2a..3d66269e 100644 Binary files a/scripts/Modules/Saritasa.General/1.2.0/PSGetModuleInfo.xml and b/scripts/Modules/Saritasa.General/1.3.0/PSGetModuleInfo.xml differ diff --git a/scripts/Modules/Saritasa.General/1.2.0/Saritasa.General.psd1 b/scripts/Modules/Saritasa.General/1.3.0/Saritasa.General.psd1 similarity index 97% rename from scripts/Modules/Saritasa.General/1.2.0/Saritasa.General.psd1 rename to scripts/Modules/Saritasa.General/1.3.0/Saritasa.General.psd1 index e53a7066..b77d1ebf 100644 --- a/scripts/Modules/Saritasa.General/1.2.0/Saritasa.General.psd1 +++ b/scripts/Modules/Saritasa.General/1.3.0/Saritasa.General.psd1 @@ -12,7 +12,7 @@ RootModule = 'Saritasa.General' # Version number of this module. -ModuleVersion = '1.2.0' +ModuleVersion = '1.3.0' # ID used to uniquely identify this module GUID = '7c7dc05c-033b-4838-8619-b84792571317' @@ -24,7 +24,7 @@ Author = 'Anton Zimin' CompanyName = 'Saritasa' # Copyright statement for this module -Copyright = '(c) 2016 Saritasa. All rights reserved.' +Copyright = '(c) 2016-2017 Saritasa. All rights reserved.' # Description of the functionality provided by this module Description = 'Contains general PowerShell helpers.' @@ -66,7 +66,7 @@ Description = 'Contains general PowerShell helpers.' # NestedModules = @() # Functions to export from this module -FunctionsToExport = @('Get-CallerPreference', 'Test-IsLocalhost') +FunctionsToExport = @('Get-CallerPreference', 'Test-IsLocalhost', 'Use-Object') # Cmdlets to export from this module CmdletsToExport = @() diff --git a/scripts/Modules/Saritasa.General/1.2.0/Saritasa.General.psm1 b/scripts/Modules/Saritasa.General/1.3.0/Saritasa.General.psm1 similarity index 84% rename from scripts/Modules/Saritasa.General/1.2.0/Saritasa.General.psm1 rename to scripts/Modules/Saritasa.General/1.3.0/Saritasa.General.psm1 index 7cc4bfa5..d272c9af 100644 --- a/scripts/Modules/Saritasa.General/1.2.0/Saritasa.General.psm1 +++ b/scripts/Modules/Saritasa.General/1.3.0/Saritasa.General.psm1 @@ -174,3 +174,61 @@ function Test-IsLocalhost $ComputerName -match "^(\.|localhost|$env:COMPUTERNAME)`$" } + +<# +.SYNOPSIS +Dispose an object after using it. + +.DESCRIPTION +This cmdlet is designed to use the same way the "using" keyword in C# is used. + +.PARAMETER InputObject +Object to be disposed. + +.PARAMETER ScriptBlock +Script to be executed. + +.EXAMPLE +C:\PS> $text = "" +C:\PS> $fileStream = New-Object System.IO.FileStream("G:\test\1.txt", [System.IO.FileMode]::Open) +C:\PS> Use-Object $fileStream ` +{ + $streamReader = New-Object System.IO.StreamReader($fileStream) + Use-Object $streamReader ` + { + $text = $streamReader.ReadToEnd() + } +} +C:\PS> $text +#> +function Use-Object +{ + [CmdletBinding()] + param + ( + # Object to be disposed. + [Parameter(Mandatory = $true)] + [AllowEmptyString()] + [AllowEmptyCollection()] + [AllowNull()] + [Object] + $InputObject, + + # Code to be executed after which the object will be disposed + [Parameter(Mandatory = $true)] + [scriptblock] + $ScriptBlock + ) + + try + { + . $ScriptBlock + } + finally + { + if ($null -ne $InputObject -and $InputObject -is [System.IDisposable]) + { + $InputObject.Dispose() + } + } +} \ No newline at end of file diff --git a/scripts/Modules/Saritasa.Test/1.2.3/Saritasa.Test.psm1 b/scripts/Modules/Saritasa.Test/1.2.3/Saritasa.Test.psm1 deleted file mode 100644 index 96e29b69..00000000 --- a/scripts/Modules/Saritasa.Test/1.2.3/Saritasa.Test.psm1 +++ /dev/null @@ -1,53 +0,0 @@ -<# -.SYNOPSIS -Run NUnit 3 tests. - -.NOTES -NUnit.ConsoleRunner package should be installed. -#> -function Invoke-Nunit3Runner -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true, HelpMessage = 'Path to assembly file with tests.')] - [string] $TestAssembly, - [string[]] $Params - ) - - Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState - - # Format and validate params - if (!(Test-Path $TestAssembly)) - { - throw "$TestAssembly does not exist." - } - - # Find nunit3-console.exe - $packagesDirectory = Get-ChildItem -Filter 'packages' -Recurse -Depth 3 | - Where-Object { $_.PSIsContainer -and (Get-ChildItem $_.FullName 'NUnit.ConsoleRunner.*') } | - Select-Object -First 1 - - if (!$packagesDirectory) - { - throw 'Cannot find packages directory.' - } - Write-Information "Found $packagesDirectory." - $nunitExeDirectory = Get-ChildItem $packagesDirectory.FullName 'NUnit.ConsoleRunner.*' | - Sort-Object { $_.Name } | Select-Object -Last 1 - if (!$nunitExeDirectory) - { - throw 'Cannot find nunit console runner package.' - } - $nunitExe = Join-Path $nunitExeDirectory.FullName '.\tools\nunit3-console.exe' - Write-Information "Found $($nunitExeDirectory.FullName)" - - # Run nunit - $args = @($TestAssembly, '--noresult', '--stoponerror', '--noheader') - $args += $Params - &"$nunitExe" $args - if ($LASTEXITCODE) - { - throw "Unit tests failed." - } -} diff --git a/scripts/Modules/Saritasa.Test/1.2.3/PSGetModuleInfo.xml b/scripts/Modules/Saritasa.Test/1.4.0/PSGetModuleInfo.xml similarity index 87% rename from scripts/Modules/Saritasa.Test/1.2.3/PSGetModuleInfo.xml rename to scripts/Modules/Saritasa.Test/1.4.0/PSGetModuleInfo.xml index a1abae5b..c04e6bd5 100644 Binary files a/scripts/Modules/Saritasa.Test/1.2.3/PSGetModuleInfo.xml and b/scripts/Modules/Saritasa.Test/1.4.0/PSGetModuleInfo.xml differ diff --git a/scripts/Modules/Saritasa.Test/1.2.3/Saritasa.Test.psd1 b/scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psd1 similarity index 97% rename from scripts/Modules/Saritasa.Test/1.2.3/Saritasa.Test.psd1 rename to scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psd1 index 8d83aa1c..b8cca64e 100644 --- a/scripts/Modules/Saritasa.Test/1.2.3/Saritasa.Test.psd1 +++ b/scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psd1 @@ -12,7 +12,7 @@ RootModule = 'Saritasa.Test' # Version number of this module. -ModuleVersion = '1.2.3' +ModuleVersion = '1.4.0' # ID used to uniquely identify this module GUID = '97046c41-6b19-4e13-9434-ead6834a5338' @@ -68,7 +68,7 @@ RequiredModules = @( # NestedModules = @() # Functions to export from this module -FunctionsToExport = @('Invoke-Nunit3Runner') +FunctionsToExport = @('Invoke-Nunit3Runner', 'Invoke-XunitRunner') # Cmdlets to export from this module CmdletsToExport = @() diff --git a/scripts/Modules/Saritasa.General/1.1.0/Saritasa.General.psd1 b/scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psd1.orig similarity index 64% rename from scripts/Modules/Saritasa.General/1.1.0/Saritasa.General.psd1 rename to scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psd1.orig index 775405a5..d60d43e8 100644 --- a/scripts/Modules/Saritasa.General/1.1.0/Saritasa.General.psd1 +++ b/scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psd1.orig @@ -1,33 +1,39 @@ -# -# Module manifest for module 'Saritasa.General' # -# Generated by: Anton Zimin +# Module manifest for module 'PSGet_Saritasa.Test' # -# Generated on: 9/29/2016 +# Generated by: Ivan Kozhin +# +# Generated on: 6/27/2017 # @{ # Script module or binary module file associated with this manifest. -RootModule = 'Saritasa.General' +RootModule = 'Saritasa.Test' # Version number of this module. -ModuleVersion = '1.1.0' +ModuleVersion = '1.3.0' +<<<<<<< HEAD + +# Supported PSEditions +# CompatiblePSEditions = @() +======= +>>>>>>> develop # ID used to uniquely identify this module -GUID = '7c7dc05c-033b-4838-8619-b84792571317' +GUID = '97046c41-6b19-4e13-9434-ead6834a5338' # Author of this module -Author = 'Anton Zimin' +Author = 'Ivan Kozhin' # Company or vendor of this module CompanyName = 'Saritasa' # Copyright statement for this module -Copyright = '(c) 2016 Saritasa. All rights reserved.' +Copyright = '(c) 2016-2017 Saritasa. All rights reserved.' # Description of the functionality provided by this module -Description = 'Contains general PowerShell helpers.' +Description = 'Contains functions to run unit tests.' # Minimum version of the Windows PowerShell engine required by this module # PowerShellVersion = '' @@ -38,17 +44,17 @@ Description = 'Contains general PowerShell helpers.' # Minimum version of the Windows PowerShell host required by this module # PowerShellHostVersion = '' -# Minimum version of Microsoft .NET Framework required by this module +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. # DotNetFrameworkVersion = '' -# Minimum version of the common language runtime (CLR) required by this module +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. # CLRVersion = '' # Processor architecture (None, X86, Amd64) required by this module # ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module -# RequiredModules = @() +RequiredModules = @(@{ModuleName = 'Saritasa.General'; GUID = '7c7dc05c-033b-4838-8619-b84792571317'; ModuleVersion = '1.1.0'; }) # Assemblies that must be loaded prior to importing this module # RequiredAssemblies = @() @@ -65,16 +71,21 @@ Description = 'Contains general PowerShell helpers.' # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess # NestedModules = @() +<<<<<<< HEAD +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = 'Invoke-Nunit3Runner' +======= # Functions to export from this module -FunctionsToExport = @('Get-CallerPreference') +FunctionsToExport = @('Invoke-Nunit3Runner', 'Invoke-XunitRunner') +>>>>>>> develop -# Cmdlets to export from this module +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() # Variables to export from this module -VariablesToExport = @() +# VariablesToExport = @() -# Aliases to export from this module +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. AliasesToExport = @() # DSC resources to export from this module @@ -92,7 +103,7 @@ PrivateData = @{ PSData = @{ # Tags applied to this module. These help with module discovery in online galleries. - Tags = 'Util' + Tags = 'NUnit','Unit','Test' # A URL to the license for this module. LicenseUri = 'https://raw.githubusercontent.com/Saritasa/PSGallery/master/LICENSE' @@ -106,9 +117,12 @@ PrivateData = @{ # ReleaseNotes of this module # ReleaseNotes = '' - } # End of PSData hashtable + # External dependent modules of this module + # ExternalModuleDependencies = '' -} # End of PrivateData hashtable + } # End of PSData hashtable + + } # End of PrivateData hashtable # HelpInfo URI of this module # HelpInfoURI = '' diff --git a/scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psm1 b/scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psm1 new file mode 100644 index 00000000..dc226da9 --- /dev/null +++ b/scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psm1 @@ -0,0 +1,118 @@ +<# +.SYNOPSIS +Run NUnit 3 tests. + +.NOTES +NUnit.ConsoleRunner package should be installed. +#> +function Invoke-Nunit3Runner +{ + [CmdletBinding()] + param + ( + # Path to the testing assembly. + [Parameter(Mandatory = $true, HelpMessage = 'Path to assembly file with tests.')] + [string] $TestAssembly, + # Additional parameters to be passed to NUnit console runner. + [string[]] $Params, + # Path to the NUnit console runner. If not specified, the cmdlet will try to find it automatically from current script folder's subfolders. + [string] $NUnitPath + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + # Format and validate params. + if (!(Test-Path $TestAssembly)) + { + throw "$TestAssembly does not exist." + } + if ($NUnitPath -and !(Test-Path $NUnitPath)) + { + throw "$NUnitPath does not exist." + } + + if (!($NUnitPath)) + { + # Find nunit3-console.exe + $packagesDirectory = Get-ChildItem -Filter 'packages' -Recurse -Depth 3 | + Where-Object { $_.PSIsContainer -and (Get-ChildItem $_.FullName 'NUnit.ConsoleRunner.*') } | + Select-Object -First 1 + + if (!$packagesDirectory) + { + throw 'Cannot find packages directory.' + } + Write-Information "Found $packagesDirectory." + $nunitExeDirectory = Get-ChildItem $packagesDirectory.FullName 'NUnit.ConsoleRunner.*' | + Sort-Object { $_.Name } | Select-Object -Last 1 + if (!$nunitExeDirectory) + { + throw 'Cannot find nunit console runner package.' + } + $NUnitPath = Join-Path $nunitExeDirectory.FullName '.\tools\nunit3-console.exe' + Write-Information "Found $($nunitExeDirectory.FullName)" + } + + # Run nunit. + $args = @($TestAssembly, '--noresult', '--stoponerror', '--noheader') + $args += $Params + &"$NUnitPath" $args + if ($LASTEXITCODE) + { + throw "Unit tests failed." + } +} + +<# +.SYNOPSIS +Run xUnit tests. + +.NOTES +xunit.runner.console package should be installed. +#> +function Invoke-XunitRunner +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true, HelpMessage = 'Path to assembly file with tests.')] + [string] $TestAssembly, + [string[]] $Params + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + # Format and validate params. + if (!(Test-Path $TestAssembly)) + { + throw "$TestAssembly does not exist." + } + + # Find xunit.console.exe . + $packagesDirectory = Get-ChildItem -Filter 'packages' -Recurse -Depth 3 | + Where-Object { $_.PSIsContainer -and (Get-ChildItem $_.FullName 'xunit.runner.console.*') } | + Select-Object -First 1 + + if (!$packagesDirectory) + { + throw 'Cannot find packages directory.' + } + Write-Information "Found $packagesDirectory." + $xunitExeDirectory = Get-ChildItem $packagesDirectory.FullName 'xunit.runner.console.*' | + Sort-Object { $_.Name } | Select-Object -Last 1 + if (!$xunitExeDirectory) + { + throw 'Cannot find xunit console runner package.' + } + $xunitExe = Join-Path $xunitExeDirectory.FullName '.\tools\xunit.console.exe' + Write-Information "Found $($xunitExeDirectory.FullName)" + + # Run xunit + $args = @($TestAssembly, '-nologo', '-nocolor') + $args += $Params + &"$xunitExe" $args + if ($LASTEXITCODE) + { + throw "Unit tests failed." + } +} diff --git a/scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psm1.orig b/scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psm1.orig new file mode 100644 index 00000000..fc5b8998 --- /dev/null +++ b/scripts/Modules/Saritasa.Test/1.4.0/Saritasa.Test.psm1.orig @@ -0,0 +1,128 @@ +<# +.SYNOPSIS +Run NUnit 3 tests. + +.NOTES +NUnit.ConsoleRunner package should be installed. +#> +function Invoke-Nunit3Runner +{ + [CmdletBinding()] + param + ( + # Path to the testing assembly. + [Parameter(Mandatory = $true, HelpMessage = 'Path to assembly file with tests.')] + [string] $TestAssembly, + # Additional parameters to be passed nunit console runner. + [string[]] $Params, + # Path to the nunit console runner. If not specified, the cmdlet will try to find it automatically from current script folder's subfolders. + [string] $NUnitPath + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + # Format and validate params. + if (!(Test-Path $TestAssembly)) + { + throw "$TestAssembly does not exist." + } +<<<<<<< HEAD + if ($NUnitPath -and !(Test-Path $NUnitPath)) +======= + + # Find nunit3-console.exe . + $packagesDirectory = Get-ChildItem -Filter 'packages' -Recurse -Depth 3 | + Where-Object { $_.PSIsContainer -and (Get-ChildItem $_.FullName 'NUnit.ConsoleRunner.*') } | + Select-Object -First 1 + + if (!$packagesDirectory) +>>>>>>> develop + { + throw "$NUnitPath does not exist." + } + + if (!($NUnitPath)) + { + # Find nunit3-console.exe + $packagesDirectory = Get-ChildItem -Filter 'packages' -Recurse -Depth 3 | + Where-Object { $_.PSIsContainer -and (Get-ChildItem $_.FullName 'NUnit.ConsoleRunner.*') } | + Select-Object -First 1 + + if (!$packagesDirectory) + { + throw 'Cannot find packages directory.' + } + Write-Information "Found $packagesDirectory." + $nunitExeDirectory = Get-ChildItem $packagesDirectory.FullName 'NUnit.ConsoleRunner.*' | + Sort-Object { $_.Name } | Select-Object -Last 1 + if (!$nunitExeDirectory) + { + throw 'Cannot find nunit console runner package.' + } + $NUnitPath = Join-Path $nunitExeDirectory.FullName '.\tools\nunit3-console.exe' + Write-Information "Found $($nunitExeDirectory.FullName)" + } + + # Run nunit. + $args = @($TestAssembly, '--noresult', '--stoponerror', '--noheader') + $args += $Params + &"$NUnitPath" $args + if ($LASTEXITCODE) + { + throw "Unit tests failed." + } +} + +<# +.SYNOPSIS +Run xUnit tests. + +.NOTES +xunit.runner.console package should be installed. +#> +function Invoke-XunitRunner +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true, HelpMessage = 'Path to assembly file with tests.')] + [string] $TestAssembly, + [string[]] $Params + ) + + Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState + + # Format and validate params. + if (!(Test-Path $TestAssembly)) + { + throw "$TestAssembly does not exist." + } + + # Find xunit.console.exe . + $packagesDirectory = Get-ChildItem -Filter 'packages' -Recurse -Depth 3 | + Where-Object { $_.PSIsContainer -and (Get-ChildItem $_.FullName 'xunit.runner.console.*') } | + Select-Object -First 1 + + if (!$packagesDirectory) + { + throw 'Cannot find packages directory.' + } + Write-Information "Found $packagesDirectory." + $xunitExeDirectory = Get-ChildItem $packagesDirectory.FullName 'xunit.runner.console.*' | + Sort-Object { $_.Name } | Select-Object -Last 1 + if (!$xunitExeDirectory) + { + throw 'Cannot find xunit console runner package.' + } + $xunitExe = Join-Path $xunitExeDirectory.FullName '.\tools\xunit.console.exe' + Write-Information "Found $($xunitExeDirectory.FullName)" + + # Run xunit + $args = @($TestAssembly, '-nologo', '-nocolor') + $args += $Params + &"$xunitExe" $args + if ($LASTEXITCODE) + { + throw "Unit tests failed." + } +} diff --git a/scripts/Modules/Saritasa.WebDeploy/1.14.1/PSGetModuleInfo.xml b/scripts/Modules/Saritasa.WebDeploy/1.15.0/PSGetModuleInfo.xml similarity index 91% rename from scripts/Modules/Saritasa.WebDeploy/1.14.1/PSGetModuleInfo.xml rename to scripts/Modules/Saritasa.WebDeploy/1.15.0/PSGetModuleInfo.xml index 31bc2ea8..ed6fdc09 100644 Binary files a/scripts/Modules/Saritasa.WebDeploy/1.14.1/PSGetModuleInfo.xml and b/scripts/Modules/Saritasa.WebDeploy/1.15.0/PSGetModuleInfo.xml differ diff --git a/scripts/Modules/Saritasa.WebDeploy/1.14.1/Saritasa.WebDeploy.psd1 b/scripts/Modules/Saritasa.WebDeploy/1.15.0/Saritasa.WebDeploy.psd1 similarity index 97% rename from scripts/Modules/Saritasa.WebDeploy/1.14.1/Saritasa.WebDeploy.psd1 rename to scripts/Modules/Saritasa.WebDeploy/1.15.0/Saritasa.WebDeploy.psd1 index 6eac28e9..1cba855a 100644 --- a/scripts/Modules/Saritasa.WebDeploy/1.14.1/Saritasa.WebDeploy.psd1 +++ b/scripts/Modules/Saritasa.WebDeploy/1.15.0/Saritasa.WebDeploy.psd1 @@ -12,7 +12,7 @@ RootModule = 'Saritasa.WebDeploy' # Version number of this module. -ModuleVersion = '1.14.1' +ModuleVersion = '1.15.0' # ID used to uniquely identify this module GUID = '1821cb68-29fe-4074-b296-58c450cb9177' @@ -24,7 +24,7 @@ Author = 'Anton Zimin' CompanyName = 'Saritasa' # Copyright statement for this module -Copyright = '(c) 2016 Saritasa. All rights reserved.' +Copyright = '(c) 2016-2017 Saritasa. All rights reserved.' # Description of the functionality provided by this module Description = 'Contains functions to control app pools and synchronize IIS web sites using Microsoft WebDeploy tool.' diff --git a/scripts/Modules/Saritasa.WebDeploy/1.14.1/Saritasa.WebDeploy.psm1 b/scripts/Modules/Saritasa.WebDeploy/1.15.0/Saritasa.WebDeploy.psm1 similarity index 74% rename from scripts/Modules/Saritasa.WebDeploy/1.14.1/Saritasa.WebDeploy.psm1 rename to scripts/Modules/Saritasa.WebDeploy/1.15.0/Saritasa.WebDeploy.psm1 index a9a8506f..7e2e1d7b 100644 --- a/scripts/Modules/Saritasa.WebDeploy/1.14.1/Saritasa.WebDeploy.psm1 +++ b/scripts/Modules/Saritasa.WebDeploy/1.15.0/Saritasa.WebDeploy.psm1 @@ -4,9 +4,19 @@ $credential = '' <# .SYNOPSIS +Configure Web Deploy default settings. -.DESCRIPTION -Leave -Username and -Password empty for NTLM. +.PARAMETER Credential +Credentials to be used for authorization. + +.PARAMETER MsdeployPath +Provide to override folder location of Microsoft Web Deploy utility. + +.PARAMETER MsdeployPort +Provide to override default MS Deploy port. + +.NOTES +Leave -Credential empty for NTLM. For NTLM support execute on server: Set-ItemProperty HKLM:Software\Microsoft\WebManagement\Server WindowsAuthenticationEnabled 1 Restart-Service WMSVC @@ -49,6 +59,10 @@ function Initialize-WebDeploy } } +<# +.SYNOPSIS +Checks if Web Deploy credentials are set. +#> function Assert-WebDeployCredential() { if (!$credential) @@ -58,6 +72,27 @@ function Assert-WebDeployCredential() } <# +.SYNOPSIS +Package a project. + +.PARAMETER ProjectPath +Path to project file. + +.PARAMETER PackagePath +Path to where the resulting package should be saved. + +.PARAMETER Configuration +Target build configuration. + +.PARAMETER Platform +Target build platform. + +.PARAMETER Precompile +Whether or not project should be precompiled before packaging. + +.PARAMETER BuildParams +Any additional parameters to be passed to MSBuild utility. + .EXAMPLE Invoke-PackageBuild src/WebApp.csproj WebApp.zip -BuildParams ('/p:AspnetMergePath="C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools"') #> @@ -90,8 +125,18 @@ function Invoke-PackageBuild <# .SYNOPSIS +Starts the application pool for specified application on a remote machine. + +.PARAMETER ServerHost +Hostname of target machine. -.DESCRIPTION +.PARAMETER SiteName +Web site name. + +.PARAMETER Application +Application name. + +.NOTES The recycleApp provider should be delegated to WDeployAdmin. #> function Start-AppPool @@ -114,7 +159,7 @@ function Start-AppPool $computerName, $useTempAgent = GetComputerName $ServerHost $SiteName $destArg = "-dest:recycleApp='$SiteName/$Application',recycleMode='StartAppPool'," + - "computerName='$computerName',tempAgent='$useTempAgent'," + $credential + "computerName='$computerName',tempAgent='$useTempAgent',$credential" $args = @('-verb:sync', '-source:recycleApp', $destArg) $result = Start-Process -NoNewWindow -Wait -PassThru "$msdeployPath\msdeploy.exe" $args @@ -126,8 +171,18 @@ function Start-AppPool <# .SYNOPSIS +Stops the application pool for specified application on a remote machine. + +.PARAMETER ServerHost +Hostname of target machine. -.DESCRIPTION +.PARAMETER SiteName +Web site name. + +.PARAMETER Application +Application name. + +.NOTES The recycleApp provider should be delegated to WDeployAdmin. #> function Stop-AppPool @@ -150,7 +205,7 @@ function Stop-AppPool $computerName, $useTempAgent = GetComputerName $ServerHost $SiteName $destArg = "-dest:recycleApp='$SiteName/$Application',recycleMode='StopAppPool'," + - "computerName='$computerName',tempAgent='$useTempAgent'," + $credential + "computerName='$computerName',tempAgent='$useTempAgent',$credential" $args = @('-verb:sync', '-source:recycleApp', $destArg) $result = Start-Process -NoNewWindow -Wait -PassThru "$msdeployPath\msdeploy.exe" $args @@ -161,6 +216,15 @@ function Stop-AppPool } <# +.SYNOPSIS +Get a MSDeploy URL by host name. + +.PARAMETER ServerHost +Hostname of target machine. + +.PARAMETER SiteName +Web site name. + .OUTPUTS computerName, useTempAgent #> @@ -201,9 +265,26 @@ function GetComputerName([string] $ServerHost, [string] $SiteName) <# .SYNOPSIS +Invokes a web deployment process. + +.PARAMETER PackagePath +Path to package to be deployed. +To generate the package the Invoke-PackageBuild command can be used. + +.PARAMETER ServerHost +Hostname of target machine. + +.PARAMETER SiteName +Web site name. + +.PARAMETER Application +Application name. + +.PARAMETER AllowUntrusted +When specified, untrusted SSL connections are allowed. Otherwise, untrusted SSL connections are not allowed. -.DESCRIPTION -The recycleApp provider should be delegated to WDeployConfigWriter. +.PARAMETER MSDeployParams +Any additional parameters to be passed to MSDeploy utility. #> function Invoke-WebDeployment { @@ -230,7 +311,7 @@ function Invoke-WebDeployment $computerName, $useTempAgent = GetComputerName $ServerHost $SiteName $args = @("-source:package='$PackagePath'", - ("-dest:auto,computerName='$computerName',tempAgent='$useTempAgent',includeAcls='False'," + $credential), + "-dest:auto,computerName='$computerName',tempAgent='$useTempAgent',includeAcls='False',$credential", '-verb:sync', '-disableLink:AppPoolExtension', '-disableLink:ContentExtension', '-disableLink:CertificateExtension', "-setParam:name='IIS Web Application Name',value='$SiteName/$Application'") @@ -254,6 +335,15 @@ function Invoke-WebDeployment <# .SYNOPSIS Copies IIS app content from local server to remote server. + +.PARAMETER SiteName +Web site name. + +.PARAMETER Application +Application name. + +.PARAMETER ServerHost +Hostname of target machine. #> function Sync-IisApp { @@ -266,16 +356,17 @@ function Sync-IisApp [AllowEmptyString()] [string] $Application, [Parameter(Mandatory = $true)] - [string] $DestinationServer + [Alias("DestinationServer")] + [string] $ServerHost ) Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState Assert-WebDeployCredential - $computerName, $useTempAgent = GetComputerName $DestinationServer $SiteName + $computerName, $useTempAgent = GetComputerName $ServerHost $SiteName $args = @('-verb:sync', "-source:iisApp='$SiteName/$Application'", - ("-dest:auto,computerName='$computerName',tempAgent='$useTempAgent'," + $credential)) + "-dest:auto,computerName='$computerName',tempAgent='$useTempAgent',$credential") $result = Start-Process -NoNewWindow -Wait -PassThru "$msdeployPath\msdeploy.exe" $args if ($result.ExitCode) @@ -283,12 +374,27 @@ function Sync-IisApp throw 'Msdeploy failed.' } - Write-Information "Updated '$SiteName/$Application' app on $DestinationServer server." + Write-Information "Updated '$SiteName/$Application' app on $ServerHost server." } <# .SYNOPSIS Synchronizes web site file structure between local and remote servers. + +.PARAMETER ContentPath +Folder path on local machine to be synchronized. + +.PARAMETER ServerHost +Hostname of target machine. + +.PARAMETER SiteName +Web site name. + +.PARAMETER AutoDestination +If set, the destination will be specified automatically. + +.PARAMETER Application +Application name. #> function Sync-WebContent { @@ -298,7 +404,8 @@ function Sync-WebContent [Parameter(Mandatory = $true)] [string] $ContentPath, [Parameter(Mandatory = $true)] - [string] $DestinationServer, + [Alias("DestinationServer")] + [string] $ServerHost, [Parameter(Mandatory = $true)] [string] $SiteName, [Parameter(Mandatory = $true, ParameterSetName = 'IIS')] @@ -324,7 +431,7 @@ function Sync-WebContent $computerName, $useTempAgent = GetComputerName $DestinationServer $SiteName $args = @('-verb:sync', "-source:contentPath='$ContentPath'", - ("$destinationParam,computerName='$computerName',tempAgent='$useTempAgent'," + $credential)) + "$destinationParam,computerName='$computerName',tempAgent='$useTempAgent',$credential") $result = Start-Process -NoNewWindow -Wait -PassThru "$msdeployPath\msdeploy.exe" $args if ($result.ExitCode) @@ -332,12 +439,30 @@ function Sync-WebContent throw 'Msdeploy failed.' } - Write-Information "Updated '$ContentPath' directory on $DestinationServer server." + Write-Information "Updated '$ContentPath' directory on $ServerHost server." } <# .SYNOPSIS Deploys ASP.NET web site (app without project) to remote server. It's similar to Sync-WebContent, but creates IIS application. + +.PARAMETER Path +Folder path to be deployed. + +.PARAMETER ServerHost +Hostname of target machine. + +.PARAMETER SiteName +Web site name. + +.PARAMETER Application +Application name. + +.PARAMETER AllowUntrusted +When specified, untrusted SSL connections are allowed. otherwise, untrusted SSL connections are not allowed. + +.PARAMETER MSDeployParams +Any additional parameters to be passed to MSDeploy utility. #> function Invoke-WebSiteDeployment { @@ -364,7 +489,7 @@ function Invoke-WebSiteDeployment $computerName, $useTempAgent = GetComputerName $ServerHost $SiteName $args = @('-verb:sync', "-source:iisApp='$Path'", - ("-dest:iisApp='$SiteName/$Application',computerName='$computerName',tempAgent='$useTempAgent'," + $credential)) + "-dest:iisApp='$SiteName/$Application',computerName='$computerName',tempAgent='$useTempAgent',$credential") if ($AllowUntrusted) { diff --git a/scripts/Modules/VSSetup/2.0.1.32208/Microsoft.VisualStudio.Setup.Configuration.Interop.dll b/scripts/Modules/VSSetup/2.0.1.32208/Microsoft.VisualStudio.Setup.Configuration.Interop.dll new file mode 100644 index 00000000..24277b04 Binary files /dev/null and b/scripts/Modules/VSSetup/2.0.1.32208/Microsoft.VisualStudio.Setup.Configuration.Interop.dll differ diff --git a/scripts/Modules/VSSetup/2.0.1.32208/Microsoft.VisualStudio.Setup.PowerShell.dll b/scripts/Modules/VSSetup/2.0.1.32208/Microsoft.VisualStudio.Setup.PowerShell.dll new file mode 100644 index 00000000..fd6e87c2 Binary files /dev/null and b/scripts/Modules/VSSetup/2.0.1.32208/Microsoft.VisualStudio.Setup.PowerShell.dll differ diff --git a/scripts/Modules/VSSetup/2.0.1.32208/PSGetModuleInfo.xml b/scripts/Modules/VSSetup/2.0.1.32208/PSGetModuleInfo.xml index d15b890a..1fa07b18 100644 Binary files a/scripts/Modules/VSSetup/2.0.1.32208/PSGetModuleInfo.xml and b/scripts/Modules/VSSetup/2.0.1.32208/PSGetModuleInfo.xml differ diff --git a/scripts/Saritasa.PsakeTasks.ps1 b/scripts/Saritasa.PsakeTasks.ps1 index ffe8b032..806fa194 100644 --- a/scripts/Saritasa.PsakeTasks.ps1 +++ b/scripts/Saritasa.PsakeTasks.ps1 @@ -2,7 +2,7 @@ <#PSScriptInfo -.VERSION 1.3.1 +.VERSION 1.3.4 .GUID 966fce03-6946-447c-8e16-29b673f2918b @@ -85,20 +85,42 @@ Task update-gallery -description '* Update all modules from Saritasa PS Gallery. Get-ChildItem -Path $root -Include 'Saritasa*Tasks.ps1' -Recurse | ForEach-Object ` { - Write-Information "Updating $($_.Name)..." - Invoke-WebRequest -Uri "$baseUri/scripts/Psake/$($_.Name)" -OutFile "$root\$($_.Name)" - Write-Information 'OK' + UpdateScript $_.Name "$root\$($_.Name)" "$baseUri/scripts/Psake/$($_.Name)" + } + + $otherScripts = @('WebDeploy\AddDelegationRules.ps1', 'WebDeploy\SetupSiteForPublish.ps1') + + foreach ($script in $otherScripts) + { + $item = Get-Item "$root\$script" -ErrorAction SilentlyContinue + + if ($item) + { + $uri = "$baseUri/scripts/$script" -replace '\\', '/' + UpdateScript $item.Name $item.FullName $uri } + } Invoke-Task add-scripts-to-git } +function UpdateScript([string] $Name, [string] $Path, [string] $Uri) +{ + Write-Information "Updating $Name..." + Invoke-WebRequest -Uri $Uri -OutFile $Path + Write-Information 'OK' +} + Task add-scripts-to-git -description 'Add PowerShell scripts and modules to Git.' ` { $root = $PSScriptRoot + $badExtensions = @('.bak', '.orig') Get-ChildItem -Path $root -File -Recurse -Exclude '*.exe' -Force | ForEach-Object ` { - Exec { git add -f $_.FullName } + if ($badExtensions -notcontains $_.Extension) + { + Exec { git add -f $_.FullName } + } } }