3
3
using System . IO ;
4
4
using System . Linq ;
5
5
using System . Text . RegularExpressions ;
6
+ using Semmle . Util ;
6
7
7
8
namespace Semmle . Extraction . CSharp . DependencyFetching
8
9
{
@@ -13,19 +14,21 @@ internal partial class DotNet : IDotNet
13
14
{
14
15
private readonly IDotNetCliInvoker dotnetCliInvoker ;
15
16
private readonly ProgressMonitor progressMonitor ;
17
+ private readonly TemporaryDirectory ? tempWorkingDirectory ;
16
18
17
- private DotNet ( IDotNetCliInvoker dotnetCliInvoker , ProgressMonitor progressMonitor )
19
+ private DotNet ( IDotNetCliInvoker dotnetCliInvoker , ProgressMonitor progressMonitor , TemporaryDirectory ? tempWorkingDirectory = null )
18
20
{
19
21
this . progressMonitor = progressMonitor ;
22
+ this . tempWorkingDirectory = tempWorkingDirectory ;
20
23
this . dotnetCliInvoker = dotnetCliInvoker ;
21
24
Info ( ) ;
22
25
}
23
26
24
- private DotNet ( IDependencyOptions options , ProgressMonitor progressMonitor ) : this ( new DotNetCliInvoker ( progressMonitor , Path . Combine ( options . DotNetPath ?? string . Empty , "dotnet" ) ) , progressMonitor ) { }
27
+ private DotNet ( IDependencyOptions options , ProgressMonitor progressMonitor , TemporaryDirectory tempWorkingDirectory ) : this ( new DotNetCliInvoker ( progressMonitor , Path . Combine ( options . DotNetPath ?? string . Empty , "dotnet" ) ) , progressMonitor , tempWorkingDirectory ) { }
25
28
26
29
internal static IDotNet Make ( IDotNetCliInvoker dotnetCliInvoker , ProgressMonitor progressMonitor ) => new DotNet ( dotnetCliInvoker , progressMonitor ) ;
27
30
28
- public static IDotNet Make ( IDependencyOptions options , ProgressMonitor progressMonitor ) => new DotNet ( options , progressMonitor ) ;
31
+ public static IDotNet Make ( IDependencyOptions options , ProgressMonitor progressMonitor , TemporaryDirectory tempWorkingDirectory ) => new DotNet ( options , progressMonitor , tempWorkingDirectory ) ;
29
32
30
33
private void Info ( )
31
34
{
@@ -37,12 +40,29 @@ private void Info()
37
40
}
38
41
}
39
42
40
- private static string GetRestoreArgs ( string projectOrSolutionFile , string packageDirectory ) =>
41
- $ "restore --no-dependencies \" { projectOrSolutionFile } \" --packages \" { packageDirectory } \" /p:DisableImplicitNuGetFallbackFolder=true";
43
+ private string GetRestoreArgs ( string projectOrSolutionFile , string packageDirectory , bool forceDotnetRefAssemblyFetching )
44
+ {
45
+ var args = $ "restore --no-dependencies \" { projectOrSolutionFile } \" --packages \" { packageDirectory } \" /p:DisableImplicitNuGetFallbackFolder=true";
46
+
47
+ if ( forceDotnetRefAssemblyFetching )
48
+ {
49
+ // Ugly hack: we set the TargetFrameworkRootPath and NetCoreTargetingPackRoot properties to an empty folder:
50
+ var path = ".empty" ;
51
+ if ( tempWorkingDirectory != null )
52
+ {
53
+ path = Path . Combine ( tempWorkingDirectory . ToString ( ) , "emptyFakeDotnetRoot" ) ;
54
+ Directory . CreateDirectory ( path ) ;
55
+ }
56
+
57
+ args += $ " /p:TargetFrameworkRootPath=\" { path } \" /p:NetCoreTargetingPackRoot=\" { path } \" ";
58
+ }
59
+
60
+ return args ;
61
+ }
42
62
43
- public bool RestoreProjectToDirectory ( string projectFile , string packageDirectory , string ? pathToNugetConfig = null )
63
+ public bool RestoreProjectToDirectory ( string projectFile , string packageDirectory , bool forceDotnetRefAssemblyFetching , string ? pathToNugetConfig = null )
44
64
{
45
- var args = GetRestoreArgs ( projectFile , packageDirectory ) ;
65
+ var args = GetRestoreArgs ( projectFile , packageDirectory , forceDotnetRefAssemblyFetching ) ;
46
66
if ( pathToNugetConfig != null )
47
67
{
48
68
args += $ " --configfile \" { pathToNugetConfig } \" ";
@@ -51,9 +71,9 @@ public bool RestoreProjectToDirectory(string projectFile, string packageDirector
51
71
return dotnetCliInvoker . RunCommand ( args ) ;
52
72
}
53
73
54
- public bool RestoreSolutionToDirectory ( string solutionFile , string packageDirectory , out IEnumerable < string > projects )
74
+ public bool RestoreSolutionToDirectory ( string solutionFile , string packageDirectory , bool forceDotnetRefAssemblyFetching , out IEnumerable < string > projects )
55
75
{
56
- var args = GetRestoreArgs ( solutionFile , packageDirectory ) ;
76
+ var args = GetRestoreArgs ( solutionFile , packageDirectory , forceDotnetRefAssemblyFetching ) ;
57
77
args += " --verbosity normal" ;
58
78
if ( dotnetCliInvoker . RunCommand ( args , out var output ) )
59
79
{
0 commit comments