简体   繁体   中英

Visual Studio Can't Target .NET Framework 4.8

I'm having some issues creating a project that targets .NET Framework 4.8. I am using Visual Studio 2019, upgraded to version 16.2.5. I have also installed the .NET Framework 4.8 Developer Pack . From the Visual Studio Installer, I don't see any option for enabling 4.8 development tools similar to 4.7 .

Just had a similar issue with Visual Studio 2019 Community Edition: only.Net Core versions were shown.

I edited the .csproj file manually. I changed the line with the TargetFramework property to

<TargetFramework>net48</TargetFramework>

Oddly, now all other versions show up also.

Just thought I'll post my issues as I stumbled across this too with VS2019 Winforms project, and couldn't target anything apart from.Net 5 and Core 3.1. Turns out there're 2 types of Winforms, Winforms App and Winforms App (.Net Framework). The former won't be able to target the other .net framework. The latter is able to. Duh. Simple stuffs that aren't obvious.

This Visual Studio thread had all the answers I was looking for. The .NET Framework 4.8 Developer Pack includes both the SDK and Targeting Pack. After installing this and restarting Visual Studio, I can now see .NET Framework 4.8 as a targeting option for Visual Studio projects. You should not need to do any Visual Studio Installer steps.

Also mentioned in the above thread, .NET Framework 4.8 will be included in the Visual Studio installation process as of 16.3 ( currently listed under 16.3 Preview 2 ).

None of the solutions above fixed my issues but the one by Oak_3260548 Pointed me in the right direction.

In Visual Studio Installer, that can be accessed by clicking on " Tools / Get Tools and features " in the top menu, I selected the " Individual Component " tab and checked " .Net Framework 4.8 Targeting pack ". That fixed it for me. 在此处输入图像描述

I installed framework 4.8 through VS under target frameworks. It wasn't selectable there, under project properties as I would expect.

I wound up having to re-create my VS project. For template, I found framework 4.8 through searching templates in project creation using framework c# console search params. I then copied my files over to the new project folder, and added them as existing items through the solution tool.

For anybody having this issue in VS 2019 Community edition. The problem in my case was confusion over which template to select. Templates for .NET Framework are in parenthesis and lower in the list (not showing at all in my case until I clicked the "clear" link next to the search box).

Examples:

Console App (.NET Framework) ASP.NET Web Application (.NET Framework) Class Library (.NET Framework) etc

I have found a solution: If I want Visual Studio Community 2019 to target .NET 4.8, I can create some simple projects by using Visual Studio Express 2013. In the Project settings I change the required .NET (up to 4.8) and save. After that, you can open that project with Visual Studio Community 2019 and you will see in the Project settings all .NET target options up to 4.8.

However, if you want to play with .NET Core 3.1 and .NET 5.0, you have to create a new project from within Visual Studio Community 2019.

No solution above solved my problem. The note in https://docs.microsoft.com/en-us/visualstudio/ide/step-1-create-a-windows-forms-application-project?view=vs-2019 point 2 note helped:

Note

If you don't see the Windows Forms App (.NET Framework) template, you can install it from the Create a new project window. In the Not finding what you're looking for? message, choose the Install more tools and features link.

The 'Install more tools and features' link from the 'Not finding what you're looking for' message in the 'Create new project' window

在此处输入图像描述

Next, in the Visual Studio Installer, choose the .NET desktop development workload.

在此处输入图像描述

After that, choose the Modify button in the Visual Studio Installer. You might be prompted to save your work; if so, do so. Next, choose Continue to install the workload.

Although I always check this when installing VS it was missing. And the tepmlates were missing even though I had the correct trageting packs installed.

C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets

<!--
<GetReferenceAssemblyPaths
    Condition="'$(TargetFrameworkMoniker)' != '' and ('$(_TargetFrameworkDirectories)' == '' or '$(_FullFrameworkReferenceAssemblyPaths)' == '')"
    TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
    RootPath="$(TargetFrameworkRootPath)"
    TargetFrameworkFallbackSearchPaths="$(TargetFrameworkFallbackSearchPaths)"
    BypassFrameworkInstallChecks="$(BypassFrameworkInstallChecks)"
    >
  <Output TaskParameter="ReferenceAssemblyPaths" PropertyName="_TargetFrameworkDirectories"/>
  <Output TaskParameter="FullFrameworkReferenceAssemblyPaths" PropertyName="_FullFrameworkReferenceAssemblyPaths"/>
  <Output TaskParameter="TargetFrameworkMonikerDisplayName" PropertyName="TargetFrameworkMonikerDisplayName" Condition="'$(TargetFrameworkMonikerDisplayName)' == ''"/>
</GetReferenceAssemblyPaths>
-->

1. Choose WPF APP (.NET Fromework) with XMAL

2. Select .NET 4.8

On Visual Studio 2022, I choose the WPF APP (.NET Fromework) with XMAL can support .NET Framework

Even with lower Visual studio (mine is 15.2 under Win 2008 R2), you can do it!

  1. Install both Net Framework 4.8 Runtime AND Developper Pack
  2. Reboot the server
  3. Open your existing project and in the project properties, switch the framework to 4.8

That's it!

enter image description here What happens when I get prompted

every time I click continue, it doesn't seem to install or allow me to go forward, it visibly shows that my files are unloaded. Am I doing something wrong?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM