Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 9, 2025

When ArtifactsPath is set to a location outside the repository root, generated files in intermediate output directories (e.g., Project.Version.cs) are not properly mapped in PDBs, breaking build reproducibility.

Changes

  • Microsoft.NET.DefaultOutputPaths.targets: Add ArtifactsPath to SourceRoot items when defined, handling both trailing and non-trailing slash variants
  • ArtifactsOutputPathTests.cs: Add test verifying artifacts path outside repo root produces correct output location

Context

Source mapping requires all source file locations to be declared in SourceRoot items. When artifacts live outside the repo, the intermediate output path becomes unmapped, causing full paths to leak into PDBs instead of deterministic mapped paths (_1/, _2/, etc.).

<!-- Added to Microsoft.NET.DefaultOutputPaths.targets -->
<ItemGroup Condition="'$(ArtifactsPath)' != ''">
  <SourceRoot Condition="!HasTrailingSlash('$(ArtifactsPath)')" Include="$(ArtifactsPath)\" />
  <SourceRoot Condition="HasTrailingSlash('$(ArtifactsPath)')" Include="$(ArtifactsPath)" />
</ItemGroup>
Original prompt

This section details on the original issue you should resolve

<issue_title>Custom ArtifactsPath outside repo does not add SourceRoot, making build not reproducible</issue_title>
<issue_description><!--
Please keep in mind that the GitHub issue tracker is not intended as a general support forum, but for reporting non-security bugs and feature requests.

If you believe you have an issue that affects the SECURITY of the platform, please do NOT create an issue and instead email your issue details to [email protected]. Your report may be eligible for our bug bounty but ONLY if it is reported through email.
For other types of questions, consider using StackOverflow.

-->

Describe the bug

When setting ArtifactsPath to a location outside a repo root, generated files in the obj dir (e.g. Project.Version.cs) are not escaped properly and have the full path in the pdb instead of _1/, _2, etc.

To Reproduce

In an AzDo pipeline, create a package with dotnet pack -p:ArtifactsPath=$(Build.ArtifactStagingDirectory) and examine the result in NuGet Package Explorer. In AzDo, the Build.ArtifactStagingDirectory location lives outside of the source location.

Exceptions (if any)

Further technical details

Tested with .NET SDK 10 RC2

Workaround

Adding this into the Directory.Build.targets solves it:

<SourceRoot Condition="'$(ArtifactsPath)' != '' and !HasTrailingSlash('$(ArtifactsPath)')" Include="$(ArtifactsPath)\" />
<SourceRoot Condition="'$(ArtifactsPath)' != '' and HasTrailingSlash('$(ArtifactsPath)')" Include="$(ArtifactsPath)" />
```</issue_description>

<agent_instructions>When we set ArtifactsPath, let's add it to SourceRoot. Can you add a test as well?</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix custom ArtifactsPath not adding SourceRoot for reproducibility Add ArtifactsPath to SourceRoot for deterministic builds outside repo Dec 9, 2025
Copilot AI requested a review from marcpopMSFT December 9, 2025 22:01
@marcpopMSFT marcpopMSFT requested a review from tmat December 13, 2025 00:07
@marcpopMSFT marcpopMSFT force-pushed the copilot/fix-artifact-path-issue branch from 40eff34 to 017fe4c Compare December 13, 2025 00:07
@marcpopMSFT
Copy link
Member

@tmat I believe you know source link well so may know if this is the right solution here. I just had copilot follow what the original issue stated but wanted someone to confirm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom ArtifactsPath outside repo does not add SourceRoot, making build not reproducible

2 participants