Skip to content

Commit 6bcde79

Browse files
Update requirements.psd1 template for PowerShell function apps (#7073)
1 parent d5840d3 commit 6bcde79

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

src/WebJobs.Script/FileProvisioning/PowerShell/PowerShellFileProvisioner.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,27 @@ private void AddRequirementsFile(string scriptRootPath)
6262
string requirementsContent = FileUtility.ReadResourceString(RequirementsPsd1ResourceFileName);
6363
string guidance = null;
6464

65+
bool majorVersionRetrievedSuccessfully = false;
66+
6567
try
6668
{
6769
string majorVersion = GetLatestAzModuleMajorVersion();
68-
69-
requirementsContent = Regex.Replace(requirementsContent, @"#(\s?)'Az'", "'Az'");
7070
requirementsContent = Regex.Replace(requirementsContent, "MAJOR_VERSION", majorVersion);
71+
72+
majorVersionRetrievedSuccessfully = true;
7173
}
7274
catch
7375
{
74-
guidance = "Uncomment the next line and replace the MAJOR_VERSION, e.g., 'Az' = '2.*'";
76+
guidance = "Uncomment the next line and replace the MAJOR_VERSION, e.g., 'Az' = '5.*'";
7577
_logger.LogDebug($"Failed to get Az module version. Edit the {RequirementsPsd1FileName} file when the powershellgallery.com is accessible.");
7678
}
7779

78-
requirementsContent = Regex.Replace(requirementsContent, "GUIDANCE", guidance ?? string.Empty);
80+
if (majorVersionRetrievedSuccessfully)
81+
{
82+
guidance = Environment.NewLine + " # To use the Az module in your function app, please uncomment the line below.";
83+
}
84+
85+
requirementsContent = Regex.Replace(requirementsContent, "GUIDANCE", guidance);
7986
File.WriteAllText(requirementsFilePath, requirementsContent);
8087

8188
_logger.LogDebug($"{RequirementsPsd1FileName} created sucessfully.");

test/WebJobs.Script.Tests/FileProvisioning/TestPowerShellFileProvisioner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected override string GetLatestAzModuleMajorVersion()
2020
throw new Exception($@"Failed to get module version for 'Az'.");
2121
}
2222

23-
return "2";
23+
return "5";
2424
}
2525
}
2626
}

test/WebJobs.Script.Tests/Resources/FileProvisioning/PowerShell/requirements_PSGalleryOffline.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# See https://aka.ms/functionsmanageddependency for additional information.
33
#
44
@{
5-
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. Uncomment the next line and replace the MAJOR_VERSION, e.g., 'Az' = '2.*'
5+
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. Uncomment the next line and replace the MAJOR_VERSION, e.g., 'Az' = '5.*'
66
# 'Az' = 'MAJOR_VERSION.*'
77
}

test/WebJobs.Script.Tests/Resources/FileProvisioning/PowerShell/requirements_PSGalleryOnline.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
#
44
@{
55
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
6-
'Az' = '2.*'
6+
# To use the Az module in your function app, please uncomment the line below.
7+
# 'Az' = '5.*'
78
}

0 commit comments

Comments
 (0)