I'm working on a WPF project that targets .NET Framework 4.8
1/
Now I'm researching about running that application with .NET 7 but is it possible to do that?
For example, I tried dotnet wpf.exe
but it shown some errors
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Users\admin\Documents\Debug\'.
Failed to run as a self-contained app.
- The application was run as a self-contained app because 'C:\Users\admin\Documents\Debug\wpf.runtimeconfig.json' was not found.
- If this should be a framework-dependent app, add the 'C:\Users\admin\Documents\Debug\wpf.runtimeconfig.json' file and specify the appropriate framework.
This is some info about the environment (from dotnet --info
)
I've installed a new Windows 10 22H2 so I think .NET Framework 4.8 is included
.NET SDK:
Version: 7.0.101
Commit: bb24aafa11
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.101\
Host:
Version: 7.0.1
Architecture: x64
Commit: 97203d38ba
.NET SDKs installed:
7.0.101 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
2/
If the above is impossible, is there a way to build the .NET Framework project so it can run with .NET 7 without changing (migrating) the current project structure? (Something like I can continue working on .NET Framework project as before then use a specific dotnet
command to build it to .NET 7 executable. Assuming all packages are compatible with .NET 7)
CodePudding user response:
Now I'm researching about running that application with .NET 7 but is it possible to do that?
No. A WPF application that targets the .NET Framework cannot run on the .NET Core/5/6/7 runtime.
You will either have to migrate your application to .NET 7 or stick with running it on the old .NET Framework runtime.
You may target multiple frameworks using an SDK-style project but that's another story. If you want to take advantage of the features available in .NET 7, you will have to migrate and this includes the project file as well. You can still be compatible with .NET Framework if you want though.
But there is no option of doing nothing with the code base and simply run the .NET Framework app as-is on .NET Core or later versions.
The migration itself doesn't necessarily have to be that tricky depending on your code base. Please refer to the link above for more information.