简体   繁体   中英

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. 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?

With 300+ projects in my team's solution it looks like we are never going to switch. It's just too much work.

I have tried updating the <TargetFramework> manually and that didn't work.

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.

I have a solution of four.net 4.0 projects including a WPF project and also four xUnit test projects. There is a .net upgrade assistant I used and I just stopped after the "convert project to sdk style step". 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. I think it says that as you'll need 2022 if you are doing the full migration to .net 6/7.

The only other thing I did before converting to SDK was update each project to use PackageReference instead of packages.config. I'm not sure if that's important as I did this before deciding to convert my projects to SDK-style. If you right click on the project you'll see a command called "migrate package.config to package reference". 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. 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. For my WPF project I had to remove that and replace with the version for .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. 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.

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