Skip to content

Commit a521829

Browse files
Francisco-Gaminodaxian-dbw
authored andcommitted
Updating Managed Dependencies folder installation path for local development. (Azure#190)
1 parent cf483fc commit a521829

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/DependencyManagement/DependencyManager.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ internal class DependencyManager
4545
// Central repository for acquiring PowerShell modules.
4646
private const string Repository = "PSGallery";
4747

48+
// AzureFunctions folder name.
49+
private const string AzureFunctionsFolderName = "AzureFunctions";
50+
4851
// Managed Dependencies folder name.
4952
private const string ManagedDependenciesFolderName = "ManagedDependencies";
5053

@@ -305,9 +308,9 @@ private void ValidateModuleName(string name)
305308
/// <summary>
306309
/// Gets the Managed Dependencies folder path.
307310
/// If we are running in Azure, the path is HOME\data\ManagedDependencies.
308-
/// Otherwise, the path is functionAppRoot\ManagedDependencies.
311+
/// Otherwise, the path is LocalApplicationData\AzureFunctions\FunctionAppName\ManagedDependencies.
309312
/// </summary>
310-
private string GetManagedDependenciesPath(string functionAppRoot)
313+
private string GetManagedDependenciesPath(string functionAppRootPath)
311314
{
312315
string managedDependenciesFolderPath = null;
313316

@@ -325,8 +328,10 @@ private string GetManagedDependenciesPath(string functionAppRoot)
325328
}
326329
else
327330
{
328-
// Otherwise, the ManagedDependencies folder is created under the function app root.
329-
managedDependenciesFolderPath = Path.Join(functionAppRoot, ManagedDependenciesFolderName);
331+
// Otherwise, the ManagedDependencies folder is created under LocalApplicationData\AzureFunctions\FunctionAppName\ManagedDependencies.
332+
string functionAppName = Path.GetFileName(functionAppRootPath);
333+
string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify);
334+
managedDependenciesFolderPath = Path.Combine(appDataFolder, AzureFunctionsFolderName, functionAppName, ManagedDependenciesFolderName);
330335
}
331336

332337
return managedDependenciesFolderPath;

test/Unit/DependencyManagement/DependencyManagementTests.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class DependencyManagementTests
1616
private readonly string _dependencyManagementDirectory;
1717
private readonly string _functionId;
1818
private const string ManagedDependenciesFolderName = "ManagedDependencies";
19+
private const string AzureFunctionsFolderName = "AzureFunctions";
1920

2021
public DependencyManagementTests()
2122
{
@@ -42,6 +43,14 @@ private FunctionLoadRequest GetFuncLoadRequest(string functionAppRoot, bool mana
4243
return functionLoadRequest;
4344
}
4445

46+
private string GetManagedDependenciesPath(string functionAppRootPath)
47+
{
48+
string functionAppName = Path.GetFileName(functionAppRootPath);
49+
string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify);
50+
string managedDependenciesFolderPath = Path.Combine(appDataFolder, AzureFunctionsFolderName, functionAppName, ManagedDependenciesFolderName);
51+
return managedDependenciesFolderPath;
52+
}
53+
4554
private void TestCaseCleanup()
4655
{
4756
// We run a test case clean up to reset DependencyManager.Dependencies and DependencyManager.DependenciesPath
@@ -66,10 +75,10 @@ public void TestManagedDependencyBasicRequirements()
6675
{
6776
// Test case setup.
6877
var requirementsDirectoryName = "BasicRequirements";
69-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName,
70-
"FunctionDirectory");
71-
var managedDependenciesFolderPath = Path.Combine(_dependencyManagementDirectory,
72-
requirementsDirectoryName, ManagedDependenciesFolderName);
78+
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
79+
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
80+
var managedDependenciesFolderPath = GetManagedDependenciesPath(functionAppRoot);
81+
7382
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
7483

7584
// Create DependencyManager and process the requirements.psd1 file at the function app root.
@@ -97,10 +106,9 @@ public void TestManagedDependencyEmptyHashtableRequirement()
97106
{
98107
// Test case setup.
99108
var requirementsDirectoryName = "EmptyHashtableRequirement";
100-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName,
101-
"FunctionDirectory");
102-
var managedDependenciesFolderPath = Path.Combine(_dependencyManagementDirectory,
103-
requirementsDirectoryName, ManagedDependenciesFolderName);
109+
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName,"FunctionDirectory");
110+
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
111+
var managedDependenciesFolderPath = GetManagedDependenciesPath(functionAppRoot);
104112
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
105113

106114
// Create DependencyManager and process the requirements.psd1 file at the function app root.

0 commit comments

Comments
 (0)