dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.2k stars 1.35k forks source link

MSBuild does not resolve WindowsBase correctly #8289

Open EatonZ opened 1 year ago

EatonZ commented 1 year ago

Describe the bug

I am working with third-party components (DevExpress) and their new release based on .NET 6 appears to have exposed a potential bug in MSBuild's assembly resolution logic. There appears to be a versioning conflict between two WindowsBase DLLs in the WindowsDesktop and NETCore SDKs. For further details, please see this public support ticket. In particular, this reply.

The issue applies to both .NET 6 and .NET 7 WindowsDesktop projects.

To Reproduce

Here is a sample project you can build to reproduce. Just build it and look in the Visual Studio build output to see the below lines.

Exceptions (if any)

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3277: Found conflicts between different versions of "WindowsBase" that could not be resolved.
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3277: There was a conflict between "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" and "WindowsBase, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35".
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3277:     "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" was chosen because it was primary and "WindowsBase, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" was not.
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3277:     References which depend on "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" [C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.1\ref\net7.0\WindowsBase.dll].
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3277:         C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.1\ref\net7.0\WindowsBase.dll
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3277:           Project file item includes which caused reference "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.1\ref\net7.0\WindowsBase.dll".
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3277:             C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.1\ref/net7.0/WindowsBase.dll
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3277:     References which depend on "WindowsBase, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" [].
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3277:         C:\Users\Eaton\Source\Repos\WinFormsApp1\WinFormsApp1\DevExpress.Data.Desktop.v22.2.dll
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3277:           Project file item includes which caused reference "C:\Users\Eaton\Source\Repos\WinFormsApp1\WinFormsApp1\DevExpress.Data.Desktop.v22.2.dll".
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3277:             DevExpress.Data.Desktop.v22.2

Further technical details

Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.101\

Host: Version: 7.0.1 Architecture: x64 Commit: 97203d38ba

.NET SDKs installed: 6.0.202 [C:\Program Files\dotnet\sdk] 7.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download


- The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
`Visual Studio 2022 Version 17.4.3 (Windows)`
KalleOlaviNiemitalo commented 1 year ago

@RobThree I think it would be better to file that as a separate issue because it likely has a different root cause and has to be fixed and tested separately.

RobThree commented 1 year ago

@KalleOlaviNiemitalo I figured out it had to do with MySQL.Data 8.0.32 (so, yes, this is unrelated, sorry, my bad).

hyke123 commented 1 year ago

Has this issue been resolved? Which version of Visual Studio can I build without encountering these warnings? Thanks.

EatonZ commented 1 year ago

@hyke123 It has not been resolved as of the latest VS version (17.5.3). No one from MS has commented here on the issue yet - still waiting.👀

BrightLight commented 1 year ago

Maybe dotnet/sdk would be a better fit for this. There are some issues that sound related, for instance WindowsBase NETCoreApp vs WindowsDesktopApp Do not autoreference WindowsBase.dll in Microsoft.NetCore.App

dedale commented 11 months ago

To circumvent this error, you may try to look at project.assets.json to help identify if some dependency is bringing in old Windows base version and then update this dependency accordingly. HTH

dedale commented 11 months ago

I actually fixed this with

<UseWPF>true</UseWPF>
EatonZ commented 11 months ago

@dedale Thanks for the suggestion, but I do not use that file, and my project is WinForms and not WPF.

This issue still happens as of today. Hopefully something will be done for .NET 8?

dedale commented 11 months ago

@dedale Thanks for the suggestion, but I do not use that file, and my project is WinForms and not WPF.

This issue still happens as of today. Hopefully something will be done for .NET 8?

My project is WinForms too so I enabled both 🤷‍♂️ . Otherwise you'll see in VS in framework dependencies of your project that WindowsBase is only taken from NetCore.App (in version 4). My finding is that when you also enable UseWPF, NetCore.WindowsApp dependencies also include WindowsBase is version of your tfm i.e. 6 or 7).

dedale commented 11 months ago

@EatonZ see https://github.com/dotnet/sdk/issues/10378#issuecomment-511596653 and also https://stackoverflow.com/a/69397047/305023

EatonZ commented 11 months ago

@dedale Unfortunately just adding that to my csproj breaks the project:

Build Errors

char8t commented 5 months ago

I have the very same issue with the WindowBase Assembly resolution but with a different kind of project (Maui Blazor Hybrid App) and running on .NET 8. Also adding <UseWPF>true</UseWPF> will totally break the project.

warning MSB3277: Es wurden Konflikte zwischen verschiedenen Versionen von "WindowsBase" gefunden, die nicht aufgelöst werden konnten.
warning MSB3277: Konflikt zwischen WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 und WindowsBase, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
warning MSB3277:     WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 wurde aufgrund der primären Eigenschaft WindowsBase, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 vorgezogen.
warning MSB3277:     Verweise, die von "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" abhängig sind [C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.2\ref\net8.0\WindowsBase.dll].
warning MSB3277:         C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.2\ref\net8.0\WindowsBase.dll
warning MSB3277:           Elementincludes einer Projektdatei, die den Verweis "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.2\ref\net8.0\WindowsBase.dll" verursacht haben.
warning MSB3277:             C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.2\ref/net8.0/WindowsBase.dll
warning MSB3277:     Verweise, die von „WindowsBase, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35“ [] abhängen oder damit vereint wurden.
warning MSB3277:         C:\Users\<redacted>\.nuget\packages\emgu.cv.wpf\4.8.1.5350\lib\netcoreapp3.1\Emgu.CV.Wpf.dll
warning MSB3277:           Elementincludes einer Projektdatei, die den Verweis "C:\Users\<redacted>\.nuget\packages\emgu.cv.wpf\4.8.1.5350\lib\netcoreapp3.1\Emgu.CV.Wpf.dll" verursacht haben.
warning MSB3277:             C:\Users\<redacted>\.nuget\packages\emgu.cv.wpf\4.8.1.5350\lib\netcoreapp3.1\Emgu.CV.Wpf.dll
Nico-1987 commented 3 months ago

I also face this error in one of my projects. I found that when referencing an assembly that depends on WindowsBase version 6, the conflict happens. I can reproduce this in a very simple project, using both .NET 6 SDK and .NET 8 SDK.

I have no desire to enable UseWPF in this project, as this project has no UI layer.

Interestingly enough, when changing the Reference into a PackageReference, the warning is gone. Even though Visual Studio references the same full path of the dll.

In this particular situation i am not able to use a PackageReference to the file i need, i need to use an assembly reference.

Why does an assembly reference cause WindowsBase 4.0.0.0 to be included?

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0-windows10.0.19041</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="C:\Users\username\.nuget\packages\system.reactive\6.0.0\lib\net6.0-windows10.0.19041\System.Reactive.dll" />
  </ItemGroup>

</Project>

Resulting in error

MSB3277 Found conflicts between different versions of "WindowsBase" that could not be resolved.
There was a conflict between "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" and "WindowsBase, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35".
    "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" was chosen because it was primary and "WindowsBase, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" was not.
    References which depend on "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" [C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.29\ref\net6.0\WindowsBase.dll].
        C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.29\ref\net6.0\WindowsBase.dll
          Project file item includes which caused reference "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.29\ref\net6.0\WindowsBase.dll".
            C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.29\ref/net6.0/WindowsBase.dll
    References which depend on or have been unified to "WindowsBase, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" [].
        C:\Users\username\.nuget\packages\system.reactive\6.0.0\lib\net6.0-windows10.0.19041\System.Reactive.dll
          Project file item includes which caused reference "C:\Users\username\.nuget\packages\system.reactive\6.0.0\lib\net6.0-windows10.0.19041\System.Reactive.dll".
            C:\Users\username\.nuget\packages\system.reactive\6.0.0\lib\net6.0-windows10.0.19041\System.Reactive.dll    ConsoleApp2     
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets  2401