@@ -17,7 +17,7 @@ public void ProjectsThatDoNotSupportWorkloadsAreNotInspected()
1717 {
1818 var cliHome = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) ;
1919 Directory . CreateDirectory ( cliHome ) ;
20- File . Create ( Path . Combine ( cliHome , "userlocal" ) ) . Dispose ( ) ;
20+ CreateUserLocalFileForCurrentSdk ( cliHome ) ;
2121
2222 var projectPath =
2323 _testAssetsManager
@@ -39,7 +39,7 @@ public void ProjectsThatDoNotSupportWorkloadsAndAreTransitivelyReferencedDoNotBr
3939 {
4040 var cliHome = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) ;
4141 Directory . CreateDirectory ( cliHome ) ;
42- File . Create ( Path . Combine ( cliHome , "userlocal" ) ) . Dispose ( ) ;
42+ CreateUserLocalFileForCurrentSdk ( cliHome ) ;
4343
4444 var projectPath =
4545 _testAssetsManager
@@ -55,4 +55,20 @@ public void ProjectsThatDoNotSupportWorkloadsAndAreTransitivelyReferencedDoNotBr
5555 // if we did try to restore the esproj in this TestAsset we would fail, so passing means we didn't!
5656 . Pass ( ) ;
5757 }
58+
59+ private void CreateUserLocalFileForCurrentSdk ( string cliHome )
60+ {
61+ var result = new DotnetCommand ( Log , "--version" ) . Execute ( ) ;
62+ if ( result . ExitCode != 0 || string . IsNullOrWhiteSpace ( result . StdOut ) )
63+ {
64+ throw new Exception ( "Failed to get dotnet version" ) ;
65+ }
66+ var sdkVersion = result . StdOut . Trim ( ) ;
67+ var version = Version . Parse ( sdkVersion . Split ( '-' ) [ 0 ] ) ;
68+ var featureBand = $ "{ version . Major } .{ version . Minor } .{ ( version . Build / 100 ) * 100 } ";
69+
70+ var userlocalPath = Path . Combine ( cliHome , ".dotnet" , "metadata" , "workloads" , featureBand ) ;
71+ Directory . CreateDirectory ( userlocalPath ) ;
72+ File . Create ( Path . Combine ( userlocalPath , "userlocal" ) ) . Dispose ( ) ;
73+ }
5874}
0 commit comments