@@ -86,17 +86,19 @@ var isTagged = BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag && !string.
8686var isIntegrationTestsProjectPresent = FileExists( integrationTestsProject ) ;
8787var isUnitTestsProjectPresent = FileExists ( unitTestsProject ) ;
8888var isBenchmarkProjectPresent = FileExists ( benchmarkProject ) ;
89+ var isCodeCoverageTarget = target . Equals( "Coverage" , StringComparison . OrdinalIgnoreCase ) ||
90+ target . Equals ( "Run-Code-Coverage" , StringComparison . OrdinalIgnoreCase ) ||
91+ target . Equals ( "Generate-Code-Coverage-Report" , StringComparison . OrdinalIgnoreCase ) ||
92+ target . Equals ( "Upload-Coverage-Result" , StringComparison . OrdinalIgnoreCase ) ;
93+ var removeIntegrationTests = isIntegrationTestsProjectPresent && ( ! isLocalBuild || isCodeCoverageTarget ) ;
94+ var removeBenchmarks = isBenchmarkProjectPresent && ( ! isLocalBuild || isCodeCoverageTarget ) ;
8995
9096var publishingError = false ;
9197
9298// Generally speaking, we want to honor all the TFM configured in the unit tests, integration tests and benchmark projects.
9399// However, a single framework is sufficient when calculating code coverage.
94100const string DEFAULT_FRAMEWORK = "net9.0" ;
95- var isSingleTfmMode = ( IsRunningOnWindows ( ) && BuildSystem . AppVeyor . IsRunningOnAppVeyor ) ||
96- target . Equals( "Coverage" , StringComparison . OrdinalIgnoreCase ) ||
97- target . Equals ( "Run-Code-Coverage" , StringComparison . OrdinalIgnoreCase ) ||
98- target . Equals ( "Generate-Code-Coverage-Report" , StringComparison . OrdinalIgnoreCase ) ||
99- target . Equals ( "Upload-Coverage-Result" , StringComparison . OrdinalIgnoreCase ) ;
101+ var isSingleTfmMode = ( IsRunningOnWindows ( ) && ! isLocalBuild ) || isCodeCoverageTarget ;
100102
101103
102104///////////////////////////////////////////////////////////////////////////////
@@ -154,23 +156,41 @@ Setup(context =>
154156 }
155157
156158 // In single TFM mode we want to override the framework(s) with our desired framework
157- if ( isSingleTfmMode )
159+ if ( isSingleTfmMode && isUnitTestsProjectPresent ) Context . UpdateProjectTarget ( unitTestsProject , DEFAULT_FRAMEWORK ) ;
160+
161+ // Integration tests are intended to be used for debugging purposes and not intended to be executed in CI environment.
162+ if ( removeIntegrationTests )
158163 {
159- if ( isUnitTestsProjectPresent ) Context . UpdateProjectTarget ( unitTestsProject , DEFAULT_FRAMEWORK ) ;
160- if ( isBenchmarkProjectPresent ) Context . UpdateProjectTarget ( benchmarkProject , DEFAULT_FRAMEWORK ) ;
161- if ( isIntegrationTestsProjectPresent ) Context . UpdateProjectTarget ( integrationTestsProject , DEFAULT_FRAMEWORK ) ;
164+ Information ( "" ) ;
165+ Information ( "Removing integration tests" ) ;
166+ DotNetTool ( solutionFile , "sln" , $ "remove { integrationTestsProject . TrimStart ( sourceFolder , StringComparison . OrdinalIgnoreCase ) } ") ;
167+ }
168+
169+ // Similarly, benchmarks are not intended to be executed in CI environment.
170+ if ( removeBenchmarks )
171+ Information ( "" ) ;
172+ Information ( "Removing benchmark project" ) ;
173+ DotNetTool ( solutionFile , "sln" , $ "remove { benchmarkProject . TrimStart ( sourceFolder , StringComparison . OrdinalIgnoreCase ) } ") ;
162174 }
163175} ) ;
164176
165177Teardown( context =>
166178{
167179 if ( isSingleTfmMode )
168180 {
169- Information ( "Restoring project files that may have been modified during build script setup" ) ;
181+ Information ( "Restoring project files that were modified during build script setup" ) ;
170182 GitCheckout ( "." , GetFiles ( "./Source/**/*.csproj" ) . ToArray ( ) ) ;
171183 Information ( "" ) ;
172184 }
173185
186+ if ( removeIntegrationTests || removeBenchmarks )
187+ {
188+ Information ( "Restoring the solution file which was modified during build script setup" ) ;
189+ GitCheckout ( "." , new FilePath [ ] { solutionFile } ) ;
190+ Information ( " Restored {0}" , solutionFile . ToString ( ) ) ;
191+ Information ( "" ) ;
192+ }
193+
174194 // Executed AFTER the last task.
175195 Information ( "Finished running tasks." ) ;
176196} ) ;
0 commit comments