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.6k stars 1.03k forks source link

dotnet publish with test project leads to "Could not load file or assembly 'Microsoft.Extensions.FileSystemGlobbing, Version=3.1.0.0" #16207

Open timmkrause opened 3 years ago

timmkrause commented 3 years ago

Trying to publish a test project and execute tests within Azure Pipelines (at the bottom you can find dotnet --info).

Getting the following, when trying to run the tests:

System.TypeInitializationException: The type initializer for 'Foo.Bar' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Bar.Baz' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.FileSystemGlobbing, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Stack Trace:
    at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.ChangeTokenInfo..ctor
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.ChangeTokenInfo..ctor(CancellationTokenSource tokenSource, CancellationChangeToken changeToken)
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.GetOrAddFilePathChangeToken(String filePath)
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.GetOrAddChangeToken(String pattern)
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken(String filter)
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider.Watch(String filter)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.<.ctor>b__1_0()
   at Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration`1..ctor(Func`1 changeTokenProducer, Action`1 changeTokenConsumer, TState state)
   at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor(FileConfigurationSource source)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider..ctor(JsonConfigurationSource source)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build(IConfigurationBuilder builder)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()

The problem is, that a wrong version of Microsoft.Extensions.FileSystemGlobbing.dll is part of the artifact (2.0.1.18051 and product version 2.0.1-rtm-10011). It took me some hours to reproduce it and find out what is actually causing the problem. Finally I tried to start from scratch and aligned the project in baby steps to the project which is causing the problem.

Repro steps (.NET Core 3.1 or .NET 5 does not seem to make a difference):

dotnet new mstest

Observe coverlet.collector version 1.3.0 is installed.

dotnet publish --output out-tests

Observe Microsoft.Extensions.FileSystemGlobbing.dll file version 2.0.1.18051 and product version 2.0.1-rtm-10011 in the output folder.

dotnet add package Microsoft.Extensions.Configuration
dotnet add package Microsoft.Extensions.Configuration.Json

dotnet publish --output out-tests

Observe Microsoft.Extensions.FileSystemGlobbing.dll file version 3.100.1221.6909 and product version 1.1.12+4210e7... in the output folder.

dotnet add package coverlet.collector --version 3.0.3

Update coverlet.collector to version 3.0.3 and observe Microsoft.Extensions.FileSystemGlobbing.dll file version 2.0.1.18051 and product version 2.0.1-rtm-10011 which is not the correct version anymore.

Quickly analyzing the NuGet package did not led to anything beside noticing, that it only targets netstandard1.0. Nothing seems to have changed from 1.3.0 to 3.0.3 regarding that DLL, no scripts, nothing. I don't get what is going on. Downgrading coverlet.collector for now.

I don't know if this is the right repo here or if I should raise the bug at coverlet.collector. It seems to me though that publish breaks it somehow, dotnet build always produces the correct version in bin\Debug.

❯ dotnet --info:

.NET SDK (gemäß "global.json"):
 Version:   5.0.200
 Commit:    70b3e65d53

Laufzeitumgebung:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.200\

Host (useful for support):
  Version: 5.0.3
  Commit:  c636bbdc8a

.NET SDKs installed:
  3.1.301 [C:\Program Files\dotnet\sdk]
  5.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Cross ref., even though it's not about testing: https://github.com/dotnet/aspnetcore/issues/27675

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

timmkrause commented 3 years ago

Seems to be fixed, unsure if released already, not retested:

https://github.com/coverlet-coverage/coverlet/issues/1106