dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

Project Build Issues after upgrading to Dotnet 5 #15071

Open lukos opened 3 years ago

lukos commented 3 years ago

Since upgrading our build servers to dotnet 5, the behaviour of our builds has changed and is now broken. I keep trying different tricks and workarounds but they sometimes seem to work and sometimes don't. I am wasting so much of my time.

Scenario

We have a solution that contains a mixture of netstandard and netfx 4.7.2 projects. We have individual builds on our build server for projects within this solution. The build steps were:

  1. nuget restore against the solution
  2. msbuild of the solution
  3. dotnet pack for the project

This used to work fine but after installing .Net 5 (which updated dotnet), although I can't rule out that Windows update didn't do anything at that point, we started seeing the following error:

C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241, 5): error NETSDK1005: Assets file 'C:\TeamCity\buildAgent\work\2357397f21417b8a\Src\Shared.Common\obj\project.assets.json' doesn't have a target for 'netstandard2.0'.

Note the project mentioned is netstandard2.0.

I tried googling and found various articles saying to run dotnet restore at the start of the process. So I added that in but that then caused a different error against a netfx project:

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\NuGet\16.0\Microsoft.NuGet.targets(198, 5): Your project file doesn't list 'win' as a "RuntimeIdentifier". You should add 'win' to the "RuntimeIdentifiers" property in your project file and then re-run NuGet restore.

I then found advice to disable both of the restore steps and to use the restore target in msbuild, which I added and which seemed to fix the problem but I suspect it only seemed to work since the depedencies were already cached on the build server. We added another build server and the build failed due to missing dependencies. I added back in the nuget restore step and it seemed to work but now it doesn't work on the first server again. Other advice mentioned modifying the projects but I didn't want to start down a slippery slope without understanding what was happening and when the builds used to work fine.

I have tried with every combination of both restore steps, neither, msbuild, dotnet etc. and everything seems to cause some problem or other.

I feel like this should just work, that nuget/msbuild/dotnet should handle what they can handle and ignore what they can't - or at least provide clear errors if we are definitely doing something wrong. I also don't know why MS seems to consistently break the tooling everytime they make a major release. We have problems with netstandard in netfx projects, with assembly redirects that don't get added properly, with esoteric messages, with "improvements" that are breaking changes, with a plethora of versions, incompatabilities, magic advice on StackOverflow which sometimes work for reasons unknown and with a broken mix of versions in the Microsoft.Extensions packages that require manual fixing of assembly redirects after every update of packages. Please can you advise why this is not working or is this already a know bug with .Net 5?

sfoslund commented 3 years ago

I'm sorry to hear upgrading has been difficult, have you updated your entire toolset or just the SDK? The .NET 5 SDK is compatible with Visual Studio/ nuget 16.8 and above, and from one of the error messages it appears you're still using 16.0. Can you try to update the rest of your toolset and see if this makes a difference?

skelendal commented 3 years ago

I was having a similar issue after installing .net5 SDK on a TeamCity build agent. I started getting the Your project file doesn't list 'win' as a "RuntimeIdentifier". You should add 'win' to the "RuntimeIdentifiers" property in your project file and then re-run NuGet restore. error weirdly on an older project that does not use .net5 yet. The actual .net5 project was fine. The solution was to use 'nuget.exe restore' instead of 'dotnet restore' on the older project.