@@ -454,37 +454,32 @@ public static string GetRunningProcessAsString(Dictionary<string, Process>? proc
454
454
/// </summary>
455
455
/// <param name="path1">The path of the first file to swap</param>
456
456
/// <param name="path2">The path of the file to swap it with</param>
457
- public static void SwapFiles ( string path1 , string path2 )
457
+ private static void SwapFiles ( string path1 , string path2 )
458
458
{
459
- string tempFile = Path . GetTempFileName ( ) ;
460
- string file1Name = Path . GetFileName ( path1 ) ;
461
- string file2Name = Path . GetFileName ( path2 ) ;
462
- string file1Dir = Path . GetDirectoryName ( path1 ) ;
463
- string file2Dir = Path . GetDirectoryName ( path2 ) ;
459
+ // Read the contents of both files
460
+ string file1Contents = File . ReadAllText ( path1 ) ;
461
+ string file2Contents = File . ReadAllText ( path2 ) ;
464
462
465
- // Move file1 to tempFile
466
- File . Move ( path1 , tempFile ) ;
463
+ // Write the contents of file2 to file1
464
+ File . WriteAllText ( path1 , file2Contents ) ;
467
465
468
- // Move file2 to file1's original location and rename it to file1's name
469
- File . Move ( path2 , Path . Combine ( file1Dir , file1Name ) ) ;
466
+ // Write the contents of file1 to file2
467
+ File . WriteAllText ( path2 , file1Contents ) ;
470
468
471
- // Move tempFile (original file1) to file2's original location and rename it to file2's name
472
- File . Move ( tempFile , Path . Combine ( file2Dir , file2Name ) ) ;
473
-
474
- Console . WriteLine ( "Files swapped and renamed successfully." ) ;
469
+ Console . WriteLine ( "File contents swapped successfully." ) ;
475
470
}
476
471
477
472
478
- public static void RebuildSolution ( string solutionPath )
473
+ private static void RebuildSolution ( string solutionPath )
479
474
{
480
475
ProcessStartInfo startInfo = new ProcessStartInfo
481
476
{
482
477
FileName = "dotnet" ,
483
- Arguments = $ "build { solutionPath } --no-incremental ",
478
+ Arguments = $ "build { solutionPath } ",
484
479
RedirectStandardOutput = true ,
485
480
RedirectStandardError = true ,
486
481
UseShellExecute = false ,
487
- CreateNoWindow = true
482
+ CreateNoWindow = false
488
483
} ;
489
484
490
485
using ( Process process = new Process ( ) )
@@ -502,15 +497,22 @@ public static void RebuildSolution(string solutionPath)
502
497
Console . WriteLine ( "Solution rebuild initiated." ) ;
503
498
}
504
499
505
- public static void BuildSampleWithTestAppsettings ( string testAssemblyLocation , string appLocation , string testAppsettingsName )
500
+ public static void BuildSampleWithTestAppsettings (
501
+ string testAssemblyLocation ,
502
+ string appLocation ,
503
+ string testAppsettingsPathFromRepoRoot ,
504
+ string solutionFileName
505
+ )
506
506
{
507
507
string appsettingsDirectory = GetAppsettingsDirectory ( testAssemblyLocation , appLocation ) ;
508
508
string appsettingsPath = Path . Combine ( appsettingsDirectory , TestConstants . AppSetttingsDotJson ) ;
509
- string testAppsettingsPath = Path . Combine ( appsettingsDirectory , testAppsettingsName ) ;
510
- SwapFiles ( appsettingsPath , testAppsettingsPath ) ;
511
- RebuildSolution ( appsettingsDirectory ) ;
509
+ string testAppsettingsPath = GetAppsettingsDirectory ( testAssemblyLocation , testAppsettingsPathFromRepoRoot ) ;
510
+
512
511
SwapFiles ( appsettingsPath , testAppsettingsPath ) ;
513
512
513
+ try { RebuildSolution ( appsettingsDirectory + solutionFileName ) ; }
514
+ catch ( Exception ) { throw ; }
515
+ finally { SwapFiles ( appsettingsPath , testAppsettingsPath ) ; }
514
516
}
515
517
}
516
518
0 commit comments