11

I am creating a Simple application in ASP.NET 5 Console in VS2015 CTP. For the below line of code

// Wait for user input
            Console.ReadKey(); 

I am getting error 'Console' does not contain a definition for 'ReadKey'. Also i am getting a Suggestion as ASP.Net 5.0-Available ASP.NET Core 5.0- Not available. ReadKey keyword is no more used ? what does that suggestion means i need to add some reference ?

Shrivallabh
  • 2,863
  • 2
  • 27
  • 47

1 Answers1

16

Basically, Console.ReadKey is available in the full framework, but isn't available in .NET Core. That's why it's saying it's "Available" for ASP.NET 5.0 (building against the full framework) but "Not available" for ASP.NET Core 5.0 (building against CoreCLR).

Either stop using it, or only build against the full framework - edit your project.json file to remove the "core" option from your frameworks property. (Exactly what it will be called will depend on which version of ASP.NET 5 you're using. It may be dnxcore50 for example.)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • You just beat me to it! – Icemanind Jun 02 '15 at 06:04
  • @JonSkeet You mean i have to use normal console application ? – Shrivallabh Jun 02 '15 at 06:07
  • @Shrivallabh: No, I mean that you can edit your project.json to remove the attempt to build against .NET Core. – Jon Skeet Jun 02 '15 at 06:07
  • That worked @JonSkeet. This means if i build with both Core and Full Framework then i should only use those methods which both of them support? – Shrivallabh Jun 02 '15 at 06:15
  • 3
    @Shrivallabh: Yes - or use conditional compilation (`#if ...`) if necessary. – Jon Skeet Jun 02 '15 at 06:16
  • @JonSkeet: sorry for the newbie question, what would I put as the condition for the if statement to only run for the full ASP.NET 5.0? – Nathan Hanna Nov 06 '15 at 18:52
  • @Nathan: You'd need to use `#if` and define a compiler preprocessor symbol for just that build. Haven't looked at how to do that. – Jon Skeet Nov 06 '15 at 18:54
  • 1
    Thanks for the quick response @Jon, and for those wondering, it looks like you just use the all caps version number as the condition (ex: #if DNX451) the documentation is here: http://docs.asp.net/en/latest/conceptual-overview/dotnetcore.html#building-applications-with-net-core – Nathan Hanna Nov 06 '15 at 19:15