question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Upgrade Project fixer should be able to upgrade TargetFramework to support new language versions

See original GitHub issue

Scenario: you have an existing netcoreapp3.1 project and you just installed VS 16.8. You want to try some of the new C# 9 features so you go into your code and add:

record Widget(string Name, int Id);

This gives some diagnostics about how there’s no type named ‘record’ in scope, this language feature requires LangVersion 9.0, etc. So you use the lightbulb menu to upgrade your project’s LangVersion to 9.0.

However, the TargetFramework in your project is unchanged. Instead of building successfuly, the fixed project has the diagnostic: CS0518 Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported. This type is only present in net5.0, so you have to upgrade the TargetFramework or declare the type yourself (not officially supported) in order to use records. note: it’s a bug that the upgrade was offered to a language version not supported by the target framework. Tracked by #47983

Given this behavior, and given that we basically require using new TargetFramework in order to adopt new language versions (old TargetFrameworks are unsupported in combination with newer LangVersions), perhaps the UpgradeProject fixer should offer to change the TargetFramework instead of the LangVersion in certain scenarios.

/cc @CyrusNajmabadi @jcouv

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
sharwellcommented, Sep 24, 2020

@RikkiGibson Thanks, I updated the title and removed the records label since it applies to all version-specific features starting with C# 8

0reactions
RikkiGibsoncommented, Sep 24, 2020

This issue tracks the suggestion to automatically upgrade the user’s TargetFramework. #47983 tracks the bug where the UpgradeProject code fix is offered in scenarios it should not be offered in.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to upgrade a Windows Forms desktop app to .NET 7
NET Framework projects and .NET projects. However, the latest .NET releases provide many language and compiler improvements over .NET Standard.
Read more >
How to change C# Language Version for all of the projects ...
If possible - you could also upgrade your Visual Studio to 2019 where default language versions are set as what you want. –...
Read more >
Upgrade Tooling for .NET 7
NET Incremental Migration (to help the old and new projects ... You can find the latest docs and news about Upgrade Assistant on...
Read more >
Upgrade Your Existing Projects to .NET7 - ABP Community
Upgrade Your Existing Projects to .NET7. A new .NET version has come. ... First, you need to update all your *.csproj files to...
Read more >
dotnet/upgrade-assistant
NET 6 and beyond - GitHub - dotnet/upgrade-assistant: A tool to assist developers in upgrading . ... NET Framework projects to the latest...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found