Skip to content

[11.0.1xx] File-based apps: improve legacy artifact support - #56248

Closed
jjonescz wants to merge 1 commit into
dotnet:release/11.0.1xxfrom
jjonescz:sprint-reuse-artifacts-net10-2-11.0.1xx
Closed

[11.0.1xx] File-based apps: improve legacy artifact support#56248
jjonescz wants to merge 1 commit into
dotnet:release/11.0.1xxfrom
jjonescz:sprint-reuse-artifacts-net10-2-11.0.1xx

Conversation

@jjonescz

Copy link
Copy Markdown
Member

Backport of #56160.

@jjonescz jjonescz added the backport PR that has been backported to a servicing branch label Sep 11, 2026
@jjonescz
jjonescz requested review from a team as code owners September 11, 2026 09:10
Copilot AI lite review requested due to automatic review settings September 11, 2026 09:10
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical compilation and legacy-fallback issues remain unresolved.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Backports file-based app artifact compatibility for older SDK hosts.

Changes:

  • Adds an SDK capability marker.
  • Implements legacy artifact-path fallback logic.
  • Adds compatibility regression tests.
File summaries
File Summary and review findings
test/dotnet.Tests/CommandTests/Run/RunFileTests_CscOnlyAndApi.cs Adds compatibility tests. Critical (1 vote): missing System.Security import for SecurityElement.
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.DefaultArtifactsPath.props Adds the artifact support marker. Nit (1 vote): tests override the marker instead of verifying its assignment.
src/Cli/Microsoft.DotNet.FileBasedPrograms/VirtualProjectBuilder.cs Adds artifact support detection and fallback. Critical (3 votes): _useLegacyArtifactsPath is undeclared. Critical (3 votes): fallback reuses cached modern project text instead of generating legacy properties.
Review details

Suppressed comments (1)

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.DefaultArtifactsPath.props:20

  • Both cases in the new test force _SupportsFileBasedAppArtifactsPath through additionalGlobalProperties; because global properties override project properties, the test never exercises this new assignment. Removing this line would still leave that test green while the current SDK is classified as legacy in real use. Add a case that evaluates without overriding the marker and verifies support is detected.
    <_SupportsFileBasedAppArtifactsPath>true</_SupportsFileBasedAppArtifactsPath>
  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Lite

Comment on lines +505 to +509
if (_useLegacyArtifactsPath is null)
{
var supportsFileBasedAppArtifactsPath = await project.GetPropertyValueAsync("_SupportsFileBasedAppArtifactsPath").ConfigureAwait(false);

_useLegacyArtifactsPath = !string.Equals(supportsFileBasedAppArtifactsPath, bool.TrueString, StringComparison.OrdinalIgnoreCase);
Comment on lines +511 to +513
if (_useLegacyArtifactsPath == true)
{
return await CreateProjectInstanceNoEvaluation(projectCollection, directives, additionalGlobalProperties).ConfigureAwait(false);
{
xml.Should()
.Contain("<IncludeProjectNameInArtifactsPaths>false</IncludeProjectNameInArtifactsPaths>")
.And.Contain($"<ArtifactsPath>{SecurityElement.Escape(artifactsPath)}</ArtifactsPath>")
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Build Failure Analysis

Summary — The build fails to compile across every leg (Linux/macOS/Windows, AOT and non-AOT) with CS0103: The name '_useLegacyArtifactsPath' does not exist in the current context in VirtualProjectBuilder.cs, because this backport PR added the code that uses the field _useLegacyArtifactsPath without adding the field itself (or the rest of the change that consumes it).

Root cause: incomplete backport of #56160 — missing _useLegacyArtifactsPath field and its consumer changes

This PR ([11.0.1xx] File-based apps: improve legacy artifact support) is a manual backport of #56160. The upstream PR made changes in three places of VirtualProjectBuilder.cs:

  1. Field declarationprivate bool? _useLegacyArtifactsPath; (class-level field).
  2. Passing the field's value to WriteProjectFileuseLegacyArtifactsPath: _useLegacyArtifactsPath == true, inside the CreateProjectInstanceNoEvaluation local function's call to WriteProjectFile.
  3. The hunk that sets the field (only this one made it into this PR) — the if (_useLegacyArtifactsPath is null) { ... } block that reads the new _SupportsFileBasedAppArtifactsPath MSBuild property and recurses.
  4. WriteProjectFile's signature and body — adding the bool useLegacyArtifactsPath = false parameter and branching between the legacy (IncludeProjectNameInArtifactsPaths/ArtifactsPath/PublishDir/PackageOutputPath) and new (FileBasedAppArtifactsPath) property emission.

Only item 3 is present in this PR's diff (src/Cli/Microsoft.DotNet.FileBasedPrograms/VirtualProjectBuilder.cs lines 503–518) along with the companion change to Microsoft.NET.DefaultArtifactsPath.props (adding _SupportsFileBasedAppArtifactsPath) and the new test. Items 1, 2, and 4 were never carried over, so _useLegacyArtifactsPath is referenced but never declared — a plain compile error, reproduced identically in all 10 build legs (binlog_errors reports the same three CS0103 errors at lines 505/509/511 in every leg that has full error reporting, e.g. Windows x64 and Linux arm64).

Affected files / errors

Proposed fix

Bring over the remaining hunks from #56160 that this backport dropped. None of the missing lines are within this PR's current diff (they live elsewhere in the same file, untouched by this PR), so they can't be expressed as single-line GitHub suggestions — apply them as additional edits to VirtualProjectBuilder.cs:

     private (ImmutableArray<CSharpDirective> Original, ImmutableArray<CSharpDirective> Evaluated)? _evaluatedDirectives;
 
+    private bool? _useLegacyArtifactsPath;
+
     internal string EntryPointFileFullPath { get; }
                 entryPointFilePath: EntryPointFileFullPath,
                 artifactsPath: ArtifactsPath,
+                useLegacyArtifactsPath: _useLegacyArtifactsPath == true,
                 includeRuntimeConfigInformation: RequestedTargets?.Any(static t => t is "Publish" or "Pack") != true);
         string? entryPointFilePath = null,
         string? artifactsPath = null,
+        bool useLegacyArtifactsPath = false,
         bool includeRuntimeConfigInformation = true,
             writer.WriteLine($"""
                 <Project>
 
                   <PropertyGroup>
-                    <FileBasedAppArtifactsPath>{EscapeValue(artifactsPath)}</FileBasedAppArtifactsPath>
+                """);
+
+            if (useLegacyArtifactsPath)
+            {
+                writer.WriteLine($"""
+                        <IncludeProjectNameInArtifactsPaths>false</IncludeProjectNameInArtifactsPaths>
+                        <ArtifactsPath>{EscapeValue(artifactsPath)}</ArtifactsPath>
+                        <PublishDir>artifacts/$(AssemblyName)</PublishDir>
+                        <PackageOutputPath>artifacts/$(AssemblyName)</PackageOutputPath>
+                    """);
+            }
+            else
+            {
+                writer.WriteLine($"""
+                        <FileBasedAppArtifactsPath>{EscapeValue(artifactsPath)}</FileBasedAppArtifactsPath>
+                    """);
+            }
+
+            writer.WriteLine($"""
                     <AssemblyName>{EscapeValue(Path.GetFileNameWithoutExtension(entryPointFilePath))}</AssemblyName>

Reference: the full, correct set of hunks for this file is visible in the merged upstream PR at dotnet/sdk#56160's diff for VirtualProjectBuilder.cs.


Build overview
  • Failing across all 10 build legs (Windows x64/arm64, Linux x64/arm64, macOS arm64 — both AOT and non-AOT — plus the Windows FullFramework leg).
  • Same 3 CS0103 errors reproduced verbatim in every leg that reports full errors (e.g. 10_0_Windows_x64_Logs, 1_0_Linux_arm64_AOT_Logs, 2_0_Linux_arm64_Logs), each hitting two projects that compile VirtualProjectBuilder.cs: Microsoft.DotNet.ProjectTools.csproj and Microsoft.DotNet.FileBasedPrograms.Package.csproj.
  • Target: CoreCompile (task Csc). Exit: build failed ("Build failed.").
All MSBuild errors (3 unique, repeated per compiling project)
Code Project File:Line Message
CS0103 Microsoft.DotNet.ProjectTools / Microsoft.DotNet.FileBasedPrograms.Package VirtualProjectBuilder.cs:505 The name _useLegacyArtifactsPath does not exist in the current context
CS0103 Microsoft.DotNet.ProjectTools / Microsoft.DotNet.FileBasedPrograms.Package VirtualProjectBuilder.cs:509 The name _useLegacyArtifactsPath does not exist in the current context
CS0103 Microsoft.DotNet.ProjectTools / Microsoft.DotNet.FileBasedPrograms.Package VirtualProjectBuilder.cs:511 The name _useLegacyArtifactsPath does not exist in the current context

🤖 Generated by the Build Failure Analysis workflow using (a href="(dev.azure.com/redacted) · commit 904a90e

🤖 Automated content by GitHub Copilot. Generated by the Build Failure Analysis workflow. · auto · 167 AIC · ⌖ 2.78 AIC · ⊞ 7.2K · [◷]( · )

@jjonescz jjonescz closed this Sep 11, 2026
@jjonescz
jjonescz deleted the sprint-reuse-artifacts-net10-2-11.0.1xx branch September 11, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport PR that has been backported to a servicing branch Servicing-consider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants