Closed
Description
The new implicit global usings feature added to the SDK in 6.0.100-preview.7 has caused a few issues in some important scenarios such that some changes will be made to mitigate them and generally improve its usability.
These changes are targeting 6.0.100-rc.1
Items:
- Rename the MSBuild property from
<DisableImplicitNamespaceImports>
to<ImplicitUsings>
- Note this is for C# only
- Visual Basic will continue to use the
<DisableImplicitNamespaceImports>
property for disabling implicit namespace imports
- Add the
<ImplicitUsings>
property to the schema file so it appears in statement completion - Change the defined conditions to only enable adding the implicit usings from the SDK when the
<ImplictUsings>
property is set to "true" or "enable"- The existing conditions based on TFM should be removed
- The only condition for adding the implicit usings as defined in the SDK will be the check that
<ImplicitUsings>
is equal to "true" or "enable"
- Rename the item type that specifies the global namespaces to emit to the generated .cs file from
<Import>
to<Using>
- Note this is for C# only
- Visual Basic will continue to use the
<Import>
item type for specifying namespaces to import
- Update schema for ImplicitUsings feature msbuild#6745
- Ensure the generated file is still emitted if any
<Using>
items are declared (even if<ImplicitUsings>
is false) - Ensure that implicit
<Import>
items for Visual Basic are not changed from what they were in .NET 5 - Update processing of
<Using>
items to support definingusing [alias]
andusing static [type]
as well asusing [namespace]
, e.g.:<Using Include="Microsoft.AspNetCore.Http.Results" Alias="Results" />
emitsglobal using Results = global::Microsoft.AspNetCore.Http.Results;
<Using Include="Microsoft.AspNetCore.Http.Results" Static="True" />
emitsglobal using static global::Microsoft.AspNetCore.Http.Results;
<Using Include="Microsoft.AspNetCore.Http" />
emitsglobal using global::Microsoft.AspNetCore.Http;
- Update the C# project templates to enable implicit usings for new .NET 6 projects, i.e. include
<ImplicitUsings>enable</ImplicitUsings>
in the.csproj
file- This will be tracked by issues in the relevant repos for each template
- Update web project templates to opt-in to ImplicitUsings feature aspnetcore#35131
- Update console & classlib project templates to opt-in to ImplicitUsings feature templating#3619
- Update C# templates with global usings winforms#5074
Example project file content after these changes:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Using Include="My.Awesome.Namespace" />
</ItemGroup>
</Project>