Skip to content

Commit c67cebb

Browse files
kshyjusoninaren
andauthored
.NET8 in-proc support (#3680)
* .NET8 Inproc support for host start action. (#3670) * Zip generation updates for Inproc8 * Handling net8 artifact generation for min versions of artifacts (used in VS feed) * Optimizing TestPreSignedArtifacts method. * Zipping _net8.0 artifacts and other cleanups * Publish --self-contained (#3673) * updating template reference for core tools (#3675) * Moved log messages behind "Verbose" logging enabled check. Minor refactoring * Adding a test for .NET8 inproc * Update Microsoft.Azure.WebJobs.Script.WebHost to 4.834.2 * Minor cleanup * Publishing net8 bits as self-contained. Reordering of some code snippets to fix failing test. * Updating tests to reflect recent text changes. * Generating "_net8.0.zip" for all artifacts (previously only for ".min" ones) * Reordered supported target framework list as per PR feedback. Added a new test for unsupported use case. * Changes based on PR feedback * Fixed a test to reflect revised exception message change * Adding `--no-build` in "DotnetPack" step * Revert "Adding `--no-build` in "DotnetPack" step" This reverts commit bb9191a. * Added back `--no-build` flag for pack. Pack only when targetFramework == net6.0 --------- Co-authored-by: Naren Soni <[email protected]>
1 parent d6407dd commit c67cebb

15 files changed

+461
-65
lines changed

Diff for: build/BuildSteps.cs

+91-32
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public static void DotnetPack()
101101
Shell.Run("dotnet", $"pack {Settings.SrcProjectPath} " +
102102
$"/p:BuildNumber=\"{Settings.BuildNumber}\" " +
103103
$"/p:NoWorkers=\"true\" " +
104+
$"/p:TargetFramework=net6.0 " + // without TargetFramework, the generated nuspec has incorrect path for the copy files operation.
104105
$"/p:CommitHash=\"{Settings.CommitId}\" " +
105106
(string.IsNullOrEmpty(Settings.IntegrationBuildNumber) ? string.Empty : $"/p:IntegrationBuildNumber=\"{Settings.IntegrationBuildNumber}\" ") +
106107
$"-o {outputPath} -c Release --no-build");
@@ -110,19 +111,21 @@ public static void DotnetPublishForZips()
110111
{
111112
foreach (var runtime in Settings.TargetRuntimes)
112113
{
114+
var isMinVersion = runtime.StartsWith(Settings.MinifiedVersionPrefix);
113115
var outputPath = Path.Combine(Settings.OutputDir, runtime);
114116
var rid = GetRuntimeId(runtime);
115-
Shell.Run("dotnet", $"publish {Settings.ProjectFile} " +
116-
$"/p:BuildNumber=\"{Settings.BuildNumber}\" " +
117-
$"/p:CommitHash=\"{Settings.CommitId}\" " +
118-
(string.IsNullOrEmpty(Settings.IntegrationBuildNumber) ? string.Empty : $"/p:IntegrationBuildNumber=\"{Settings.IntegrationBuildNumber}\" ") +
119-
$"-o {outputPath} -c Release " +
120-
(string.IsNullOrEmpty(rid) ? string.Empty : $" -r {rid}"));
121-
122-
if (runtime.StartsWith(Settings.MinifiedVersionPrefix))
117+
118+
ExecuteDotnetPublish(outputPath, rid, "net6.0", skipLaunchingNet8ChildProcess: isMinVersion);
119+
120+
if (isMinVersion)
123121
{
124122
RemoveLanguageWorkers(outputPath);
125123
}
124+
125+
// Publish net8 version of the artifact as well.
126+
var outputPathNet8 = BuildNet8ArtifactFullPath(runtime);
127+
ExecuteDotnetPublish(outputPathNet8, rid, "net8.0", skipLaunchingNet8ChildProcess: true);
128+
RemoveLanguageWorkers(outputPathNet8);
126129
}
127130

128131
if (!string.IsNullOrEmpty(Settings.IntegrationBuildNumber) && (_integrationManifest != null))
@@ -131,6 +134,24 @@ public static void DotnetPublishForZips()
131134
}
132135
}
133136

137+
private static string BuildNet8ArtifactFullPath(string runtime)
138+
{
139+
return Path.Combine(Settings.OutputDir, BuildNet8ArtifactDirectory(runtime));
140+
}
141+
142+
private static string BuildNet8ArtifactDirectory(string runtime) => runtime + "_net8.0";
143+
144+
private static void ExecuteDotnetPublish(string outputPath, string rid, string targetFramework, bool skipLaunchingNet8ChildProcess)
145+
{
146+
Shell.Run("dotnet", $"publish {Settings.ProjectFile} " +
147+
$"/p:BuildNumber=\"{Settings.BuildNumber}\" " +
148+
$"/p:SkipInProcessHost=\"{skipLaunchingNet8ChildProcess}\" " +
149+
$"/p:CommitHash=\"{Settings.CommitId}\" " +
150+
(string.IsNullOrEmpty(Settings.IntegrationBuildNumber) ? string.Empty : $"/p:IntegrationBuildNumber=\"{Settings.IntegrationBuildNumber}\" ") +
151+
$"-o {outputPath} -c Release -f {targetFramework} --self-contained" +
152+
(string.IsNullOrEmpty(rid) ? string.Empty : $" -r {rid}"));
153+
}
154+
134155
public static void FilterPowershellRuntimes()
135156
{
136157
var minifiedRuntimes = Settings.TargetRuntimes.Where(r => r.StartsWith(Settings.MinifiedVersionPrefix));
@@ -153,7 +174,7 @@ public static void FilterPowershellRuntimes()
153174
$"{Environment.NewLine}Found runtimes are {string.Join(", ", allFoundPowershellRuntimes)}");
154175
}
155176

156-
// Delete all the runtimes that should not belong to the current runtime
177+
// Delete all the runtimes that should not belong to the current artifactDirectory
157178
allFoundPowershellRuntimes.Except(powershellRuntimesForCurrentToolsRuntime).ToList().ForEach(r => Directory.Delete(Path.Combine(powershellRuntimePath, r), recursive: true));
158179
}
159180
}
@@ -177,6 +198,8 @@ public static void FilterPowershellRuntimes()
177198
}
178199
}
179200
}
201+
202+
// No action needed for the "_net8.0" versions of these artifacts as they have an empty "workers" directory.
180203
}
181204

182205
public static void FilterPythonRuntimes()
@@ -205,11 +228,13 @@ public static void FilterPythonRuntimes()
205228

206229
if (!atLeastOne)
207230
{
208-
throw new Exception($"No Python worker matched the OS '{Settings.RuntimesToOS[runtime]}' for runtime '{runtime}'. " +
231+
throw new Exception($"No Python worker matched the OS '{Settings.RuntimesToOS[runtime]}' for artifactDirectory '{runtime}'. " +
209232
$"Something went wrong.");
210233
}
211234
}
212235
}
236+
237+
// No action needed for the "_net8.0" versions of these artifacts as they have an empty "workers" directory.
213238
}
214239

215240
public static void AddDistLib()
@@ -232,6 +257,8 @@ public static void AddDistLib()
232257

233258
File.Delete(distLibZip);
234259
Directory.Delete(distLibDir, recursive: true);
260+
261+
// No action needed for the "_net8.0" versions of these artifacts as we don't ship workers for them.
235262
}
236263

237264
public static void AddTemplatesNupkgs()
@@ -314,7 +341,7 @@ public static void Test()
314341

315342
Environment.SetEnvironmentVariable("DURABLE_FUNCTION_PATH", Settings.DurableFolder);
316343

317-
Shell.Run("dotnet", $"test {Settings.TestProjectFile} --logger trx");
344+
Shell.Run("dotnet", $"test {Settings.TestProjectFile} -f net6.0 --logger trx");
318345
}
319346

320347
public static void CopyBinariesToSign()
@@ -371,7 +398,7 @@ public static void CopyBinariesToSign()
371398

372399
// These assemblies are currently signed, but with an invalid root cert.
373400
// Until that is resolved, we are explicity signing the AppService.Middleware packages
374-
401+
375402
unSignedBinaries = unSignedBinaries.Concat(allFiles
376403
.Where(f => f.Contains("Microsoft.Azure.AppService.Middleware") || f.Contains("Microsoft.Azure.AppService.Proxy"))).ToList();
377404

@@ -384,6 +411,8 @@ public static void CopyBinariesToSign()
384411

385412
public static void TestPreSignedArtifacts()
386413
{
414+
var filterExtensionsSignSet = new HashSet<string>(Settings.SignInfo.FilterExtensionsSign);
415+
387416
foreach (var supportedRuntime in Settings.SignInfo.RuntimesToSign)
388417
{
389418
if (supportedRuntime.StartsWith("osx"))
@@ -397,20 +426,30 @@ public static void TestPreSignedArtifacts()
397426
Directory.CreateDirectory(targetDir);
398427
FileHelpers.RecursiveCopy(sourceDir, targetDir);
399428

400-
var toSignPaths = Settings.SignInfo.authentiCodeBinaries.Select(el => Path.Combine(targetDir, el));
401-
var toSignThirdPartyPaths = Settings.SignInfo.thirdPartyBinaries.Select(el => Path.Combine(targetDir, el));
429+
var inProc8Directory = Path.Combine(targetDir, "in-proc8");
430+
var inProc8DirectoryExists = Directory.Exists(inProc8Directory);
431+
432+
var toSignPathsForInProc8 = inProc8DirectoryExists
433+
? Settings.SignInfo.authentiCodeBinaries.Select(el => Path.Combine(inProc8Directory, el))
434+
: Enumerable.Empty<string>();
435+
var toSignPaths = Settings.SignInfo.authentiCodeBinaries.Select(el => Path.Combine(targetDir, el)).Concat(toSignPathsForInProc8);
436+
437+
var toSignThirdPartyPathsForInProc8 = inProc8DirectoryExists
438+
? Settings.SignInfo.thirdPartyBinaries.Select(el => Path.Combine(inProc8Directory, el))
439+
: Enumerable.Empty<string>();
440+
var toSignThirdPartyPaths = Settings.SignInfo.thirdPartyBinaries.Select(el => Path.Combine(targetDir, el)).Concat(toSignThirdPartyPathsForInProc8);
441+
402442
var unSignedFiles = FileHelpers.GetAllFilesFromFilesAndDirs(FileHelpers.ExpandFileWildCardEntries(toSignPaths))
403-
.Where(file => !Settings.SignInfo.FilterExtensionsSign.Any(ext => file.EndsWith(ext))).ToList();
443+
.Where(file => !filterExtensionsSignSet.Any(ext => file.EndsWith(ext))).ToList();
404444

405445
unSignedFiles.AddRange(FileHelpers.GetAllFilesFromFilesAndDirs(FileHelpers.ExpandFileWildCardEntries(toSignThirdPartyPaths))
406-
.Where(file => !Settings.SignInfo.FilterExtensionsSign.Any(ext => file.EndsWith(ext))));
446+
.Where(file => !filterExtensionsSignSet.Any(ext => file.EndsWith(ext))));
407447

408448
unSignedFiles.ForEach(filePath => File.Delete(filePath));
409449

410450
var unSignedPackages = GetUnsignedBinaries(targetDir);
411451
if (unSignedPackages.Count() != 0)
412452
{
413-
414453
var missingSignature = string.Join($",{Environment.NewLine}", unSignedPackages);
415454
ColoredConsole.Error.WriteLine($"This files are missing valid signatures: {Environment.NewLine}{missingSignature}");
416455
throw new Exception($"sigcheck.exe test failed. Following files are unsigned: {Environment.NewLine}{missingSignature}");
@@ -498,31 +537,47 @@ public static List<string> GetUnsignedBinaries(string targetDir)
498537
return unSignedPackages;
499538
}
500539

540+
private static void CreateZipFromArtifact(string artifactSourcePath, string zipPath)
541+
{
542+
if (!Directory.Exists(artifactSourcePath))
543+
{
544+
throw new Exception($"Artifact source path {artifactSourcePath} does not exist.");
545+
}
546+
547+
ColoredConsole.WriteLine($"Creating {zipPath}");
548+
ZipFile.CreateFromDirectory(artifactSourcePath, zipPath, CompressionLevel.Optimal, includeBaseDirectory: false);
549+
}
550+
501551
public static void Zip()
502552
{
503553
var version = CurrentVersion;
504554

505555
foreach (var runtime in Settings.TargetRuntimes)
506556
{
507-
var path = Path.Combine(Settings.OutputDir, runtime);
557+
var isMinVersion = runtime.StartsWith(Settings.MinifiedVersionPrefix);
558+
var artifactPath = Path.Combine(Settings.OutputDir, runtime);
508559

509560
var zipPath = Path.Combine(Settings.OutputDir, $"Azure.Functions.Cli.{runtime}.{version}.zip");
510-
ColoredConsole.WriteLine($"Creating {zipPath}");
511-
ZipFile.CreateFromDirectory(path, zipPath, CompressionLevel.Optimal, includeBaseDirectory: false);
561+
CreateZipFromArtifact(artifactPath, zipPath);
562+
563+
// Zip the .net8 version as well.
564+
var net8Path = BuildNet8ArtifactFullPath(runtime);
565+
var net8ZipPath = zipPath.Replace(".zip", "_net8.0.zip");
566+
CreateZipFromArtifact(net8Path, net8ZipPath);
567+
512568

513569
// We leave the folders beginning with 'win' to generate the .msi files. They will be deleted in
514570
// the ./generateMsiFiles.ps1 script
515571
if (!runtime.StartsWith("win"))
516572
{
517573
try
518574
{
519-
Directory.Delete(path, recursive: true);
575+
Directory.Delete(artifactPath, recursive: true);
520576
}
521-
catch
577+
catch (Exception ex)
522578
{
523-
ColoredConsole.Error.WriteLine($"Error deleting {path}");
579+
ColoredConsole.Error.WriteLine($"Error deleting {artifactPath}. Exception: {ex}");
524580
}
525-
526581
}
527582

528583
ColoredConsole.WriteLine();
@@ -549,12 +604,15 @@ private static string CurrentVersion
549604
public static void GenerateSBOMManifestForZips()
550605
{
551606
Directory.CreateDirectory(Settings.SBOMManifestTelemetryDir);
552-
// Generate the SBOM manifest for each runtime
553-
foreach (var runtime in Settings.TargetRuntimes)
607+
// Generate the SBOM manifest for each artifactDirectory
608+
609+
var allArtifactDirectories = Settings.TargetRuntimes.Concat(Settings.TargetRuntimes.Select(r => BuildNet8ArtifactDirectory(r)));
610+
611+
foreach (var artifactDirectory in allArtifactDirectories)
554612
{
555-
var packageName = $"Azure.Functions.Cli.{runtime}.{CurrentVersion}";
556-
var buildPath = Path.Combine(Settings.OutputDir, runtime);
557-
var manifestFolderPath = Path.Combine(buildPath, "_manifest");
613+
var packageName = $"Azure.Functions.Cli.{artifactDirectory}.{CurrentVersion}";
614+
var artifactDirectoryFullPath = Path.Combine(Settings.OutputDir, artifactDirectory);
615+
var manifestFolderPath = Path.Combine(artifactDirectoryFullPath, "_manifest");
558616
var telemetryFilePath = Path.Combine(Settings.SBOMManifestTelemetryDir, Guid.NewGuid().ToString() + ".json");
559617

560618
// Delete the manifest folder if it exists
@@ -565,8 +623,8 @@ public static void GenerateSBOMManifestForZips()
565623

566624
// Generate the SBOM manifest
567625
Shell.Run("dotnet",
568-
$"{Settings.SBOMManifestToolPath} generate -PackageName {packageName} -BuildDropPath {buildPath}"
569-
+ $" -BuildComponentPath {buildPath} -Verbosity Information -t {telemetryFilePath}");
626+
$"{Settings.SBOMManifestToolPath} generate -PackageName {packageName} -BuildDropPath {artifactDirectoryFullPath}"
627+
+ $" -BuildComponentPath {artifactDirectoryFullPath} -Verbosity Information -t {telemetryFilePath}");
570628
}
571629
}
572630

@@ -576,9 +634,10 @@ public static void DotnetPublishForNupkg()
576634
Shell.Run("dotnet", $"publish {Settings.ProjectFile} " +
577635
$"/p:BuildNumber=\"{Settings.BuildNumber}\" " +
578636
$"/p:NoWorkers=\"true\" " +
637+
$"/p:TargetFramework=net6.0 " +
579638
$"/p:CommitHash=\"{Settings.CommitId}\" " +
580639
(string.IsNullOrEmpty(Settings.IntegrationBuildNumber) ? string.Empty : $"/p:IntegrationBuildNumber=\"{Settings.IntegrationBuildNumber}\" ") +
581-
$"-c Release");
640+
$"-c Release -f net6.0");
582641
}
583642

584643
public static void GenerateSBOMManifestForNupkg()

Diff for: build/Shell.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static void Run(string program, string arguments, bool streamOutput = tru
2525

2626
if (exitcode != 0)
2727
{
28-
throw new Exception($"{program} Exit Code == {exitcode}");
28+
throw new Exception($"{program} {arguments} Exit Code == {exitcode}");
2929
}
3030
}
3131

Diff for: pipelineUtilities.psm1

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ $DotnetSDKVersionRequirements = @{
6767
MinimalPatch = '417'
6868
DefaultPatch = '417'
6969
}
70+
71+
'8.0' = @{
72+
MinimalPatch = '204'
73+
DefaultPatch = '204'
74+
}
7075
}
7176

7277
function AddLocalDotnetDirPath {

0 commit comments

Comments
 (0)