Skip to content

Commit

Permalink
Remove global:: from generated global usings (#44916)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz authored Nov 22, 2024
1 parent d58f584 commit d7fe6e6
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 73 deletions.
3 changes: 1 addition & 2 deletions src/Tasks/Microsoft.NET.Build.Tasks/GenerateGlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ protected override void ExecuteCore()
.Append(" = ");
}

lineBuilder.Append("global::")
.Append(@using.Namespace)
lineBuilder.Append(@using.Namespace)
.Append(';');

lines[index++] = lineBuilder.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ public void It_generates_blazorwasm_usings_and_builds_successfully()

File.ReadAllText(Path.Combine(outputDirectory.FullName, globalUsingsFileName)).Should().Be(
@"// <auto-generated/>
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Logging;
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Logging;
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Net.Http;
global using System.Threading;
global using System.Threading.Tasks;
");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public void It_can_generate_global_usings_and_builds_successfully()

File.ReadAllText(Path.Combine(outputDirectory.FullName, globalUsingsFileName)).Should().Be(
@"// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Net.Http;
global using System.Threading;
global using System.Threading.Tasks;
");
}

Expand Down Expand Up @@ -80,12 +80,12 @@ public void It_can_remove_specific_usings_in_project_file()

File.ReadAllText(Path.Combine(outputDirectory.FullName, globalUsingsFileName)).Should().Be(
@"// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Net.Http;
global using System.Threading;
global using System.Threading.Tasks;
");
}

Expand All @@ -103,6 +103,9 @@ public void It_can_generate_custom_usings()
<Using Include=""CustomNamespace"" />
<Using Include=""TestStaticNamespace"" Static=""True"" />
<Using Include=""System.Biology"" Alias=""AppliedChemistry"" />
<Using Include=""(System.String X, int Y)"" Alias=""MyTuple"" />
<Using Include=""dynamic"" Alias=""Any"" />
<Using Include=""int"" Alias=""Number"" />
</ItemGroup>"));
});

Expand All @@ -121,9 +124,12 @@ public void It_can_generate_custom_usings()

File.ReadAllText(Path.Combine(outputDirectory.FullName, globalUsingsFileName)).Should().Be(
@"// <auto-generated/>
global using global::CustomNamespace;
global using AppliedChemistry = global::System.Biology;
global using static global::TestStaticNamespace;
global using CustomNamespace;
global using Any = dynamic;
global using AppliedChemistry = System.Biology;
global using MyTuple = (System.String X, int Y);
global using Number = int;
global using static TestStaticNamespace;
");
}

Expand Down Expand Up @@ -164,11 +170,11 @@ public void It_considers_switches_when_deduping()

File.ReadAllText(Path.Combine(outputDirectory.FullName, globalUsingsFileName)).Should().Be(
@"// <auto-generated/>
global using global::CustomNamespace;
global using global::TestStaticNamespace;
global using Disk = global::System.IO.File;
global using FileIO = global::System.IO.File;
global using static global::TestStaticNamespace;
global using CustomNamespace;
global using TestStaticNamespace;
global using Disk = System.IO.File;
global using FileIO = System.IO.File;
global using static TestStaticNamespace;
");
}

Expand Down Expand Up @@ -202,13 +208,13 @@ public void It_can_persist_generatedfile_between_cleans()
outputDirectory.Should().HaveFile(globalUsingsFileName);
File.ReadAllText(Path.Combine(outputDirectory.FullName, globalUsingsFileName)).Should().Be(
@"// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Net.Http;
global using System.Threading;
global using System.Threading.Tasks;
");
}

Expand All @@ -234,12 +240,12 @@ public void It_not_generate_global_usings_for_system_net_http_when_multitarget()

File.ReadAllText(Path.Combine(outputDirectory.FullName, globalUsingsFileName)).Should().Be(
@"// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Threading;
global using System.Threading.Tasks;
");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ public void It_generates_web_implicit_usings_and_builds_successfully()

File.ReadAllText(Path.Combine(outputDirectory.FullName, globalUsingsFileName)).Should().Be(
@"// <auto-generated/>
global using global::Microsoft.AspNetCore.Builder;
global using global::Microsoft.AspNetCore.Hosting;
global using global::Microsoft.AspNetCore.Http;
global using global::Microsoft.AspNetCore.Routing;
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging;
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Net.Http.Json;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Hosting;
global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Routing;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Hosting;
global using Microsoft.Extensions.Logging;
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Net.Http;
global using System.Net.Http.Json;
global using System.Threading;
global using System.Threading.Tasks;
");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ public void It_generates_worker_implicit_usings_and_builds_successfully()

File.ReadAllText(Path.Combine(outputDirectory.FullName, globalUsingsFileName)).Should().Be(
@"// <auto-generated/>
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging;
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Hosting;
global using Microsoft.Extensions.Logging;
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Net.Http;
global using System.Threading;
global using System.Threading.Tasks;
");
}

Expand Down

0 comments on commit d7fe6e6

Please sign in to comment.