6

I'm currently migrating my WPF projects from .NET Framework 4.8 to .NET 6 using the .NET Upgrade Assistant as a base and then manually fixing the remaining problems.
All my projects have a shared set of libraries, one of this contains both standard classes and a few custom UserControl. When migrating this particular library to .NET 6 the frameworks referenced by this library are Microsoft.NETCore.App and Microsoft.WindowsDesktop.App. The problem is when I try to use this library in another project I get the following warning:

Warning 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.0.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.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" was not.

Looking at the WindowsBase referenced by the two frameworks referenced by the library I see that Microsoft.NETCore.App references WindowsBase v4.0.0.0 while Microsoft.WindowsDesktop.App references WindowsBase v6.0.0.0.
How can I solve this?

6
  • Try to remove WindowsBase dependency and then add it again with correct version. Commented Dec 14, 2021 at 9:27
  • From Visual Studio I can't find a way to remove the dependency from the referenced frameworks. Maybe there's a way to do it manually? Commented Dec 15, 2021 at 7:11
  • How to: Create and remove project dependencies Commented Dec 15, 2021 at 8:16
  • In that menu you see just the dependencies on other projects of the solution, not the ones on which the frameworks referenced by the project rely on Commented Dec 15, 2021 at 10:14
  • How does the project file of the project that doesn't compile look like? Commented Dec 15, 2021 at 16:22

4 Answers 4

1

I met the exact issue as you when upgrading a csharp project from .Net framework to .Net6.

There are some dependencies under assemblies (such as system system.xml) which directed to the wrong framework path but can not be removed or modified. There was no much information about this issue on csdn so it really took me a while to find the root cause by trial and error, and finally it was the WinFX.Targets file imported in my csproj project file which brough these .net framework dependencies.

The WinFX.Targets file was imported by csproj before upgrading and the importing was deleted by upgrading. It was necessary for the project so I added it back without modification, which caused the MSB3277 build warning.

Sign up to request clarification or add additional context in comments.

2 Comments

So you haven't find a solution either, do you? I switched to other projects so I don't know if the problem is still present in my project. I found someone telling that adding the tag <UseWPF>true</UseWPF> in the csproj file under the tag PropertyGroup solved the problem but I can't test it since I no longer have the original project.
@Ori my answer did resolve the MSB3277 build warnings in one of my projects. But later when I build other projects under the same solution I found more MSB3277 warnings which came with C1001 internal error and could not be fixed by this way. I assumes when upgrading from .net framework to .net 6, many factors would cause this warning, and the developer has to fix it according to the projects
1

This warning disappeared after I added a FrameworkReference to Microsoft.WindowsDesktop.App to the .vcxproj project file:

    <ItemGroup>
        <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
    </ItemGroup>

Comments

0

I had the same issue in a solution containing a shared Razor Class Library (RCL), which is referenced by two projects: 1) .NET MAUI Blazor App (for desktop); and 2) Blazor Server App (for web). In my case, I made the mistake of adding Microsoft.AspNetCore.Hosting directly to the RCL, which means I had to add Microsoft.AspNetCore.App as a framework (to the RCL).

Side note: Microsoft.AspNetCore.App should not be confused with Microsoft.NETCore.App. Razor Class Libraries do target the latter.

When I ran the web app, everything was fine because (as of the time of writing) Blazor Server Apps use Microsoft.AspNetCore.App as a framework (see in Visual Studio > Project > Dependencies > Frameworks). However, as I realized, the .NET MAUI Blazor App targets the frameworks net7.0-windows, net7.0-maccatalyst, etc.

I ended up creating an interface, which the RCL references, and registering framework-specific implementations in each app.

P.S., All of my projects target .NET 7.0.

Comments

0

To avoid such problems, we explicitly disable binding redirects in .NET Core, net6, etc:

<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>false</GenerateBindingRedirectsOutputType>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.