Skip to content

Feature request: dotnet --info should include language versions #9214

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

Open
BillWagner opened this issue Mar 22, 2018 · 4 comments
Open

Feature request: dotnet --info should include language versions #9214

BillWagner opened this issue Mar 22, 2018 · 4 comments
Labels
untriaged Request triage from a team member
Milestone

Comments

@BillWagner
Copy link
Member

Currently there is no good way for users to determine which managed language versions are included with each release of the .NET Core SDK.

Ideally, dotnet --info should include the versions of the C# compiler and VB compiler delivered with that SDK.

This was originally reported as part of dotnet/docs#4154

/cc @jcouv @KathleenDollard

@jcouv
Copy link
Member

jcouv commented Mar 22, 2018

This information is typically included in the .NET Core release notes. For example: https://docs.microsoft.com/en-us/dotnet/core/whats-new/

Also, I found a roundabout way of getting the information (provided with path specific to a version of .NET Core): dotnet exec "c:\Program Files\dotnet\sdk\2.2.0-preview1-007622\Roslyn\bincore\csc.dll" -langversion:?

Relates to this SO thread.

@KathleenDollard
Copy link

@BillWagner I think this is a very reasonable idea, but I think it should be in the next version after 2.1.300, which is 2.1.400. I think we're too close to be making changes, particularly in a part of the product that spans two pieces (although this is just in the SDK, part is in the host) and that I think is localized.

In 2.1.400 we want to take a deeper look at how we communicate the state of their system to users. This is a great addition to that conversation, so I'd like to leave this issue open on the CLI. If we look at these versions, I think we should also look at MSBuild and NuGet among others. From an engineering perspective, we're going to have to find a super automated way to get this information, because the wrong information would be worse than no information.

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@msftgits msftgits added this to the Backlog milestone Jan 31, 2020
Copy link
Contributor

Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.

@github-actions github-actions bot added the stale label Apr 25, 2024
@jcouv jcouv added the untriaged Request triage from a team member label Apr 25, 2024
@github-actions github-actions bot removed the stale label Apr 25, 2024
@am11
Copy link
Member

am11 commented Apr 25, 2024

For this kind of JSON structure:

[
  {
    "sdkPath": "...",
    "languages": [
      {
        "language": "C#",
        "languageVersions": ["...", "..."]
      },
      {
        "language": "VB",
        "languageVersions": ["...", "..."]
      },
      {
        "language": "F#",
        "languageVersions": ["...", "..."]
      }
    ]
  }
  ...
]
Here is a C# program which shells out to dotnet --list-sdks.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Text.RegularExpressions;

List<SdkEntry> storage = new();
using var process = Process.Start(new ProcessStartInfo("dotnet", "--list-sdks") { RedirectStandardOutput = true });

string? line = null;
while ((line = process?.StandardOutput.ReadLine()) is not null)
{
    var match = InstalledSdks.Pattern().Match(line);
    var sdkEntry = new SdkEntry(Path.Combine(match.Groups["path"].Value, match.Groups["version"].Value), new());

    string csc = Path.Combine(sdkEntry.sdkPath, "Roslyn", "bincore", "csc.dll");
    using var cscProcess = Process.Start(new ProcessStartInfo("dotnet", [csc, "-langversion:?"]) { RedirectStandardOutput = true });
    sdkEntry.languages.Add(new("C#", cscProcess?.StandardOutput?.ReadToEnd()?.Split('\n', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)[1..]));

    string vbc = Path.Combine(sdkEntry.sdkPath, "Roslyn", "bincore", "vbc.dll");
    using var vbcProcess = Process.Start(new ProcessStartInfo("dotnet", [vbc, "-langversion:?"]) { RedirectStandardOutput = true });
    sdkEntry.languages.Add(new("VB", vbcProcess?.StandardOutput?.ReadToEnd()?.Split('\n', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)[1..]));

    string fsc = Path.Combine(sdkEntry.sdkPath, "FSharp", "fsc.dll");
    using var fscProcess = Process.Start(new ProcessStartInfo("dotnet", [fsc, "--langversion:?"]) { RedirectStandardOutput = true });
    sdkEntry.languages.Add(new("F#", fscProcess?.StandardOutput?.ReadToEnd()?.Split('\n', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)[1..]));

    storage.Add(sdkEntry);
}

Console.WriteLine(JsonSerializer.Serialize(storage, new JsonSerializerOptions { WriteIndented = true }));

file record LanguageEntry(string language, string[]? languageVersions);
file record SdkEntry(string sdkPath, List<LanguageEntry> languages);

static partial class InstalledSdks
{
    [GeneratedRegex(@"(?<version>.*)\s\[(?<path>.*)\]")] public static partial Regex Pattern();
}

Since SDK has most of this context, we can gather the rest in similar (or better) way and make this info emit with:
dotnet --list-compilers --json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

5 participants