@@ -17,7 +17,7 @@ public void ProjectsThatDoNotSupportWorkloadsAreNotInspected()
17
17
{
18
18
var cliHome = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) ;
19
19
Directory . CreateDirectory ( cliHome ) ;
20
- File . Create ( Path . Combine ( cliHome , "userlocal" ) ) . Dispose ( ) ;
20
+ CreateUserLocalFileForCurrentSdk ( cliHome ) ;
21
21
22
22
var projectPath =
23
23
_testAssetsManager
@@ -39,7 +39,7 @@ public void ProjectsThatDoNotSupportWorkloadsAndAreTransitivelyReferencedDoNotBr
39
39
{
40
40
var cliHome = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) ;
41
41
Directory . CreateDirectory ( cliHome ) ;
42
- File . Create ( Path . Combine ( cliHome , "userlocal" ) ) . Dispose ( ) ;
42
+ CreateUserLocalFileForCurrentSdk ( cliHome ) ;
43
43
44
44
var projectPath =
45
45
_testAssetsManager
@@ -55,4 +55,20 @@ public void ProjectsThatDoNotSupportWorkloadsAndAreTransitivelyReferencedDoNotBr
55
55
// if we did try to restore the esproj in this TestAsset we would fail, so passing means we didn't!
56
56
. Pass ( ) ;
57
57
}
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
+ }
58
74
}
0 commit comments