1

I just upgraded all of my .NET console/ASP.NET applications from 4.6.2 to 4.7.1. The ASP.NET applications work fine, but running any of my console apps results in the following message:

This application requires one of the following versions of the .NET framework: .NETFramework,Version=v4.7.1

Do you want to install this .NET Framework version now?

Why am I getting this message only for console apps?

oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206

3 Answers3

3

I Tried all of the above, did not work. Clean build no difference.

I then searched for Bin folder in solution explorer and deleted each one. I also did the same for obj folder and then did a rebuild, voila all the problems disappeared. I remember did trick to fix one of MVC upgrades, I think from v3 to v4.

I just wish error messages were not so cryptic!!!!

PBo
  • 399
  • 3
  • 6
  • 1
    The bin/obj folders are not always visible in the solution explorer as they are not part of the solution. on each project you will have to select the project and click on "show All Files" button on the solution explorer toolbar – PBo Dec 02 '17 at 00:10
2

Take a look at your app.config. Especially the <supportedRuntime> element.

<supportedRuntime version="runtime version" sku="sku id"/>

The sku attribute is optional. Maybe you have the value .NETFramework,Version=v4.7.1, which means you specifically target the .NET 4.7.1 framework.

Dávid Molnár
  • 10,673
  • 7
  • 30
  • 55
  • 1
    So I removed the `sku` attribute and now my console apps are working. VS 2017 modifed the config, so why did this break the console app? What are the implications of removing this attribute? – oscilatingcretin Nov 05 '17 at 18:20
  • IMO if you don't use anything specific from .NET 4.7.1, then you are safe to remove the sku. – Dávid Molnár Nov 05 '17 at 18:26
  • 1
    But isn't that why I would upgrade to 4.7.1 to begin with? I want to use 4.7.1 features. – oscilatingcretin Nov 05 '17 at 18:31
  • Yes, but if you don't use the new features now, then why depend on the higher version of the framework? – Dávid Molnár Nov 05 '17 at 18:34
  • 1
    I think I am lost here. When did I say I didn't want to use the 4.7.1 features right now? I do want to use them. That is why I upgraded. – oscilatingcretin Nov 05 '17 at 18:40
  • Then what's the point? The error message says, `This application requires one of the following versions of the .NET framework: .NETFramework,Version=v4.7.1` which is very clear now. And your original question was also answered. – Dávid Molnár Nov 06 '17 at 10:51
2

I finally figured out the issue. For some reason, VS 2017 had only installed the 4.7.1 targeting pack, not the developer pack/SDK. After actually installing the developer pack, I can now run my console apps without removing sku=".NETFramework,Version=v4.7.1" from my app.config.

Prior to this, I was also unable to use the new value tuples, but, oddly, I was able to use other features like declaring concrete methods within methods (as opposed to using Action or Func) and expression-bodied constructors. Don't know how that worked.

oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206
  • 1
    Some of the new features are implemented by the run time (such as value tuples), while others are implemented by the compiler (such as methods within methods). Even if you target an older version of the runtime, VS2017 will still use the latest compiler, so any features implemented by the compiler can be used even though you aren't targeting the latest version of the framework. – Andy Nov 10 '17 at 14:12