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.23k stars 1.35k forks source link

Alias any type is not working with named tuples #10982

Open SeanFeldman opened 1 day ago

SeanFeldman commented 1 day ago

Issue Description

With C# 12, it's possible to alias any type. A project that has ImplicitUsings, it works using GlobalUsings.cs. Switching from GlobalUsings.cs to Directory.Build.props breaks compilation.

I've run into a situation where a named tuple alias with a nullable doesn't work, but a collection with elements of an identical named tuple does.

Steps to Reproduce

// GlobalUsings.cs
global using NamedTuple = (bool isUsed, string value);
global using NamedTupleList = System.Collections.Generic.List<(bool isUsed, string value)>;

// Anywhere in the project
NamedTuple nt;      // compiles
NamedTupleList ntl; // compiles

When attempting to use these aliases in all projects under solution using .csproj's Using element, NamedTuple doesn't work while NamedTupleList works.

The repro (link) is attempting to achieve this by defining the aliases in the Directory.Build.props file instead of GlobalUsing.cs in the following way.

<Project>
    <ItemGroup>
        <Using Include="(bool isUsed, string value)" Alias="NamedTuple" />
        <Using Include="System.Collections.Generic.List&lt;(bool isUsed, string value)&gt;" Alias="NamedTupleList" />
    </ItemGroup>
</Project>

With this change, the code fails.

// Anywhere in the project
NamedTuple nt;      // compiles
NamedTupleList ntl; // fails

Expected Behavior

NamedTuple and NamedTupleList types should be available and compilable.

Actual Behavior

NamedTupleList isn't available/compilable.

Analysis

No response

Versions & Configurations

MSBuild version 17.10.4+10fbfbf2e .NET 8.0.300 OS Windows 10 Pro 22H2

KalleOlaviNiemitalo commented 1 day ago

Duplicate of https://github.com/dotnet/sdk/issues/42479.