@@ -86,18 +86,13 @@ var isTagged = BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag && !string.
8686var isIntegrationTestsProjectPresent = FileExists( integrationTestsProject ) ;
8787var isUnitTestsProjectPresent = FileExists ( unitTestsProject ) ;
8888var isBenchmarkProjectPresent = FileExists ( benchmarkProject ) ;
89- var removeIntegrationTests = isIntegrationTestsProjectPresent && ( ! isLocalBuild || target == "coverage" ) ;
90- var removeBenchmarks = isBenchmarkProjectPresent && ( ! isLocalBuild || target == "coverage" ) ;
9189
9290var publishingError = false;
9391
94- // Generally speaking, we want to honor all the TFM configured in the source project and the unit test project.
95- // However, there are a few scenarios where a single framework is sufficient. Here are a few examples that come to mind:
96- // - when building source project on Ubuntu
97- // - when running unit tests on Ubuntu
98- // - when calculating code coverage
92+ // Generally speaking, we want to honor all the TFM configured in the unit tests, integration tests and benchmark projects.
93+ // However, a single framework is sufficient when calculating code coverage.
9994const string DEFAULT_FRAMEWORK = "net9.0" ;
100- var isSingleTfmMode = ! IsRunningOnWindows ( ) ||
95+ var isSingleTfmMode =
10196 target. Equals( "Coverage" , StringComparison . OrdinalIgnoreCase ) ||
10297 target . Equals ( "Run-Code-Coverage" , StringComparison . OrdinalIgnoreCase ) ||
10398 target . Equals ( "Generate-Code-Coverage-Report" , StringComparison . OrdinalIgnoreCase ) ||
@@ -158,49 +153,17 @@ Setup(context =>
158153 ) ;
159154 }
160155
161- // Integration tests are intended to be used for debugging purposes and not intended to be executed in CI environment.
162- // Also, the runner for these tests contains windows-specific code (such as resizing window, moving window to center of screen, etc.)
163- // which can cause problems when attempting to run unit tests on an Ubuntu image on AppVeyor.
164- if ( removeIntegrationTests )
165- {
166- Information ( "" ) ;
167- Information ( "Removing integration tests" ) ;
168- DotNetTool ( solutionFile , "sln" , $ "remove { integrationTestsProject . TrimStart ( sourceFolder , StringComparison . OrdinalIgnoreCase ) } ") ;
169- }
170-
171- // Similarly, benchmarking can causes problems similar to this one:
172- // error NETSDK1005: Assets file '/home/appveyor/projects/stronggrid/Source/StrongGrid.Benchmark/obj/project.assets.json' doesn't have a target for 'net5.0'.
173- // Ensure that restore has run and that you have included 'net5.0' in the TargetFrameworks for your project.
174- if ( removeBenchmarks )
175- {
176- Information ( "" ) ;
177- Information ( "Removing benchmark project" ) ;
178- DotNetTool ( solutionFile , "sln" , $ "remove { benchmarkProject . TrimStart ( sourceFolder , StringComparison . OrdinalIgnoreCase ) } ") ;
179- }
180-
181156 // In single TFM mode we want to override the framework(s) with our desired framework
182157 if ( isSingleTfmMode )
183158 {
184- var peekSettings = new XmlPeekSettings { SuppressWarning = true } ;
185- foreach ( var projectFile in GetFiles ( "./Source/**/*.csproj" ) )
186- {
187- Information ( "Updating TFM in: {0}" , projectFile . ToString ( ) ) ;
188- if ( XmlPeek ( projectFile , "/Project/PropertyGroup/TargetFramework" , peekSettings ) != null ) XmlPoke ( projectFile , "/Project/PropertyGroup/TargetFramework" , DEFAULT_FRAMEWORK ) ;
189- if ( XmlPeek ( projectFile , "/Project/PropertyGroup/TargetFrameworks" , peekSettings ) != null ) XmlPoke ( projectFile , "/Project/PropertyGroup/TargetFrameworks" , DEFAULT_FRAMEWORK ) ;
190- }
159+ if ( isUnitTestsProjectPresent ) Context . UpdateProjectTarget ( unitTestsProject , DEFAULT_FRAMEWORK ) ;
160+ if ( isBenchmarkProjectPresent ) Context . UpdateProjectTarget ( benchmarkProject , DEFAULT_FRAMEWORK ) ;
161+ if ( isIntegrationTestsProjectPresent ) Context . UpdateProjectTarget ( integrationTestsProject , DEFAULT_FRAMEWORK ) ;
191162 }
192163} ) ;
193164
194165Teardown( context =>
195166{
196- if ( removeIntegrationTests || removeBenchmarks )
197- {
198- Information ( "Restoring projects that may have been removed during build script setup" ) ;
199- GitCheckout ( "." , new FilePath [ ] { solutionFile } ) ;
200- Information ( " Restored {0}" , solutionFile . ToString ( ) ) ;
201- Information ( "" ) ;
202- }
203-
204167 if ( isSingleTfmMode )
205168 {
206169 Information ( "Restoring project files that may have been modified during build script setup" ) ;
@@ -265,7 +228,6 @@ Task("Build")
265228 DotNetBuild ( solutionFile , new DotNetBuildSettings
266229 {
267230 Configuration = configuration ,
268- Framework = isSingleTfmMode ? DEFAULT_FRAMEWORK : null ,
269231 NoRestore = true ,
270232 MSBuildSettings = new DotNetMSBuildSettings
271233 {
@@ -288,7 +250,6 @@ Task("Run-Unit-Tests")
288250 NoBuild = true ,
289251 NoRestore = true ,
290252 Configuration = configuration ,
291- Framework = isSingleTfmMode ? DEFAULT_FRAMEWORK : null
292253 } ) ;
293254} ) ;
294255
@@ -302,7 +263,6 @@ Task("Run-Code-Coverage")
302263 NoBuild = true ,
303264 NoRestore = true ,
304265 Configuration = configuration ,
305- Framework = isSingleTfmMode ? DEFAULT_FRAMEWORK : null ,
306266
307267 // The following assumes that coverlet.msbuild has been added to the unit testing project
308268 ArgumentCustomization = args => args
@@ -618,7 +578,7 @@ private static string GetBuildBranch(this ICakeContext context)
618578 return repositoryBranch;
619579}
620580
621- public static string GetRepoName ( this ICakeContext context )
581+ private static string GetRepoName ( this ICakeContext context )
622582{
623583 var buildSystem = context . BuildSystem ( ) ;
624584
@@ -631,3 +591,14 @@ public static string GetRepoName(this ICakeContext context)
631591 var parts = originUrl . Split ( '/' , StringSplitOptions . RemoveEmptyEntries ) ;
632592 return $"{ parts [ parts . Length - 2 ] } / { parts [ parts . Length - 1 ] . Replace ( ".git" , "" ) } ";
633593}
594+
595+ private static void UpdateProjectTarget ( this ICakeContext context , string path , string desiredTarget )
596+ {
597+ var peekSettings = new XmlPeekSettings { SuppressWarning = true } ;
598+ foreach ( var projectFile in context. GetFiles ( path ) )
599+ {
600+ context . Information ( "Updating TFM in: {0}" , projectFile . ToString ( ) ) ;
601+ if ( context . XmlPeek ( projectFile , "/Project/PropertyGroup/TargetFramework" , peekSettings ) != null ) context. XmlPoke ( projectFile , "/Project/PropertyGroup/TargetFramework" , desiredTarget ) ;
602+ if ( context . XmlPeek ( projectFile , "/Project/PropertyGroup/TargetFrameworks" , peekSettings ) != null ) context. XmlPoke ( projectFile , "/Project/PropertyGroup/TargetFrameworks" , desiredTarget ) ;
603+ }
604+ }
0 commit comments