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

Prevent built-in artifacts output functionality from conflicting with Microsoft.Build.Artifacts SDK #33470

Merged
merged 3 commits into from
Jun 21, 2023

Conversation

dsplaisted
Copy link
Member

Fixes #33052

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Infrastructure untriaged Request triage from a team member labels Jun 21, 2023
@dsplaisted dsplaisted requested review from jeffkl and a team June 21, 2023 17:23
Copy link
Member

@joeloff joeloff left a comment

Choose a reason for hiding this comment

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

Looks good. Should we expect to generalize the logic for other SDKs in the future?

@@ -20,7 +20,7 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup>

<!-- Setting ArtifactsPath automatically opts in to the artifacts output format -->
<PropertyGroup Condition="'$(ArtifactsPath)' != ''">
<PropertyGroup Condition="'$(ArtifactsPath)' != '' And '$(UsingMicrosoftArtifactsSdk)' != 'true'">
Copy link
Contributor

Choose a reason for hiding this comment

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

When a user references Microsoft.Build.Artifacts as a package, its .props is imported by .nuget.g.props which is imported after this. So I don't think UsingMicrosoftArtifactsSdk will be set yet since this is imported immediately after Directory.Build.props.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is only imported early on if UseArtifactsOutput or ArtifactsPath are set in Directory.Build.props:

<Import Project="$(MSBuildThisFileDirectory)..\targets\Microsoft.NET.DefaultArtifactsPath.props"
Condition="'$(UseArtifactsOutput)' == 'true' Or '$(ArtifactsPath)' != ''"/>

If they are set later on (ie in the project file), then this file will be imported later, during the .targets evaluation: https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.DefaultOutputPaths.targets#L42-L43

So if the Microsoft.Build.Artifacts NuGet package is being used and ArtifactsPath is set in Directory.Build.props, then the built-in SDK artifacts functionality will be used. If ArtifactsPath is set in the project file (as seems to be suggested in the Microsoft.Build.Artifacts documentation), then the Microsoft.Build.Artifacts logic will be used.

Does this sound OK? Do you know if anyone using Microsoft.Build.Artifacts is setting ArtifactsPath in Directory.Build.props? IE, something like:

<Project>
  <PropertyGroup>
    <BaseArtifactsPath>$(MSBuildThisFileDirectory)artifacts</BaseArtifactsPath>
    <ArtifactsPath>$(BaseArtifactsPath)\$(MSBuildProjectName)</ArtifactsPath>
  </PropertyGroup>
</Project>

Copy link
Member Author

Choose a reason for hiding this comment

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

@jeffkl I went ahead and merged this because we wanted to get the fix in before the .NET 8 Preview 6 branch, Let me know what you think about this and we can follow up with another change if need be.

@jeffkl
Copy link
Contributor

jeffkl commented Jun 21, 2023

I've also created a pull request to disable Microsoft.Build.Artifacts if the .NET SDK's built-in functionality is enabled: microsoft/MSBuildSdks#458

@dsplaisted
Copy link
Member Author

Looks good. Should we expect to generalize the logic for other SDKs in the future?

No, this is because we added a specific property that was already in use by this specific SDK.

@dsplaisted dsplaisted merged commit bc7c5a3 into dotnet:main Jun 21, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Infrastructure untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MSBuild property ArtifactsPath is overloaded; used by both .Net 8 and Microsoft.Build.Artifacts
3 participants