@@ -9,14 +9,42 @@ namespace ElectronNET.IntegrationTests.Tests;
99/// </summary>
1010public class MigrationChecksTargetsTests
1111{
12- // AppContext.BaseDirectory resolves to:
13- // src\ElectronNET.IntegrationTests\bin\Debug\net10.0\win-x64\
14- // Five levels up => src\
15- private static readonly string TargetsFilePath = Path . GetFullPath (
16- Path . Combine (
17- AppContext . BaseDirectory ,
18- ".." , ".." , ".." , ".." , ".." ,
19- "ElectronNET" , "build" , "ElectronNET.MigrationChecks.targets" ) ) ;
12+ private static readonly string TargetsFilePath = FindTargetsFile ( ) ;
13+
14+ /// <summary>
15+ /// Walks up the directory tree from <see cref="AppContext.BaseDirectory"/> until it finds
16+ /// the migration checks targets file. This is robust against varying output paths
17+ /// (with or without RID subfolder, debug/release, etc.).
18+ /// </summary>
19+ private static string FindTargetsFile ( )
20+ {
21+ const string RelativeFromRepoRoot =
22+ "src/ElectronNET/build/ElectronNET.MigrationChecks.targets" ;
23+ const string RelativeFromSrc =
24+ "ElectronNET/build/ElectronNET.MigrationChecks.targets" ;
25+
26+ var dir = new DirectoryInfo ( AppContext . BaseDirectory ) ;
27+ while ( dir != null )
28+ {
29+ var fromRepoRoot = Path . Combine ( dir . FullName , RelativeFromRepoRoot ) ;
30+ if ( File . Exists ( fromRepoRoot ) )
31+ {
32+ return Path . GetFullPath ( fromRepoRoot ) ;
33+ }
34+
35+ var fromSrc = Path . Combine ( dir . FullName , RelativeFromSrc ) ;
36+ if ( File . Exists ( fromSrc ) )
37+ {
38+ return Path . GetFullPath ( fromSrc ) ;
39+ }
40+
41+ dir = dir . Parent ;
42+ }
43+
44+ throw new FileNotFoundException (
45+ "Could not locate ElectronNET.MigrationChecks.targets by walking up from " +
46+ $ "'{ AppContext . BaseDirectory } '.") ;
47+ }
2048
2149 // -----------------------------------------------------------------------
2250 // Content-level test (RED before fix, GREEN after fix on ALL platforms)
0 commit comments