Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable implicit namespace imports #56046

Merged
merged 2 commits into from
Jul 21, 2021

Conversation

safern
Copy link
Member

@safern safern commented Jul 20, 2021

In preview7 SDK some namespace imports are defined by default. Most of our projects don't use implicit references as we are low in the stack and producing those references. This can cause issues when building with a preview7 SDK, i.e:

D:\repos\dotnet_runtime_3\artifacts\obj\System.IO.Pipelines\ref\net6.0-Debug\System.IO.Pipelines.ImplicitNamespaceImports.cs(5,29): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) [D:\repos\dotnet_runtime_3\src\libraries\System.IO.Pipelines\ref\System.IO.Pipelines.csproj]

This was introduced to the SDK last week. dotnet/sdk@8594395

cc: @dotnet/runtime-infrastructure

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@stephentoub
Copy link
Member

I'd convinced myself here:
#55828 (comment)
that libraries were ok. Your example proves otherwise. Do you know where my proof breaks down?

Directory.Build.props Outdated Show resolved Hide resolved
@safern
Copy link
Member Author

safern commented Jul 20, 2021

that libraries were ok. Your example proves otherwise. Do you know where my proof breaks down?

Interesting. Let me look at what's going on that it is not working.

@safern
Copy link
Member Author

safern commented Jul 20, 2021

Ah I see. In this case I'm hitting it in System.IO.Pipelines, which is an OOB. We only set DisableImplicitFrameworkReferences for inbox assemblies, for OOBs we set DisableImplicitAssemblyReferences. Which is our own custom thing, so that's why the SDK doesn't set the namespace imports to false:

<!-- DisableImplicitAssemblyReferences support. -->
<Target Name="RemoveFrameworkReferences"
BeforeTargets="_HandlePackageFileConflicts"
AfterTargets="ResolveTargetingPackAssets"
Condition="'$(DisableImplicitAssemblyReferences)' == 'true' and
'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<!-- Point MicrosoftNetCoreAppRefPackRefDir to the acquired targeting pack to use it later for AssemblySearchPaths resolution. -->
<PropertyGroup Condition="'$(UseLocalTargetingRuntimePack)' != 'true'">
<_NetCoreAppTargetFrameworkIdentifier Condition="$([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '5.0'))">netcoreapp</_NetCoreAppTargetFrameworkIdentifier>
<_NetCoreAppTargetFrameworkIdentifier Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0'))">net</_NetCoreAppTargetFrameworkIdentifier>
<MicrosoftNetCoreAppRefPackRefDir>%(ResolvedFrameworkReference.TargetingPackPath)\ref\$(_NetCoreAppTargetFrameworkIdentifier)$(TargetFrameworkVersion.TrimStart('v'))\</MicrosoftNetCoreAppRefPackRefDir>
</PropertyGroup>
<ItemGroup>
<Reference Remove="@(Reference)"
Condition="'%(Reference.FrameworkReferenceName)' == '$(LocalFrameworkOverrideName)'" />
</ItemGroup>
</Target>

So I believe the right fix is to move this to the location where we set all these settings for libraries and set it to false only for that scenario.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@safern safern merged commit b64df21 into dotnet:main Jul 21, 2021
@safern safern deleted the DisableImplicitNamespaceImports branch July 21, 2021 02:08
Copy link
Member

@ViktorHofer ViktorHofer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@ghost ghost locked as resolved and limited conversation to collaborators Aug 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants