NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

dotnet build fails due to obj/project.assets.json not refreshed in certain case #9372

Open Deepscorn opened 4 years ago

Deepscorn commented 4 years ago

Details about Problem

NuGet product used dotnet.exe

NuGet version 5.5.0.4

dotnet.exe --version 3.1.200 & 3.0.100

OS version win10 & macOSX catalina

Detailed repro steps so we can see the same problem

  1. Create console .net core project (TargetFramework netcoreapp3.1, will call it "edart") with 2 dependencies: TargetFramework netcoreapp3.0 ("dart") TargetFramework netstandard2.0 ("nub")

  2. Build it using dotnet 3.1.200:

dotnet build "path to edart.sln"

So, you are building with dotnet 3.1 dart 3.0 edart 3.1

You'll see it builds successfully.

  1. Now, will use the following versions:

dotnet 3.0 dart 3.0 edart 3.0

Update TargetFramework in edart.csproj accordingly

Build it with dotnet 3.0.100

You'll see it builds successfully.

  1. Now use versions from step 2. You'll get the following error (2):

If you look inside obj/project.assets.json, you'll see it was not refreshed.

Found out, that it can be fixed by removing nuget packages cache: dotnet nuget locals global-packages --clear

or by removing obj & bin in all 3 projects (we are using this workaround right now).

BTW It reproduces on different versions too, if you make steps in this order: 1 - 3 - 2 - 3

Logs

`Microsoft (R) Build Engine версии 16.5.0+d4cbfca49 для .NET Core (C) Корпорация Майкрософт (Microsoft Corporation). Все права защищены.

Восстановление завершено в 57,23 ms для C:\Users\iz\projects\bug_project_assets_json\gist\libs\nub\nub.csproj. Восстановление завершено в 88,24 ms для C:\Users\iz\projects\bug_project_assets_json\gist\dart\dart.csproj. Восстановление завершено в 91,12 ms для C:\Users\iz\projects\bug_project_assets_json\Toolset\edart\edart.csproj. nub -> C:\Users\iz\projects\bug_project_assets_json\gist\libs\nub\bin\Debug\netstandard2.0\nub.dll H:\dart.sdk\dotnet.3.1.200\sdk\3.1.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1005: файл ресурсов "C:\Users\iz\projects\bug_project_assets_json\Toolset\edart\obj\project.assets.json" не содержит целевого объекта для ".NETCoreApp,Version=v3.1". Проверьте, что восстановление выполнено и вы включили "netcoreapp3.1" в TargetFrameworks своего проекта. [C:\Users\iz\projects\bug_project_assets_json\Toolset\edart\edart.csproj] dart -> C:\Users\iz\projects\bug_project_assets_json\gist\dart\bin\Debug\netcoreapp3.0\dart.dll

Ошибка сборки.

H:\dart.sdk\dotnet.3.1.200\sdk\3.1.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1005: файл ресурсов "C:\Users\iz\projects\bug_project_assets_json\Toolset\edart\obj\project.assets.json" не содержит целевого объекта для ".NETCoreApp,Version=v3.1". Проверьте, что восстановление выполнено и вы включили "netcoreapp3.1" в TargetFrameworks своего проекта. [C:\Users\iz\projects\bug_project_assets_json\Toolset\edart\edart.csproj] Предупреждений: 0 Ошибок: 1

Прошло времени 00:00:01.52`

Verbose logs attached (error_log.txt.zip)

error_log.txt.zip

Side notes

Why do we switch versions back & forth? Answering: we work in git repository and have prod branch & dev branch, which can have different versions.

Deepscorn commented 4 years ago

Attaching the project with repro. With this you can simply reproduce.

  1. Open following files in you lovely text editor: gist\dart\dotnet.version gist\dart\dart.csproj Toolset\edart\edart.csproj With those you can set versions.

  2. Set versions as follows: dotnet dart edart 3.1.200 3.0 3.1

perform build. By the way you can do that simply with: dart.bat / dart.sh It's our tool, which downloads dotnet and use it to execute, which we give to our customers. Works like gradlew (gradle wrapper in android).

At the end, you'll see build successfull and "hello world" output

  1. Set versions as follows: dotnet dart edart 3.0.100 3.0 3.0

Run dart or manually download dotnet core 3.0.100 and run (runs ok)

  1. Set versions back, as in step 2. The error is reproduced

bug_project_assets_json.zip

Deepscorn commented 4 years ago

May be related: https://github.com/dotnet/project-system/issues/3164 https://github.com/NuGet/Home/issues/7368

Deepscorn commented 4 years ago

Note: This does not reproduce when you change versions smoothly: start from the clean state (for example clean both caches: nuget packages & bin & obj) dotnet dart edart 3.0 3.0 3.0 ok 3.1 3.0 3.0 ok 3.1 3.0 3.1 ok, 3.1 3.1 3.1 ok (going back) 3.1 3.0 3.1 ok 3.1 3.0 3.0 ok 3.0 3.0 3.0 ok

And if you change versions not smoothly, here comes the error again: 3.1 3.0 3.1 ok 3.0 3.0 3.0 fail error NETSDK1005: resource file "C:\Users\iz\projects\scm\Toolset\edart\obj\project.assets.json" does not contain target ".NETCoreApp,Version=v3.0"