Skip to content

Conversation

@Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented May 21, 2025

Fixes #49063

Copilot AI review requested due to automatic review settings May 21, 2025 12:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adjusts test project conditions so that projects using the Microsoft Testing Platform (MTP) are no longer treated as standard test projects. The changes introduce a new property (_IsVSTestOnlyTestProject) and update existing conditions in the targets file to use this property.

  • Introduces _IsVSTestOnlyTestProject to differentiate test projects from MTP projects.
  • Updates condition checks for IsRidAgnostic, ValidateExecutableReferencesMatchSelfContained, and ShouldBeValidatedAsExecutableReference.

<_DefaultUserProfileRuntimeStorePath Condition="$([MSBuild]::IsOSPlatform(`Windows`))">$(USERPROFILE)</_DefaultUserProfileRuntimeStorePath>
<_DefaultUserProfileRuntimeStorePath>$([System.IO.Path]::Combine($(_DefaultUserProfileRuntimeStorePath), '.dotnet', 'store'))</_DefaultUserProfileRuntimeStorePath>
<UserProfileRuntimeStorePath Condition="'$(UserProfileRuntimeStorePath)' == ''">$(_DefaultUserProfileRuntimeStorePath)</UserProfileRuntimeStorePath>
<_IsVSTestOnlyTestProject Condition="'$(IsTestProject)' == 'true' AND '$(IsTestingPlatformApplication)' != 'true'">true</_IsVSTestOnlyTestProject>
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding an inline comment explaining the purpose of the new _IsVSTestOnlyTestProject property, clarifying that it excludes MTP projects from test-specific conditions.

Copilot uses AI. Check for mistakes.
property values from referencing projects. -->
<PropertyGroup Condition="'$(IsRidAgnostic)' == ''">
<IsRidAgnostic Condition="('$(_IsExecutable)' == 'true' And '$(IsTestProject)' != 'true') Or
<IsRidAgnostic Condition="('$(_IsExecutable)' == 'true' And '$(_IsVSTestOnlyTestProject)' != 'true') Or
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

[nitpick] Review and update any nearby inline comments to ensure they accurately reflect the change from IsTestProject to _IsVSTestOnlyTestProject for non-MTP test projects.

Copilot uses AI. Check for mistakes.
@Youssef1313
Copy link
Member Author

@dsplaisted Can I have an eye on this PR please? Thanks!

@Youssef1313 Youssef1313 requested a review from dsplaisted May 26, 2025 17:34
Copy link
Member

@dsplaisted dsplaisted 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, though if we can define _IsVSTestOnlyTestProject only once I think that would be better.

Have you tested this? Do you think we should add automated tests? There are some existing tests for Reference Exe scenarios here: https://github.com/dotnet/sdk/blob/main/test/Microsoft.NET.Build.Tests/ReferenceExeTests.cs

<_DefaultUserProfileRuntimeStorePath>$([System.IO.Path]::Combine($(_DefaultUserProfileRuntimeStorePath), '.dotnet', 'store'))</_DefaultUserProfileRuntimeStorePath>
<UserProfileRuntimeStorePath Condition="'$(UserProfileRuntimeStorePath)' == ''">$(_DefaultUserProfileRuntimeStorePath)</UserProfileRuntimeStorePath>
<!-- This excludes MTP projects, as they are normal console apps -->
<_IsVSTestOnlyTestProject Condition="'$(IsTestProject)' == 'true' AND '$(IsTestingPlatformApplication)' != 'true'">true</_IsVSTestOnlyTestProject>
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this property is defined multiple times. Can you find a single place to define it? You may need to dig into the evaluation order to figure out the right place to do this.

@Youssef1313
Copy link
Member Author

Youssef1313 commented Jun 2, 2025

@dsplaisted Would adding the property here be good?

Or probably here can be good as well

@dsplaisted
Copy link
Member

@Youssef1313 Looking at the ordering, I think you can leave it where you have it in Microsoft.NET.RuntimeIdentifierInference.targets, and remove it from Microsoft.NET.Sdk.targets, and that should work.

@nagilson
Copy link
Member

nagilson commented Jul 1, 2025

@Youssef1313 Will you have time to respond to @dsplaisted's feedback?

Finally, library projects and non-executable projects have awkward interactions here so they are excluded.-->
<PropertyGroup Condition="'$(UseCurrentRuntimeIdentifier)' == ''">
<!-- This excludes MTP projects, as they are normal console apps -->
<_IsVSTestOnlyTestProject Condition="'$(IsTestProject)' == 'true' AND '$(IsTestingPlatformApplication)' != 'true'">true</_IsVSTestOnlyTestProject>
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: Ensure that this is even late enough to read IsTestingPlatformApplication. It's not invalid to set it in Directory.Build.targets. So, if this is imported before, it may not work as expected.

@Youssef1313
Copy link
Member Author

@Youssef1313 Will you have time to respond to @dsplaisted's feedback?

Not yet unfortunately, and this might end up being more involved than what I initially thought.

@Youssef1313
Copy link
Member Author

@dsplaisted @nagilson We might not be able to read IsTestingPlatformApplication reliably during evaluation (unless it's part of an item condition as items are evaluated after properties).

What I have in mind is:

  • For both ShouldBeValidatedAsExecutableReference and ValidateExecutableReferencesMatchSelfContained, we don't set them during evaluation altogether, and defer their calculation inside ValidateExecutableReferences target (or a new target that ValidateExecutableReferences hooks into.
  • IsRidAgnostic and UseCurrentRuntimeIdentifier look like they will be more involved. I don't immediately have good ideas for how to handle that.

@Youssef1313 Youssef1313 marked this pull request as draft July 16, 2025 16:23
@Youssef1313
Copy link
Member Author

Replacing with #49838

@Youssef1313 Youssef1313 deleted the dev/ygerges/istestproject branch July 17, 2025 05:57
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.

Validate historical hacks for test projects that may be harmful for MTP projects

4 participants