c# - .net 框架到 .net 5 迁移构建但未启动
问题描述
我刚刚将我的 .net Framework 4.8 项目迁移到了 .net 5 中。
首先,我将旧的 csproj 项目配置文件更改为新的。然后删除了多余的程序集,最后删除或更新了所有包。之后我启动了项目兼容性测试,看看我的所有项目是否都与 .net 5 兼容并启动该项目。
奇怪的是,没有更多细节,项目构建(我有一个 .exe),立即启动并关闭自己,我唯一的线索是这条消息:
The target process terminated without raising a CoreCLR start event. Make sure the target process is
configured to use .NET Core. This can be expected behavior if the target process did not run on .NET Core.
Program 'test.exe' terminated with code -2147450740 (0x8000808c).
The program 'test.exe: Program trace' has stopped with code 0 (0x0).
我的 csproj 文件的一部分
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
有人知道出了什么问题吗?
解决方案
我通过以下步骤将我的名为FrameworkToNet5的demo项目(以framework4.7为目标)转换为.Net 5,并且成功,希望对您参考有所帮助:
步骤 1:在 Visual Studio 16.8.1 中创建一个名为FrameworkToNet5Microsoft.Xaml.Behaviors.Wpf
的框架 WPF 项目,并安装在 Nuget 包中。
第 2 步:要启用设计器,请转到工具 > 选项 > 环境 > 预览功能,然后选择使用 .NET Core 应用程序的预览 Windows 窗体设计器选项。
第 3 步:右键单击FrameworkToNet5,然后Analyze and Code Cleanup
单击Run Code Analysis
以检查 .Net 5。
第 4 步:右键单击packages.config
> Migrate packages.config to PackageReference
,然后选择所有top-level
包。
第 5 步:使用以下代码替换 .csproj
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
</ItemGroup>
第 6 步:使用以下代码替换 AssemblyInfo.cs 的内容
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None,
ResourceDictionaryLocation.SourceAssembly )]
第 7 步:清理并重建项目。
推荐阅读
- excel - 如何从命令提示符触发 Visual Studio 宏?
- javascript - React Native,如果单击主类别,则从 JSON 显示子类别列表
- php - 为什么 curl extension_loaded 显示 false 而 curl 存在
- cadence-workflow - Cadence:更改工作流 cron 计划的最佳实践是什么?
- android - 如何通过 Kotlin 在 Android 中使用套接字
- python - 调用 tf.FixedLenSequenceFeature 时无法分配 default_value
- php - 如何在 Laravel 中对深层关系进行搜索?
- python - 如何从 pandas df 中查找和删除相关列
- ssas - DAX 按州和日期划分的余额比例
- autodesk-forge - 获取访问令牌 - Revit 的设计自动化