dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.07k stars 1.17k forks source link

Any WPF project lower than net461 with System.ValueTuple cannot be compiled #2320

Open walterlv opened 4 years ago

walterlv commented 4 years ago

If a WPF project uses Microsoft.NET.Sdk.WindowsDesktop as its Sdk, and targets lower than net461, then it can never be compiled when referencing System.ValueTuple.

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

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net46</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.ValueTuple" Version="4.5.0" />
  </ItemGroup>

</Project>

Necessary conditions:

  1. Sdk version 3.1
  2. use Microsoft.NET.Sdk.WindowsDesktop Sdk and UseWpf
  3. targeting net46/net452/net451/net45
  4. Package reference the System.ValueTuple

This issue is introduced in 3.1 and everything works fine in 3.0.

Actual behavior:

Error MC1000 Unkown build error “Could not find assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.” Walterlv.Demo.CannotCompileWithValueTuple C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets 225

Expected behavior:

The project should be compiled correctly.

Minimal repro:

  1. Create a new WPF project via the Visual Studio WPF App (.NET Core) template;
  2. Edit the csproj file to targeting net46 and reference System.ValueTuple;
  3. Compile this project.

You can view the minimal project here:

vatsan-madhavan commented 4 years ago

Probably a facet of https://github.com/dotnet/wpf/issues/2274; If I'm correct about it, this is being fixed by https://github.com/dotnet/runtime/issues/730 in an upcoming servicing release.

lindexi commented 4 years ago

How to fix?

Add the global.json file and add the code

{
    "sdk": 
    {
        "version": "3.0.102"
    }
}

Goto https://dotnet.microsoft.com/download/dotnet-core and download install the dotnet core 3.0.102

lindexi commented 4 years ago

@vatsan-madhavan I think this issues can be closed. @walterlv

weltkante commented 4 years ago

How to fix?

@lindexi you are downgrading not fixing the problem in 3.1 so this is just a workaround, if OP needs features from 3.1 this won't work for him, so it is not a general solution

walterlv commented 4 years ago

@lindexi @weltkante Just wait for the 3.1.2

vatsan-madhavan commented 4 years ago

Just wait for the 3.1.2

…which should be out in a week (assuming nothing happens to upset that schedule 😉 )

GeertvanHorrik commented 4 years ago

Note that this has not been fixed with 3.1.2. See #2274 for all the details.

lindexi commented 4 years ago

@GeertvanHorrik I find the 3.1.102 published.

GeertvanHorrik commented 4 years ago

I can confirm this has been fixed in 3.1.103, great work, thanks!

walterlv commented 4 years ago

Yes! This issue has been fixed since 3.1.103.

MatthewSteeples commented 4 years ago

This looks to have regressed with 3.1.400 (16.7 release)

walterlv commented 4 years ago

@MatthewSteeples Yes! This issue resurrects with 3.1.400 (16.7 release).

What makes worse is that the embedded .NET Core version is newer than the .NET Core download page version here so that we cannot uninstall it to fix this issue temporarily.

unable to uninstall

The global.json still works but this makes projects unable to be compiled (via CI) a few months later, just like what I meet after this issue first occurred last year.

Note: This update (3.1.400) introduces two issues to breaks my project compilation. This one and another https://github.com/dotnet/sdk/issues/12842 .

lindexi commented 4 years ago

Thank you @walterlv

It is break