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

Is C# 7.1 available in preview? #590

Closed
DavidArno opened this issue May 17, 2017 · 10 comments
Closed

Is C# 7.1 available in preview? #590

DavidArno opened this issue May 17, 2017 · 10 comments

Comments

@DavidArno
Copy link

Not sure if this is a good use of an issue here, but here goes 😁

At a conference yesterday, I was listening to Kathleen Dollard. She was of the impression that a preview release of VS with C# 7.1 was available. I'd not heard of this though and thought that 7.1 was coming with VS 20017 update 4 and that there wouldn't be a preview. To further confuse things update 3 is out, yet @gafter has a tentative list of feature for 7.1 coming with that already shipped update.

Anyone have any idea which is the correct version of events here?

@alrz
Copy link
Member

alrz commented May 17, 2017

@svick
Copy link
Contributor

svick commented May 17, 2017

As far as I can tell:

  • The current version of VS 2017 Preview (a.k.a. VS 15.3 Preview) contains a very limited preview version of C# 7.1, which, just like the language features table in its branch suggests, only contains default expressions.
  • The version of Roslyn available from the Roslyn MyGet contains the features in the language features table in the master branch.
    • You can fairly easily try it yourself on .Net Core by adding the Roslyn MyGet to a NuGet.config and then referencing a recent prerelease version of the Microsoft.Net.Compilers package (currently version 3.0.0-dev-61716-08).

    • This means the following code compiles:

      class Program
      {
          static async Task Main() // async Main
          {
              int a = default, b = 42; // default expressions
              var t = (a, b);
              Console.WriteLine(t.a); // infer tuple names
          }
      
          bool M<T>(T t) => t is string s; // pattern matching with generics
      }
  • In both cases, you have to switch the language version from default to latest either in the UI or by adding <LangVersion>Latest</LangVersion> to the csproj.

@DavidArno
Copy link
Author

Thanks @svick, that clarifies things.

@jcouv
Copy link
Member

jcouv commented May 28, 2017

@svick is correct. Only default literal made it into preview 1.

Preview 2 will have all the C# 7.1 features (async Main, inferred tuple names, and pattern matching on a generic type).

You don't have to edit your project file or project settings, there is now a codefixer which offers you to change the LangVersion in your project(s) when you use a new feature.

I assume it's ok to close the issue now. Feel free to re-open if needed.

@jcouv jcouv closed this as completed May 28, 2017
@shanselman
Copy link

Nice. I prefer <LangVersion>7.1</LangVersion> though.

@DavidArno
Copy link
Author

@shanselman,

I prefer to use <LangVersion>latest</LangVersion>. That way, when C# 7.2/8.0 is released, I don't need to update my project again to take advantage of that version's features.

@jcouv,

The current "fix" produces a lot of "fluff" in the project file:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
  <LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
  <LangVersion>latest</LangVersion>
</PropertyGroup>

Is this likely to be improved in a future release to just add <LangVersion>latest</LangVersion> to the standard, non-conditional, <PropertyGroup/>?

@jnm2
Copy link
Contributor

jnm2 commented Aug 17, 2017

@jcouv This isn't the only thing that inserts conditional sections. Almost anything I do in the properties page does this and I have to manually clean up the mess, so it's never even worth the time opening the properties page. Is this going to be fixed?

For example, it's extremely unusual and weird for AllowUnsafeCode to be conditional on build configuration. That's *always* an error when I see it happen.

@CyrusNajmabadi
Copy link
Member

Project file issues should be filed over at https://github.com/dotnet/project-system. Thanks!

@jcouv
Copy link
Member

jcouv commented Aug 25, 2017

Filed dotnet/project-system#2732 for the fluff issue in csproj

@jnm2
Copy link
Contributor

jnm2 commented Aug 25, 2017

You're awesome @jcouv. 🎉

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

No branches or pull requests

7 participants