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

Feature Query API #9665

Merged
merged 25 commits into from Feb 6, 2024
Merged

Feature Query API #9665

merged 25 commits into from Feb 6, 2024

Conversation

surayya-MS
Copy link
Member

@surayya-MS surayya-MS commented Jan 19, 2024

Fixes #9653

Context

We need an API that can tell us whether a specific feature is available or not.

Changes Made

Added a new API

namespace Microsoft.Build.Framework
{
    public static class Features
    {
        public static FeatureStatus CheckFeatureAvailability(string featureName) 
        {
        }
    }

    public enum FeatureStatus
    {
        Undefined,
        Available,
        NotAvailable,
        Preview,
    }
}

Usage example:

// Available, NotAvailable or NotFound
var availability = Features.CheckFeatureAvailability("Feauture1");

Command-line support

for switches /featureavailability and /fa.

Similar to /version switch, if featureavailability switch is detected then ignores other switches. /version switch has higher priority than featureavailability.

There is no logo shown when /featureavailability is detected (similar to /getProperty).

PS>msbuild /fa:Feature1
Available

PS>msbuild /featureavailability:Feauture2
Undefined

PS>msbuild /featureavailability:Feauture1,test /fa:Feature2
{
  "Feature1": "Available",
  "test": "Undefined",
  "Feature2": "NotAvailable"
}

PS>msbuild /fa:
MSBUILD : error MSB1067: Must provide a feature name for the featureavailability switch.
    Full command line: 'msbuild /fa'
  Switches appended by response files:
Switch: /fa

For switch syntax, type "MSBuild -help"

Property Function CheckFeatureAvailability

string CheckFeatureAvailability(string featureName)

The result is one of "Undefined", "Available", "NotAvailable" strings.

Usage Example:
$([MSBuild]::CheckFeatureAvailability(Feature1))

Testing

Manual and unit tests.

Notes

Copy link
Member

@ladipro ladipro left a comment

Choose a reason for hiding this comment

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

If we go with the command-line support (does it map to a known requirement or is it for completeness/future-proofing?), I think it would be useful to support asking for several or all features with one invocation. The getProperty switch is prior art - it prints just the value when asking for one, and JSON-formatted output when asking for many.

src/Framework/FeatureAvailabilityChecker.cs Outdated Show resolved Hide resolved
Co-authored-by: Ladi Prosek <ladi.prosek@gmail.com>
@surayya-MS
Copy link
Member Author

If we go with the command-line support (does it map to a known requirement or is it for completeness/future-proofing?), I think it would be useful to support asking for several or all features with one invocation. The getProperty switch is prior art - it prints just the value when asking for one, and JSON-formatted output when asking for many.

There are no requirements for command-line support yet, I implemented it for completeness, and might remove it later from the PR. Thanks for suggestion! I agree it is more consistent the way you described. I'll change it to support asking for multiple features.

@ladipro
Copy link
Member

ladipro commented Jan 22, 2024

We could also expose the new functionality as a property function. This would make it available to project files, and via switches like getProperty also to command line, without having to add a new command line switch.

I think we'd want to get @baronfel's feedback here. The requirements would be met with a programmatic API for MSBuild hosts (e.g. IDEs) but it's definitely useful to explore additional angles. Thank you!

@baronfel
Copy link
Member

I agree with Ladi - we should ensure an easy way to check feature enablement at all points that MSBuild can be extended/consumed:

  • CLI (done)
  • API (covers loggers, in-process evaluation/execution)
  • Property Functions (covers various props/targets based extension)

@surayya-MS surayya-MS marked this pull request as ready for review January 24, 2024 13:35
src/Framework/FeatureAvailabilityChecker.cs Outdated Show resolved Hide resolved
src/Framework/FeatureAvailabilityChecker.cs Outdated Show resolved Hide resolved
src/MSBuild/CommandLineSwitches.cs Outdated Show resolved Hide resolved
src/MSBuild/Resources/Strings.resx Outdated Show resolved Hide resolved
Copy link
Member

@JanKrivanek JanKrivanek left a comment

Choose a reason for hiding this comment

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

Good job!

src/Framework/Features.cs Outdated Show resolved Hide resolved
src/Framework/Features.cs Outdated Show resolved Hide resolved
src/Framework/Features.cs Outdated Show resolved Hide resolved
src/Framework/Features.cs Show resolved Hide resolved
src/Framework/Features.cs Outdated Show resolved Hide resolved
Copy link
Member

@ladipro ladipro left a comment

Choose a reason for hiding this comment

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

New command line switches should be added to help output (msbuild -h, dotnet msbuild -h). Probably ok merging as is, as long as we don't forget to add them as part of fixing #9710.

src/MSBuild/XMake.cs Outdated Show resolved Hide resolved
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.

Feature Query API
6 participants