33
44using System ;
55using System . Diagnostics ;
6+ using System . Globalization ;
67using System . IO ;
78using System . Linq ;
89using System . Threading . Tasks ;
@@ -34,6 +35,7 @@ public Task RestorePackagesAsync()
3435 try
3536 {
3637 string projectPath = Path . Combine ( Path . GetDirectoryName ( _functionMetadata . Source ) , CSharpConstants . ProjectFileName ) ;
38+ string nugetHome = GetNugetPackagesPath ( ) ;
3739
3840 var startInfo = new ProcessStartInfo
3941 {
@@ -43,7 +45,7 @@ public Task RestorePackagesAsync()
4345 CreateNoWindow = true ,
4446 UseShellExecute = false ,
4547 ErrorDialog = false ,
46- Arguments = "restore \" " + projectPath + " \" "
48+ Arguments = string . Format ( CultureInfo . InvariantCulture , "restore \" {0} \" -PackagesDirectory \" {1} \" " , projectPath , nugetHome )
4749 } ;
4850
4951 var process = new Process { StartInfo = startInfo } ;
@@ -94,6 +96,26 @@ public static string ResolveNuGetPath()
9496 return path ?? NuGetFileName ;
9597 }
9698
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+
97119 private void ProcessDataReceived ( object sender , DataReceivedEventArgs e )
98120 {
99121 _traceWriter . Verbose ( e . Data ?? string . Empty ) ;
0 commit comments