@@ -33,6 +33,19 @@ public void AddProjectToSolutionPostActionFindSolutionFileAtOutputPath()
33
33
public void AddProjectToSolutionPostActionFindSlnxFileAtOutputPath ( )
34
34
{
35
35
string targetBasePath = _engineEnvironmentSettings . GetTempVirtualizedPath ( ) ;
36
+ _engineEnvironmentSettings . Host . VirtualizeDirectory ( targetBasePath ) ;
37
+
38
+ // Ensure parent directories exist to avoid DirectoryNotFoundException during traversal
39
+ string ? currentPath = targetBasePath ;
40
+ while ( ! string . IsNullOrEmpty ( currentPath ) && currentPath != Path . GetPathRoot ( currentPath ) )
41
+ {
42
+ if ( ! _engineEnvironmentSettings . Host . FileSystem . DirectoryExists ( currentPath ) )
43
+ {
44
+ _engineEnvironmentSettings . Host . FileSystem . CreateDirectory ( currentPath ) ;
45
+ }
46
+ currentPath = Path . GetDirectoryName ( currentPath ) ;
47
+ }
48
+
36
49
string solutionFileFullPath = Path . Combine ( targetBasePath , "MySln.slnx" ) ;
37
50
_engineEnvironmentSettings . Host . FileSystem . WriteAllText ( solutionFileFullPath , string . Empty ) ;
38
51
@@ -45,6 +58,19 @@ public void AddProjectToSolutionPostActionFindSlnxFileAtOutputPath()
45
58
public void AddProjectToSolutionPostActionPrefersSlnOverSlnx ( )
46
59
{
47
60
string targetBasePath = _engineEnvironmentSettings . GetTempVirtualizedPath ( ) ;
61
+ _engineEnvironmentSettings . Host . VirtualizeDirectory ( targetBasePath ) ;
62
+
63
+ // Ensure parent directories exist to avoid DirectoryNotFoundException during traversal
64
+ string ? currentPath = targetBasePath ;
65
+ while ( ! string . IsNullOrEmpty ( currentPath ) && currentPath != Path . GetPathRoot ( currentPath ) )
66
+ {
67
+ if ( ! _engineEnvironmentSettings . Host . FileSystem . DirectoryExists ( currentPath ) )
68
+ {
69
+ _engineEnvironmentSettings . Host . FileSystem . CreateDirectory ( currentPath ) ;
70
+ }
71
+ currentPath = Path . GetDirectoryName ( currentPath ) ;
72
+ }
73
+
48
74
string slnFileFullPath = Path . Combine ( targetBasePath , "MySln.sln" ) ;
49
75
string slnxFileFullPath = Path . Combine ( targetBasePath , "MySln.slnx" ) ;
50
76
_engineEnvironmentSettings . Host . FileSystem . WriteAllText ( slnFileFullPath , string . Empty ) ;
0 commit comments