简体   繁体   English

.NET 5 是否支持旧的 csproj 格式?

[英]Does .NET 5 support the old csproj format?

One of the biggest hurdles when migrating from .NET Framework to .NET 5+ is having to convert all csproj's to the new SDK-style format.从 .NET Framework 迁移到 .NET 5+ 的最大障碍之一是必须将所有 csproj 转换为新的 SDK 样式格式。 There is no tool to automate this, it has to be done manually.没有工具可以自动执行此操作,必须手动完成。

I wonder if this conversion is necessary?我想知道是否需要这种转换? Is there a way to switch to .NET while keeping the old cs projects?有没有办法在保留旧的cs项目的同时切换到.NET?

With 300+ projects in my team's solution it looks like we are never going to switch.我团队的解决方案中有 300 多个项目,看起来我们永远不会切换。 It's just too much work.工作量太大了。

I have tried updating the <TargetFramework> manually and that didn't work.我尝试手动更新 <TargetFramework> 但没有用。

Maybe I'm missing something and there is a way to achieve this?也许我遗漏了一些东西并且有办法实现这一目标?

Not a direct answer to you question but it may help.不是对您问题的直接回答,但可能会有所帮助。 My goal wasn't to convert to .net 5, just to convert my projects to SDK style.我的目标不是转换为 .net 5,只是将我的项目转换为 SDK 样式。

I have a solution of four.net 4.0 projects including a WPF project and also four xUnit test projects.我有四个 .net 4.0 项目的解决方案,包括一个 WPF 项目和四个 xUnit 测试项目。 There is a .net upgrade assistant I used and I just stopped after the "convert project to sdk style step".我使用了一个 .net 升级助手,我在“将项目转换为 sdk 样式步骤”之后就停止了。 It worked mostly without issues.它基本上没有问题。 I got the idea from this stack overflow post (see comment under accepted answer).我从这个堆栈溢出帖子中得到了这个想法(请参阅已接受答案下的评论)。

The link above says Visual Studio 2022 or latter but I have 2019 and it worked fine.上面的链接说 Visual Studio 2022 或更高版本,但我有 2019,它运行良好。 I think it says that as you'll need 2022 if you are doing the full migration to .net 6/7.我认为它说如果您要完全迁移到 .net 6/7,则需要 2022。

The only other thing I did before converting to SDK was update each project to use PackageReference instead of packages.config.在转换为 SDK 之前,我唯一做的另一件事是更新每个项目以使用 PackageReference 而不是 packages.config。 I'm not sure if that's important as I did this before deciding to convert my projects to SDK-style.在决定将我的项目转换为 SDK 样式之前,我不确定这是否重要,因为我这样做了。 If you right click on the project you'll see a command called "migrate package.config to package reference".如果您右键单击该项目,您将看到一个名为“将 package.config 迁移到 package 参考”的命令。 After doing that for all projects then go to Tools > Nuget Package Manager > Package Manager Settings and under Package Manager set the "Default package management format" to PackageReference.对所有项目执行此操作后,go 到工具 > Nuget Package 管理器 > Package 管理器设置,然后在 Package 管理器下将“默认 package 管理格式”设置为 PackageReference。 See here .这里

I then converted each project one at a time ensuring each one built OK before moving on to the next project.然后,我一次一个地转换每个项目,确保每个项目都构建正常,然后再继续下一个项目。 The only issue I ran into is the migration assistant adds a more recent version of Microsoft.CSharp to each project reference.我遇到的唯一问题是迁移助手向每个项目引用添加了更新版本的 Microsoft.CSharp。 For my WPF project I had to remove that and replace with the version for .net 4.0;对于我的 WPF 项目,我不得不删除它并替换为 .net 4.0 的版本; for the other projects I just had to remove it as it wasn't being used.对于其他项目,我只需要删除它,因为它没有被使用。 I'm not sure why it does that but thinking it's for a subsequent step in the migration.我不确定为什么这样做,但认为这是为了迁移的后续步骤。

The csprojs are now much cleaner. csprojs 现在更干净了。 Also enables the "Remove unused references" option in the project right-click menu.还启用项目右键菜单中的“删除未使用的引用”选项。

I also confirmed I'm able to use do.net build myProject.csproj from the command line as well.我还确认我也可以从命令行使用 do.net build myProject.csproj。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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