diff --git a/.github/actions/msbuild/Build-DotNetFrameworkSolutionOrProject.ps1 b/.github/actions/msbuild/Build-DotNetFrameworkSolutionOrProject.ps1 index d94a64a7d..9fa616fe9 100644 --- a/.github/actions/msbuild/Build-DotNetFrameworkSolutionOrProject.ps1 +++ b/.github/actions/msbuild/Build-DotNetFrameworkSolutionOrProject.ps1 @@ -1,6 +1,7 @@ param ( [string] $SolutionOrProject, [string] $Verbosity, + [string] $TreatWarningsAsErrors, [string] $EnableCodeAnalysis, [string] $Version, [string] $Switches) @@ -10,26 +11,37 @@ function ConvertTo-Array([string] $rawInput) $rawInput.Replace("`r", "").Split("`n") | ForEach-Object { $PSItem.Trim() } | Where-Object { $PSItem } } +nuget restore $SolutionOrProject + Write-Output ".NET version number: $Version" +$commonSwitches = ConvertTo-Array @" + --verbosity:$Verbosity + -p:RunAnalyzersDuringBuild=$EnableCodeAnalysis + -p:Retries=4 + -p:RetryDelayMilliseconds=1000 + -p:Version=$Version +"@ + +if ($TreatWarningsAsErrors -eq "true") +{ + $commonSwitches += ConvertTo-Array @" + --warnaserror + -p:TreatWarningsAsErrors=true +"@ +} + if (Test-Path src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj) { Write-Output "::group::Gulp Extensions found. It needs to be explicitly built before the solution." # These need to be different than those for msbuild. - $gulpBuildSwitches = ConvertTo-Array @" + $gulpBuildSwitches = $commonSwitches + (ConvertTo-Array @" --configuration:Release --nologo - --verbosity:$Verbosity - --warnaserror --warnAsMessage:MSB3026 --consoleLoggerParameters:NoSummary - -p:TreatWarningsAsErrors=true - -p:RunAnalyzersDuringBuild=$EnableCodeAnalysis - -p:Retries=4 - -p:RetryDelayMilliseconds=1000 - -p:Version=$Version -"@ +"@) $startTime = [DateTime]::Now dotnet build src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj @gulpBuildSwitches @@ -41,18 +53,11 @@ if (Test-Path src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj # -p:Retries and -p:RetryDelayMilliseconds are used to retry builds when they fail due to random locks. -$buildSwitches = ConvertTo-Array @" +$buildSwitches = $commonSwitches + (ConvertTo-Array @" -p:Configuration=Release -restore - --verbosity:$Verbosity - --warnaserror - -p:TreatWarningsAsErrors=true - -p:RunAnalyzersDuringBuild=$EnableCodeAnalysis - -p:Retries=4 - -p:RetryDelayMilliseconds=1000 - -p:Version=$Version $Switches -"@ +"@) Write-Output "Building solution or project with ``msbuild $SolutionOrProject $($buildSwitches -join " ")``." diff --git a/.github/actions/msbuild/action.yml b/.github/actions/msbuild/action.yml index de61cd22d..e0f09add4 100644 --- a/.github/actions/msbuild/action.yml +++ b/.github/actions/msbuild/action.yml @@ -10,6 +10,10 @@ inputs: required: false default: quiet description: Verbosity parameter for msbuild. + treat-warnings-as-errors: + required: false + default: "true" + description: If set to "true", warnings produced during the build will be treated as errors and fail the build. enable-code-analysis: required: false default: "true" @@ -61,6 +65,7 @@ runs: $allSwitches = @{ SolutionOrProject = (Get-ChildItem ${{ inputs.solution-or-project-path }}).FullName Verbosity = "${{ inputs.verbosity }}" + TreatWarningsAsErrors = "${{ inputs.treat-warnings-as-errors }}" EnableCodeAnalysis = "${{ inputs.enable-code-analysis }}" Version = "${{ inputs.publish-version }}" Switches = $givenSwitches diff --git a/.github/workflows/msbuild-and-test.yml b/.github/workflows/msbuild-and-test.yml index f0109f886..882955f67 100644 --- a/.github/workflows/msbuild-and-test.yml +++ b/.github/workflows/msbuild-and-test.yml @@ -42,6 +42,11 @@ on: type: string default: quiet description: Verbosity parameter for msbuild. + build-treat-warnings-as-errors: + required: false + type: string + default: "true" + description: Indicates whether warnings should be treated as errors during msbuild. build-enable-code-analysis: required: false type: string @@ -96,6 +101,7 @@ jobs: directory: ${{ inputs.build-directory }} solution-or-project-path: ${{ inputs.solution-or-project-path }} verbosity: ${{ inputs.build-verbosity }} + treat-warnings-as-errors: ${{ inputs.build-treat-warnings-as-errors }} enable-code-analysis: ${{ inputs.build-enable-code-analysis }} - name: Tests