3
3
4
4
using System ;
5
5
using System . Diagnostics ;
6
+ using System . Globalization ;
6
7
using System . IO ;
7
8
using System . Linq ;
8
9
using System . Threading . Tasks ;
@@ -34,6 +35,7 @@ public Task RestorePackagesAsync()
34
35
try
35
36
{
36
37
string projectPath = Path . Combine ( Path . GetDirectoryName ( _functionMetadata . Source ) , CSharpConstants . ProjectFileName ) ;
38
+ string nugetHome = GetNugetPackagesPath ( ) ;
37
39
38
40
var startInfo = new ProcessStartInfo
39
41
{
@@ -43,7 +45,7 @@ public Task RestorePackagesAsync()
43
45
CreateNoWindow = true ,
44
46
UseShellExecute = false ,
45
47
ErrorDialog = false ,
46
- Arguments = "restore \" " + projectPath + " \" "
48
+ Arguments = string . Format ( CultureInfo . InvariantCulture , "restore \" {0} \" -PackagesDirectory \" {1} \" " , projectPath , nugetHome )
47
49
} ;
48
50
49
51
var process = new Process { StartInfo = startInfo } ;
@@ -94,6 +96,26 @@ public static string ResolveNuGetPath()
94
96
return path ?? NuGetFileName ;
95
97
}
96
98
99
+ internal static string GetNugetPackagesPath ( )
100
+ {
101
+ string nugetHome = null ;
102
+ string home = Environment . GetEnvironmentVariable ( "HOME" ) ;
103
+ if ( ! string . IsNullOrEmpty ( home ) )
104
+ {
105
+ // We're hosted in Azure
106
+ // Set the NuGet path to %home%\data\Functions\packages\nuget
107
+ // (i.e. d:\home\data\Functions\packages\nuget)
108
+ nugetHome = Path . Combine ( home , "data\\ Functions\\ packages\\ nuget" ) ;
109
+ }
110
+ else
111
+ {
112
+ string userProfile = Environment . ExpandEnvironmentVariables ( "%userprofile%" ) ;
113
+ nugetHome = Path . Combine ( userProfile , ".nuget\\ packages" ) ;
114
+ }
115
+
116
+ return nugetHome ;
117
+ }
118
+
97
119
private void ProcessDataReceived ( object sender , DataReceivedEventArgs e )
98
120
{
99
121
_traceWriter . Verbose ( e . Data ?? string . Empty ) ;
0 commit comments