Medallyon
Medallyon

Reputation: 120

Target Framework not installed when opening a Unity project with Visual Studio 2022

I am trying to open a C# solution that has been generated from a Unity v2020.3.19f project with Visual Studio 2022. Opening it with Visual Studio 2019 works just fine, but there are reasons I'd like to be able to open it with v2022 (such as GitHub Copilot). I did not have issues with this on my previous install of Windows 10.

Upon opening the solution in VS2022, I get the following pop-up prompt for every project in the solution:

enter image description here

Choosing the first option updates the target project to .NET Framework 4.8 and loads the project, but the whole file appears with red lines. When hovering over an underlined bool Property, the error shows as: `CS0518: Predefined type 'System.Boolean' is not defined or imported.

Choosing the second option opens this URL in my browser, prompting me to install .NET Framework 4.7.1 targeting pack (which was already installed via the Visual Studio Installer). When I try to install the .NET Framework 4.7.1 runtime, the installer responds with .NET Framework 4.7.1 or a later update is already installed on this computer. When I try to install the .NET Framework 4.7.1 Developer Pack, the installer allows me to choose from "Repair", "Uninstall", or "Cancel". Repairing has no effect.

I installed both versions of Visual Studio (2019 & 2022) the usual way through the Visual Studio Installer, along with the "Game Development with Unity" workload, which tells me it's installed all dependencies just fine:

enter image description here

Here's what I've tried so far:

Nothing works for me. Any help on how to make VS2022 stop complaining is greatly appreciated.

Update 1: I found a couple of threads where people suggested simply pressing the Regenerate project files button in "Edit -> Preferences -> External Tools`. This has not helped me.

Update 2: I've tried everything I can possibly imagine, in different orders and different combinations. I even reinstalled Windows 10 to no avail. It's like Visual Studio just doesn't want to accept that the .NET Framework 4.7.1 targeting pack is installed. Please help :(

Upvotes: 4

Views: 2480

Answers (3)

Elamri Houcine
Elamri Houcine

Reputation: 1

create a new empty project and generate a cs project empty file from vs2022 and the copy your assets and projects settings only remove any vs generated files from previous damaged projects and it will be fine. that happen to me and it's fixed.

Upvotes: 0

Cawhale
Cawhale

Reputation: 36

check this

https://learn.microsoft.com/en-us/answers/questions/733018/visual-studio-2022-cannot-locate-installed-net-fra.html

If you modified the value of ProgramFilesDir(x86), just to modify it back to C:\ProgramFiles(x86) can solve the problem

Upvotes: 2

ZXYNINE
ZXYNINE

Reputation: 732

That is a very interesting problem, my main solution for you to first try is to make sure you are even targeting the correct .net framework in UNITY before you even build the solution. You are using the .NET 4.x, you need to go into your configuration settings and player settings in unity and ensure its not on a different version, for me, unity still defaults to .net standard 2.0. Follow the steps located here. To do so.

Another solution is to see if that first option actually gives you errors that prevent you from using unity, because I know that Visual Studio Code has problems occasionally where it tells me im wrong, my program is wrong, every life choice I have made was poor and I am poor, yet in unity, there are no errors showing in the console and I can hit play no problem. In that case I just had to rebuild a few times and fiddle with vs code until omnisharp stopped yelling at me.

Apperently I have been in a similar situation as when you were getting the error "Predefined type 'System.Object' is not defined or imported" because looking into it, I already have clicked on some of the links, try this one if that error persists. If you cannot prevent the errors to begin with, I would recommend you trying to fix the upgraded version from option one as that is more than likely going to get you the closest to a solution.

Upvotes: 1

Related Questions