Skip to content

Feature Request: Ability to set default language for dotnet new #4950

Closed

Description

@khellang

Now that there are several commands, dotnet repl and dotnet new, that supports language arguments, I think it makes sense to be able to somehow specify a default language.

If you primarily work with F# projects, I think it'd be nice to not have to specify --lang fsharp every time you want to create a new project or start the repl.

Is there an existing configuration mechanism in place?

I propose a simple DOTNET_DEFAULT_LANGUAGE environment variable that you can set to [c#|cs|csharp|f#|fs|fsharp].

Activity

  1. enricosada commented on Jan 29, 2016

    @enricosada
    Contributor

    👍 i can implement it, if it's approved

    I think only dotnet new and dotnet repl should use it, the other commands doesnt required a lang argument as input.

    example of current commands (or future discussed improvement):

    • dotnet new fsharp/console ( my next pr as discussed in dotnet-new enhancements #4695 )
    • dotnet repl f# ( i think we can use argument instead of --lang )
  2. khellang commented on Jan 29, 2016

    @khellang
    MemberAuthor

    Yeah, I was kinda just filing an issue before sending a PR, just to make sure I don't do any unnecessary work...

  3. enricosada commented on Jan 29, 2016

    @enricosada
    Contributor

    @khellang sure, better to discuss about it before pr 😄
    I wrote about implement it because it's something i really like to use, no need to wait ms

  4. davidfowl commented on Jan 29, 2016

    @davidfowl
    Member

    Here's a potential problem with an environment variable:

    • Who reads it? If you think about the set of things that need to know about that setting, VS tools, Omnisharp, the CLI itself. Any API that wants to reason about the project data.
    • Project to project references can be multi language and not having the language in the project file assumes that all projects have the same language (today C# is hardcoded as the fallback when nothing is specified).

    A better solution would be to have things declared in global.json and inherited by default in the project.json file.

  5. enricosada commented on Jan 29, 2016

    @enricosada
    Contributor

    Who reads it? If you think about the set of things that need to know about that setting, VS tools, Omnisharp, the CLI itself. Any API that wants to reason about the project data

    dotnet-new and dotnet-repl, only these tools
    Tools can just pass the argument --lang or similar if need specific language

    Project to project references

    i think project.json it's ok with compilerName, we use "compilerName": "fsc" so it's ok
    I think default compilerName to c# it's not a problem, in F# we can explicit set it in project.json

  6. davidfowl commented on Jan 29, 2016

    @davidfowl
    Member

    The main point was trying to explain why an environment variable doesn't work as well as you would think.

  7. khellang commented on Jan 29, 2016

    @khellang
    MemberAuthor

    It'll be exactly the same as DOTNET_BUILD_VERSION and DOTNET_ASSEMBLY_FILE_VERSION (here).

    A better solution would be to have things declared in global.json and inherited by default in the project.json file.

    That's why I asked:

    Is there an existing configuration mechanism in place?

    If you think this would be a better place for it and make the CLI read that, it's fine for me.

    This suggestion was specific for the CLI, not something that VS, OmniSharp etc. would read. They can provide their own defaults.

  8. davidfowl commented on Jan 29, 2016

    @davidfowl
    Member

    It'll be exactly the same as DOTNET_BUILD_VERSION and DOTNET_ASSEMBLY_FILE_VERSION (here).

    Agreed it's the same. The difference is that the IDE and tool chain don't really need to know about those since it shells out to the command line to produce a build. You could imagine having a property page setting tool environment.

    This suggestion was specific for the CLI, not something that VS, OmniSharp etc. would read. They can provide their own defaults.

    That's not a great experience. The CLI consists of a set of command line tools and libraries that all need to work together. When we designed the DNX we made sure to keep the systems that all need to read data in sync so that things always worked in editors and IDEs and APIs.

    Another example of this is passing the packages folder on the command line to dotnet restore. It's perfectly reasonable to do that but if you do choose to do it, dotnet build would break, omnisharp and VS would break and the runtime would break. Thats why nuget.config and global.json work better in the general case.

  9. enricosada commented on Jan 29, 2016

    @enricosada
    Contributor

    but global.json need to exists before i can do dotnet new or repl
    I cannot open a prompt and do dotnet new in a specific folder, i need to copy the global.json.
    If like that, it's better dotnet new fsharp/console or dotnet new console --lang f#

  10. davidfowl commented on Jan 29, 2016

    @davidfowl
    Member

    What if the environment variable was a default for dotnet new? Is that what we're talking about? I was under the impression that we were changing the default language without specifying any language in the file. If this is just a way to avoid the command line arg then it's fine.

  11. khellang commented on Jan 29, 2016

    @khellang
    MemberAuthor

    If this is just a way to avoid the command line arg then it's fine.

    Yes, that's it. Just a simple way to "always pass --lang fsharp" 😁

  12. davidfowl commented on Jan 29, 2016

    @davidfowl
    Member

    As long as the language ends up in the project file then we're fine. I thought the point was to avoid that.

  13. enricosada commented on Jan 29, 2016

    @enricosada
    Contributor

    sure, np about project files.
    i think it's better to have explicit compilerName: fsc in project.json, we dont want to change that

    it's to avoid in dotnet new and dotnet repl only

  14. shahid-pk commented on Jan 29, 2016

    @shahid-pk
    Contributor

    👍 yes plz

  15. thesmithee commented on Feb 25, 2016

    @thesmithee

    @enricosada is the fix in? I think we do have the language information in the project.json now, correct?

  16. enricosada commented on Feb 25, 2016

    @enricosada
    Contributor

    @BlackDwarf f# works on Windows, project.json is ok, dotnet cli too.

    This issue it's about reading an env var DOTNET_DEFAULT_LANGUAGE so dotnet new use the language of this env var as default. if not set the default is c#, the current behaviour

    It's really useful, to stop continue to write --lang f# for f# users (and vb too)

    DOTNET_DEFAULT_LANGUAGE affect only dotnet new. The others commands are ok already. Maybe dotnet repl can read it too, but it not needed atm

    @BlackDwarf if the idea of DOTNET_DEFAULT_LANGUAGE it's ok, pls write an ok there so someone can implement it. It's a really nice up-for-grab

  17. TheRealPiotrP commented on Jul 27, 2016

    @TheRealPiotrP

    @mlorbetske @livarcocc something to consider in your dotnet new work.

  18. changed the title [-]Feature Request: Ability to set default language[/-] [+]Feature Request: Ability to set default language for dotnet new[/+] on Nov 10, 2016
  19. khellang commented on Feb 8, 2017

    @khellang
    MemberAuthor

    Why was this closed? I see no linked PR that fixes this... 😕

  20. enricosada commented on Feb 8, 2017

    @enricosada
    Contributor

    I'll reopen in dotnet/templating. But i see in global.json a property :)

  21. enricosada commented on Feb 8, 2017

    @enricosada
    Contributor

    @khellang there is dotnet/templating#115 about that

  22. TheRealPiotrP commented on Feb 9, 2017

    @TheRealPiotrP

    Thanks @enricosada. I closed as the original dotnet new is no more, replaced by the templating implementation. Glad you moved this over :)

  23. transferred this issue fromdotnet/clion Jan 31, 2020
  24. added this to the Backlog milestone on Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions