Skip to content

Commit

Permalink
[dotnet] Add support for implicit namespace imports. Fixes #12084.
Browse files Browse the repository at this point in the history
Also update our templates to remove any using statements for implicitly imported
namespaces.

Fixes #12084.
  • Loading branch information
rolfbjarne committed Jul 22, 2021
1 parent b4c2185 commit 17ee4c7
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 27 deletions.
1 change: 1 addition & 0 deletions dotnet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $(1)_NUGET_TARGETS = \
$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/data/UnixFilePermissions.xml \
$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/Sdk/AutoImport.props \
$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/Sdk/Sdk.props \
$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/targets/Microsoft.$(1).Sdk.ImplicitNamespaceImports.props \
$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/targets/Microsoft.$(1).Sdk.SupportedTargetPlatforms.props \
$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/targets/Microsoft.$(1).Sdk.DefaultItems.props \
$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/targets/Microsoft.$(1).Sdk.props \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Foundation;
using UIKit;

namespace MacCatalystApp1 {
[Register ("AppDelegate")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using UIKit;

using MacCatalystApp1;

// This is the main entry point of the application.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Foundation;
using UIKit;

namespace MacCatalystApp1 {
[Register ("SceneDelegate")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Foundation;
using UIKit;

namespace iOSApp1 {
[Register ("Controller1")]
Expand Down
2 changes: 0 additions & 2 deletions dotnet/Templates/Microsoft.iOS.Templates/ios/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Foundation;
using UIKit;

namespace iOSApp1 {
[Register ("AppDelegate")]
Expand Down
2 changes: 0 additions & 2 deletions dotnet/Templates/Microsoft.iOS.Templates/ios/Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using UIKit;

using iOSApp1;

// This is the main entry point of the application.
Expand Down
2 changes: 0 additions & 2 deletions dotnet/Templates/Microsoft.iOS.Templates/ios/SceneDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Foundation;
using UIKit;

namespace iOSApp1 {
[Register ("SceneDelegate")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using AppKit;
using Foundation;

namespace macOSApp1 {
[Register ("AppDelegate")]
Expand Down
2 changes: 0 additions & 2 deletions dotnet/Templates/Microsoft.macOS.Templates/macos/Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using AppKit;

using macOSApp1;

// This is the main entry point of the application.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;

using AppKit;
using Foundation;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions dotnet/Templates/Microsoft.tvOS.Templates/tvos/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Foundation;
using UIKit;

namespace tvOSApp1 {
[Register ("AppDelegate")]
Expand Down
2 changes: 0 additions & 2 deletions dotnet/Templates/Microsoft.tvOS.Templates/tvos/Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using UIKit;

using tvOSApp1;

// This is the main entry point of the application.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using UIKit;

namespace tvOSApp1 {
public partial class ViewController : UIViewController {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains implicit namespace imports
*** WARNING ***
This file is imported by AutoImport.props, and will be imported by all
projects using Microsoft.NET.Sdk. All Item includes in this file *MUST*
be hidden behind a TargetPlatformIdentifier based condition.
This file can also not define any properties. However, due to the
order MSBuild evaluates properties, it's possible to use properties
defined in our .targets files in conditions in ItemGroups in this
file.
*** WARNING ***
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- There's a master switch, DisableImplicitNamespaceImports, which, if set, will prevent all implicit namespace imports - this is done automatically, we don't have to check DisableImplicitNamespaceImports here -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'MacCatalyst' And '$(DisableImplicitNamespaceImports_MacCatalyst)' != 'true'">
<Import Include="CoreGraphics" />
<Import Include="Foundation" />
<Import Include="UIKit" />
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions dotnet/targets/Microsoft.iOS.Sdk.ImplicitNamespaceImports.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains implicit namespace imports
*** WARNING ***
This file is imported by AutoImport.props, and will be imported by all
projects using Microsoft.NET.Sdk. All Item includes in this file *MUST*
be hidden behind a TargetPlatformIdentifier based condition.
This file can also not define any properties. However, due to the
order MSBuild evaluates properties, it's possible to use properties
defined in our .targets files in conditions in ItemGroups in this
file.
*** WARNING ***
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- There's a master switch, DisableImplicitNamespaceImports, which, if set, will prevent all implicit namespace imports - this is done automatically, we don't have to check DisableImplicitNamespaceImports here -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'iOS' And '$(DisableImplicitNamespaceImports_iOS)' != 'true'">
<Import Include="CoreGraphics" />
<Import Include="Foundation" />
<Import Include="UIKit" />
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions dotnet/targets/Microsoft.macOS.Sdk.ImplicitNamespaceImports.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains implicit namespace imports
*** WARNING ***
This file is imported by AutoImport.props, and will be imported by all
projects using Microsoft.NET.Sdk. All Item includes in this file *MUST*
be hidden behind a TargetPlatformIdentifier based condition.
This file can also not define any properties. However, due to the
order MSBuild evaluates properties, it's possible to use properties
defined in our .targets files in conditions in ItemGroups in this
file.
*** WARNING ***
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- There's a master switch, DisableImplicitNamespaceImports, which, if set, will prevent all implicit namespace imports - this is done automatically, we don't have to check DisableImplicitNamespaceImports here -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'macOS' And '$(DisableImplicitNamespaceImports_macOS)' != 'true'">
<Import Include="AppKit" />
<Import Include="CoreGraphics" />
<Import Include="Foundation" />
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions dotnet/targets/Microsoft.tvOS.Sdk.ImplicitNamespaceImports.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains implicit namespace imports
*** WARNING ***
This file is imported by AutoImport.props, and will be imported by all
projects using Microsoft.NET.Sdk. All Item includes in this file *MUST*
be hidden behind a TargetPlatformIdentifier based condition.
This file can also not define any properties. However, due to the
order MSBuild evaluates properties, it's possible to use properties
defined in our .targets files in conditions in ItemGroups in this
file.
*** WARNING ***
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- There's a master switch, DisableImplicitNamespaceImports, which, if set, will prevent all implicit namespace imports - this is done automatically, we don't have to check DisableImplicitNamespaceImports here -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'tvOS' And '$(DisableImplicitNamespaceImports_tvOS)' != 'true'">
<Import Include="CoreGraphics" />
<Import Include="Foundation" />
<Import Include="UIKit" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<!-- This contains the OS versions we support for target platform -->
<Import Project="Microsoft.$(_PlatformName).Sdk.SupportedTargetPlatforms.props" />

<!-- This contains support for implicit namespace imports -->
<Import Project="Microsoft.$(_PlatformName).Sdk.ImplicitNamespaceImports.props" />

<Import Project="Xamarin.Shared.Sdk.TargetFrameworkInference.props" />

<PropertyGroup>
Expand Down

0 comments on commit 17ee4c7

Please sign in to comment.