Skip to content

Commit

Permalink
Make the build compatible with .NET 9 SDK
Browse files Browse the repository at this point in the history
* Move all warning-as-error handling to build.props
* Disable warning-as-error in Debug builds
* Lower AnalysisLevel to .NET 8 wave when treating warnings as errors in Release
  • Loading branch information
nguerrera committed Nov 18, 2024
1 parent a4a0d6d commit 01eaa5e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion scripts/BuildAndTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function Invoke-DotNetBuild($solutionFileRelativePath) {
Write-Information "Building $solutionFileRelativePath..."

$solutionFilePath = Join-Path $SourceRoot $solutionFileRelativePath
& dotnet build $solutionFilePath --configuration $Configuration --verbosity $BuildVerbosity --no-incremental -bl -p:WarningsAsErrors="MSB3277" /p:EnforceCodeStyleInBuild=true
& dotnet build $solutionFilePath --configuration $Configuration --verbosity $BuildVerbosity --no-incremental -bl /p:EnforceCodeStyleInBuild=true

if ($LASTEXITCODE -ne 0) {
Exit-WithFailureMessage $ScriptName "Build of $solutionFilePath failed."
Expand Down
44 changes: 29 additions & 15 deletions src/build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<AnalysisMode>Default</AnalysisMode>
<AnalysisLevel>latest</AnalysisLevel>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

Expand All @@ -18,10 +21,6 @@

<!-- The stable version of the SARIF specification. -->
<StableSarifVersion>2.1.0</StableSarifVersion>

<AnalysisLevel>latest</AnalysisLevel>
<LangVersion>latest</LangVersion>

</PropertyGroup>

<PropertyGroup Label="Build">
Expand All @@ -40,10 +39,6 @@
<PackageOutputPath>$(MsBuildThisFileDirectory)..\bld\Publish\Nuget\$(Configuration)\</PackageOutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<!-- These can change externally, breaking our build. -->
<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>
<HighEntropyVA>true</HighEntropyVA>
<!-- The line causes the assemblies in a project's referenced NuGet packages to be
copied to the output directory. If we omit it from a test project, the tests
Expand All @@ -52,6 +47,31 @@
<CopyLocalLockFileAssemblies Condition="'$(IsTestProject)' == 'true'">true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<!--
NOTE: We only turn on warnings-as-errors in Release because it hurts
iteration time in the IDE to error out while the code is still
work-in-progress.
-->
<PropertyGroup Label="WarningsAsErrors" Condition="'$(Configuration)' == 'Release'">
<!-- Treat compiler warnings as errors. -->
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<!-- Treat all build warnings as errors -->
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>

<!--
NU190X are security vulnerability warnings and can trigger without code
changes. Don't let them break the build.
-->
<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>

<!--
We are not yet clean on new analysis introduced with .NET 9 SDK so lower
the analysis level when treating warnings as errors in Release.
-->
<AnalysisLevel>8</AnalysisLevel>
</PropertyGroup>

<!-- Configuration specific properties -->
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "
Label="Debug build">
Expand Down Expand Up @@ -117,10 +137,4 @@
<EmbeddedFiles Include="$(GeneratedAssemblyInfoFile)" />
<SourceRoot Include="$(MSBuildThisFileDirectory)/" />
</ItemGroup>

<PropertyGroup>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisMode>Default</AnalysisMode>
<AnalysisLevel>latest</AnalysisLevel>
</PropertyGroup>
</Project>

0 comments on commit 01eaa5e

Please sign in to comment.