Public/AzureDevOps/Add-PipelineTasks.ps1
[string[]]$global:pipelineTasksSet=@("ClearProjectDirectories","RemoveNugetImportTargets","RemoveProjectLicenseFile","RemoveProjectInvalidItems", "UpdateProjectAutoGeneratedBindingRedirects","UpdateAppendTargetFrameworkToOutputPath","UpdateGeneratedAssemblyInfo","UpdateProjectTargetFramework", "UpdateOutputPath","RemoveProjectReferences","UpdateAssemblyInfoVersion") function Add-PipelineTasks { [CmdletBinding()] [CmdLetTag(("#Azure","AzureDevOps"))] param ( [parameter(Mandatory,ValueFromPipeline)] [System.IO.FileInfo]$ProjectFile, [ValidateScript({$_ -in $global:pipelineTasksSet})] [parameter()] [ArgumentCompleter({ [OutputType([System.Management.Automation.CompletionResult])] # zero to many param( [string] $CommandName, [string] $ParameterName, [string] $WordToComplete, [System.Management.Automation.Language.CommandAst] $CommandAst, [System.Collections.IDictionary] $FakeBoundParameters ) $global:pipelineTasksSet })] [string[]]$Task=$global:pipelineTasksSet, [ValidateSet("4.5.2","4.6.1","4.7.1","4.7.2","4.8")] [string]$TargetFramework="4.7.2", [string]$OutputPath, [version]$AssemblyInfoVersion ) begin { } process { Push-Location $ProjectFile.DirectoryName Write-HostFormatted "Analyzing $($ProjectFile.BaseName)" -Section -ForegroundColor Yellow if ("ClearProjectDirectories" -in $global:pipelineTasksSet){ $currentDir=(Get-Item $ProjectFile).Name Clear-ProjectDirectories } if ("RemoveNugetImportTargets" -in $global:pipelineTasksSet){ Write-HostFormatted "Remove Nuget Imports and Targets" -Section Remove-NugetImportsTargets $ProjectFile|Out-Null } if ("RemoveProjectLicenseFile" -in $global:pipelineTasksSet){ Write-HostFormatted "Remove licx files" -Section Remove-ProjectLicenseFile -FilePath $ProjectFile.FullName|Out-Null } if ("RemoveProjectInvalidItems" -in $global:pipelineTasksSet){ Write-HostFormatted "Remove invalid Project Imports" -Section Remove-ProjectInvalidItems $ProjectFile|Out-Null } [xml]$csproj = Get-XmlContent $ProjectFile.FullName if ("UpdateProjectAutoGeneratedBindingRedirects" -in $global:pipelineTasksSet){ Write-HostFormatted "Update-ProjectAutoGenerateBindingRedirects" -Section Update-ProjectAutoGenerateBindingRedirects $csproj $false } if ("UpdateAppendTargetFrameworkToOutputPath" -in $global:pipelineTasksSet){ Write-HostFormatted "Update-AppendTargetFrameworkToOutputPath" -Section Update-AppendTargetFrameworkToOutputPath $csproj } if ("UpdateGeneratedAssemblyInfo" -in $global:pipelineTasksSet){ Write-HostFormatted "Update-GenerateAssemblyInfo" -Section Update-GenerateAssemblyInfo $csproj } if ("UpdateProjectTargetFramework" -in $global:pipelineTasksSet){ Write-HostFormatted "Update-ProjectTargetFramework" -Section Update-ProjectTargetFramework $TargetFramework $csproj } if ("UpdateOutputPath" -in $global:pipelineTasksSet -and $OutputPath){ Write-HostFormatted "Update-OutputPath" -Section Update-OutputPath $csproj $ProjectFile.FullName $OutputPath } $csproj | Save-Xml $ProjectFile.FullName|Out-Null if ("RemoveProjectReferences" -in $global:pipelineTasksSet){ Write-HostFormatted "Remove invalid hintpath references" -Section Remove-ProjectReferences $ProjectFile.FullName -InvalidHintPath|Out-Null } if ("UpdateAssemblyInfoVersion" -in $global:pipelineTasksSet){ Write-HostFormatted "Update-AssemblyInfoVersion" -Section Update-AssemblyInfoVersion $AssemblyInfoVersion "$($ProjectFile.DirectoryName)\Properties\AssemblyInfo.cs" } Pop-Location } end { } } |