Skip to content

Commit 6035eaa

Browse files
committed
Changing the NuGet package path
1 parent 89b1465 commit 6035eaa

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/WebJobs.Script/Description/CSharp/PackageAssemblyResolver.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ private static IDictionary<string, string> InitializeAssemblyRegistry(FunctionMe
4747

4848
if (target != null)
4949
{
50-
string userProfile = Environment.ExpandEnvironmentVariables("%userprofile%");
51-
string nugetHome = Path.Combine(userProfile, ".nuget\\packages");
50+
string nugetHome = PackageManager.GetNugetPackagesPath();
5251

5352
List<string> assemblyReferences = new List<string>();
5453
List<string> frameworkAssemblyReferences = new List<string>();

src/WebJobs.Script/Description/CSharp/PackageManager.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics;
6+
using System.Globalization;
67
using System.IO;
78
using System.Linq;
89
using 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

Comments
 (0)