Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating coretools to detect unsupported inproc6 sdk scenario #3825

Merged
merged 18 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions build/BuildSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static void DotnetPublishForZips()
if (isMinVersion)
{
RemoveLanguageWorkers(outputPath);
CreateMinConfigurationFile(outputPath);
}

// Publish net8 version of the artifact as well.
Expand Down Expand Up @@ -792,6 +793,13 @@ private static void RemoveLanguageWorkers(string outputPath)
}
}

private static void CreateMinConfigurationFile(string outputPath)
{
var filePath = Path.Combine(outputPath, "artifactsconfig.json");
string artifactsJsonContent = "{\"minifiedVersion\": true}";
File.WriteAllTextAsync(filePath, artifactsJsonContent).GetAwaiter().GetResult();
}

private static PackageInfo GetLatestPackageInfo(string name, string majorVersion, string source)
{
string includeAllVersion = !string.IsNullOrWhiteSpace(majorVersion) ? "-AllVersions" : string.Empty;
Expand Down
15 changes: 15 additions & 0 deletions src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,14 @@ private async Task<bool> TryHandleInProcDotNetLaunchAsync()

if (!string.Equals(HostRuntime, "default", StringComparison.OrdinalIgnoreCase))
{
if (Utilities.IsMinifiedVersion())
{
ThrowForInProc();
}

var isNet8InProcSpecified = string.Equals(HostRuntime, DotnetConstants.InProc8HostRuntime, StringComparison.OrdinalIgnoreCase);
StartHostAsChildProcess(isNet8InProcSpecified);
surgupta-msft marked this conversation as resolved.
Show resolved Hide resolved

return true;
}

Expand All @@ -488,6 +494,11 @@ private async Task<bool> TryHandleInProcDotNetLaunchAsync()

PrintVerboseForHostSelection(selectedRuntime);

if (Utilities.IsMinifiedVersion())
{
ThrowForInProc();
}

StartHostAsChildProcess(isDotNet8Project);

return true;
Expand Down Expand Up @@ -541,6 +552,10 @@ void ThrowCliException(string suffix)
PrintVerboseForHostSelection(HostRuntime);
}

private void ThrowForInProc()
{
throw new CliException($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}. Please update to the latest version. For more information, see: {DotnetConstants.InProcFunctionsDocsLink}");
}
private void PrintVerboseForHostSelection(string hostRuntime)
{
if (VerboseLogging.GetValueOrDefault())
Expand Down
2 changes: 2 additions & 0 deletions src/Azure.Functions.Cli/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ internal static class Constants
public const string HostJsonFileName = "host.json";
public const string PackageJsonFileName = "package.json";
public const string ProxiesJsonFileName = "proxies.json";
public const string ArtifactsConfigFileName = "artifactsconfig.json";
public const string MinifiedVersionConfigSectionName = "minifiedVersion";
public const string ExtensionsCsProjFile = "extensions.csproj";
public const string DefaultVEnvName = "worker_env";
public const string ExternalPythonPackages = ".python_packages";
Expand Down
4 changes: 4 additions & 0 deletions src/Azure.Functions.Cli/Common/DotnetConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ internal static class DotnetConstants
public const string InProc6HostRuntime = "inproc6";

public static readonly string[] ValidRuntimeValues = [InProc8HostRuntime, InProc6HostRuntime, "default"];

public const string InProcFunctionsSdk = "Microsoft.NET.Sdk.Functions";
public const string InProcFunctionsMinSdkVersion = "4.5.0";
public const string InProcFunctionsDocsLink = "https://aka.ms/functions-core-tools-in-proc-sdk-requirement";
}
}
20 changes: 20 additions & 0 deletions src/Azure.Functions.Cli/Common/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,25 @@ internal static IConfigurationRoot BuildHostJsonConfigutation(ScriptApplicationH
var configuration = builder.Build();
return configuration;
}

internal static bool IsMinifiedVersion()
{
IConfigurationBuilder builder = new ConfigurationBuilder();
builder.AddJsonFile(Constants.ArtifactsConfigFileName, optional: true);
var config = builder.Build();

try
{
var section = config.GetSection(Constants.MinifiedVersionConfigSectionName);

if (section.Exists())
{
string value = section.Value;
return bool.TryParse(value, out bool isValue) && isValue;
}
}
catch { }
return false;
}
}
}
16 changes: 16 additions & 0 deletions test/Azure.Functions.Cli.Tests/UtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.IO;
using Xunit;

namespace Azure.Functions.Cli.Tests
Expand Down Expand Up @@ -60,5 +61,20 @@ public void IsSystemLogCategory_Test(string inputCategory, bool expected)
{
Assert.Equal(expected, Utilities.IsSystemLogCategory(inputCategory));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void Test_IsMinifiedVersion(bool expected)
{
var filePath = Path.Combine("artifactsconfig.json");
string artifactsJsonContent = "{\"minifiedVersion\": " + expected.ToString().ToLower() + "}";
File.WriteAllTextAsync(filePath, artifactsJsonContent).GetAwaiter().GetResult();

bool output = Utilities.IsMinifiedVersion();

File.Delete(filePath);
Assert.Equal(expected, output);
}
}
}