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

.NET 6 Preview 7 breaks builds that set $(LangVersion) 8.0 #19050

Closed
jonathanpeppers opened this issue Jul 19, 2021 · 11 comments
Closed

.NET 6 Preview 7 breaks builds that set $(LangVersion) 8.0 #19050

jonathanpeppers opened this issue Jul 19, 2021 · 11 comments
Labels
Area-ImplicitUsings Area-NetSDK untriaged Request triage from a team member

Comments

@jonathanpeppers
Copy link
Member

Using 6.0.100-preview.7.21369.5, you can do:

dotnet new console
dotnet build -p:LangVersion=8.0 -bl

This fails with:

C:\src\globalusing\Program.cs(2,1): error CS8400: Feature 'top-level statements' is not available in C# 8.0. Please use language version 9.0 or greater. [C:\src\globalusing\globalusing.csproj]
C:\src\globalusing\obj\Debug\net6.0\globalusing.ImplicitNamespaceImports.cs(2,1): error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater. [C:\src\globalusing\globalusing.csproj]
C:\src\globalusing\obj\Debug\net6.0\globalusing.ImplicitNamespaceImports.cs(3,1): error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater. [C:\src\globalusing\globalusing.csproj]
C:\src\globalusing\obj\Debug\net6.0\globalusing.ImplicitNamespaceImports.cs(4,1): error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater. [C:\src\globalusing\globalusing.csproj]
C:\src\globalusing\obj\Debug\net6.0\globalusing.ImplicitNamespaceImports.cs(5,1): error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater. [C:\src\globalusing\globalusing.csproj]
C:\src\globalusing\obj\Debug\net6.0\globalusing.ImplicitNamespaceImports.cs(6,1): error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater. [C:\src\globalusing\globalusing.csproj]
C:\src\globalusing\obj\Debug\net6.0\globalusing.ImplicitNamespaceImports.cs(7,1): error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater. [C:\src\globalusing\globalusing.csproj]
C:\src\globalusing\obj\Debug\net6.0\globalusing.ImplicitNamespaceImports.cs(8,1): error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater. [C:\src\globalusing\globalusing.csproj]

Binlog: msbuild.zip

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Jul 19, 2021
@dotnet-issue-labeler
Copy link

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

@jonathanpeppers
Copy link
Member Author

The bigger issue here is the global using:

error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater.

Ignore the top-level statement error:

error CS8400: Feature 'top-level statements' is not available in C# 8.0.

I think we shouldn't add to @(Import) item group unless it is C# 10 or higher?

jonathanpeppers added a commit to jonathanpeppers/java.interop that referenced this issue Jul 19, 2021
Context: dotnet/sdk#19050

xamarin-android is hitting this build error with .NET 6 Preview 7:

    C:\src\xamarin-android\external\Java.Interop\src\Java.Interop\obj\Debug\net6.0\Java.Interop.ImplicitNamespaceImports.cs(2,1):
    error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater.
    [C:\src\xamarin-android\external\Java.Interop\src\Java.Interop\Java.Interop.csproj]

In fact, you can reproduce this by doing:

    dotnet new console
    dotnet build -p:LangVersion=8.0

It seems like `@(Import)` item group should not be present unless the
project is C# 10 or higher?

For now, we can set `$(DisableImplicitNamespaceImports)` to workaround
the issue.
jonathanpeppers added a commit to dotnet/java-interop that referenced this issue Jul 19, 2021
Context: dotnet/sdk#19050

xamarin-android is hitting this build error with .NET 6 Preview 7:

    C:\src\xamarin-android\external\Java.Interop\src\Java.Interop\obj\Debug\net6.0\Java.Interop.ImplicitNamespaceImports.cs(2,1):
    error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater.
    [C:\src\xamarin-android\external\Java.Interop\src\Java.Interop\Java.Interop.csproj]

In fact, you can reproduce this by doing:

    dotnet new console
    dotnet build -p:LangVersion=8.0

It seems like `@(Import)` item group should not be present unless the
project is C# 10 or higher?

For now, we can set `$(DisableImplicitNamespaceImports)` to workaround
the issue.
@davidfowl
Copy link
Member

You mean if the language version is explicitly set? Yes that's a good point @JunTaoLuo

@jonathanpeppers
Copy link
Member Author

Our example in dotnet/java-interop#859 was a netstandard2.0 library that is sometimes built with Mono/MSBuild. It explicitly set $(LangVersion) to 8.0 so it could opt into NRT.

@JunTaoLuo
Copy link
Contributor

I agree in principle. However, I want to highlight some nuances. LangVersion can be strings in additional to specific versions (e.g. preview, latest, latestMajor, etc) which can resolve to different C# version numbers. I don't think it's a good idea to duplicate the logic from Roslyn that deals with this resolution here in the SDK targets. Instead, it would be best if Roslyn can package that logic in a task that we can consume here.

Tactically, I think the most we could do is check if the version is a number version and if it is, disable this feature if it's below 10.0. Thoughts?

@davidfowl
Copy link
Member

cc @jaredpar thoughts?

@jaredpar
Copy link
Member

My thoughts here are that the customer has willingly downgraded one aspect of the project here (the language version). It is reasonable that they may need to downgrade other parts of the project here to compensate (implicit global usings)

Our general focus is that we default all of our experiences, including language version, based on the selected target framework. It's a very simple model for us to all follow. Particularly because all of our experiences have on "off" switch. That means the default experience is as vibrant as we want and customers have the knobs to disable experiences they don't want or aren't compatible with other knobs.

@jonathanpeppers
Copy link
Member Author

jonathanpeppers commented Jul 22, 2021

I think it's quite reasonable to check $(LangVersion) here if it prevents breaks when updating to .NET 6.

When this change flowed to dotnet/maui we're seeing similar failures due to lots of LangVersion=9.0:

https:/dotnet/maui/search?q=LangVersion

I don't actually know why they are there -- I just saw the break.

Tactically, I think the most we could do is check if the version is a number version and if it is, disable this feature if it's below 10.0. Thoughts?

@JunTaoLuo if $(LangVersion) is latest or default, I think everything in my example above works. So only an explicit version has an issue.

Redth added a commit to dotnet/maui that referenced this issue Jul 22, 2021
Redth added a commit to dotnet/maui that referenced this issue Jul 22, 2021
Redth added a commit to dotnet/maui that referenced this issue Jul 22, 2021
* Update dependencies from https:/xamarin/xamarin-android build 6.0.1xx-preview7-8ca289588b6969a2cc878afa0813afec8cd63dd3-1

Microsoft.Android.Sdk.Windows
 From Version 30.0.100-preview.7.91 -> To Version 30.0.100-preview.7.93

Dependency coherency updates

Microsoft.NETCore.App.Ref,Microsoft.Dotnet.Sdk.Internal,Microsoft.Extensions.Primitives,Microsoft.AspNetCore.App.Runtime.win-x64,Microsoft.Extensions.Hosting.Abstractions,Microsoft.Extensions.DependencyInjection.Abstractions,Microsoft.Extensions.DependencyInjection,Microsoft.Extensions.Configuration.Abstractions,Microsoft.Extensions.Configuration,Microsoft.Extensions.Logging.Abstractions,Microsoft.Extensions.Logging,Microsoft.Extensions.Logging.Console,Microsoft.Extensions.Logging.Debug,Microsoft.Extensions.FileProviders.Abstractions,Microsoft.Extensions.FileProviders.Embedded,Microsoft.AspNetCore.Authorization,Microsoft.AspNetCore.Components.WebView,Microsoft.AspNetCore.Components.Web,Microsoft.JSInterop,Microsoft.WindowsDesktop.App.Runtime.win-x64,System.CodeDom
 From Version 6.0.0-preview.7.21326.8 -> To Version 6.0.0-preview.7.21368.2 (parent: Microsoft.Dotnet.Sdk.Internal

* [build] remove workaround for iOS AOT packages on Windows

* Ignore NU1703 in DeviceTests

NU1703 warns about using nuget packages which have xamarin.ios tfm references from a newer net6.0-maccatalyst project.

* Workaround error for implicit imports

Context: dotnet/sdk#19050
and dotnet/java-interop@4fb7c14

* Ignore NU1703 for Mac Catalyst projects

* Revert "Ignore NU1703 in DeviceTests"

This reverts commit 8fdf5e1.

* Revert "Revert "Ignore NU1703 in DeviceTests""

This reverts commit 4d0456d.

* Fix other C# 10-related errors

* Use `LangVersion=latest` by default
* Fixed new NRT-related errors that appeared from C# 10.0

* Disable StaticWebAssets in MauiRazorClassLibrarySample

Workaround to get the build to work. Will revert later to investigate.

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Peppers <[email protected]>
Co-authored-by: Jonathan Dick <[email protected]>
Co-authored-by: Eilon Lipton <[email protected]>
pjcollins pushed a commit to dotnet/maui that referenced this issue Jul 23, 2021
* Update dependencies from https:/xamarin/xamarin-android build 6.0.1xx-preview7-8ca289588b6969a2cc878afa0813afec8cd63dd3-1

Microsoft.Android.Sdk.Windows
 From Version 30.0.100-preview.7.91 -> To Version 30.0.100-preview.7.93

Dependency coherency updates

Microsoft.NETCore.App.Ref,Microsoft.Dotnet.Sdk.Internal,Microsoft.Extensions.Primitives,Microsoft.AspNetCore.App.Runtime.win-x64,Microsoft.Extensions.Hosting.Abstractions,Microsoft.Extensions.DependencyInjection.Abstractions,Microsoft.Extensions.DependencyInjection,Microsoft.Extensions.Configuration.Abstractions,Microsoft.Extensions.Configuration,Microsoft.Extensions.Logging.Abstractions,Microsoft.Extensions.Logging,Microsoft.Extensions.Logging.Console,Microsoft.Extensions.Logging.Debug,Microsoft.Extensions.FileProviders.Abstractions,Microsoft.Extensions.FileProviders.Embedded,Microsoft.AspNetCore.Authorization,Microsoft.AspNetCore.Components.WebView,Microsoft.AspNetCore.Components.Web,Microsoft.JSInterop,Microsoft.WindowsDesktop.App.Runtime.win-x64,System.CodeDom
 From Version 6.0.0-preview.7.21326.8 -> To Version 6.0.0-preview.7.21368.2 (parent: Microsoft.Dotnet.Sdk.Internal

* [build] remove workaround for iOS AOT packages on Windows

* Ignore NU1703 in DeviceTests

NU1703 warns about using nuget packages which have xamarin.ios tfm references from a newer net6.0-maccatalyst project.

* Workaround error for implicit imports

Context: dotnet/sdk#19050
and dotnet/java-interop@4fb7c14

* Ignore NU1703 for Mac Catalyst projects

* Revert "Ignore NU1703 in DeviceTests"

This reverts commit 8fdf5e1.

* Revert "Revert "Ignore NU1703 in DeviceTests""

This reverts commit 4d0456d.

* Fix other C# 10-related errors

* Use `LangVersion=latest` by default
* Fixed new NRT-related errors that appeared from C# 10.0

* Disable StaticWebAssets in MauiRazorClassLibrarySample

Workaround to get the build to work. Will revert later to investigate.

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Peppers <[email protected]>
Co-authored-by: Jonathan Dick <[email protected]>
Co-authored-by: Eilon Lipton <[email protected]>
@mattleibow
Copy link
Member

There is also a discussion here: #18825

@dotMorten
Copy link

I hit this today too. It's seems rather silly to turn on a feature that isn't supported.

@jonathanpeppers
Copy link
Member Author

I think we can close this in favor of #19521, this feature is being redesigned.

The idea is you will have to opt into it with ImplicitUsings=true, so we wouldn't have hit an issue if that was the case.

jonpryor pushed a commit to dotnet/java-interop that referenced this issue Aug 25, 2021
Context: dotnet/sdk#19050

xamarin-android is hitting this build error with .NET 6 Preview 7:

    C:\src\xamarin-android\external\Java.Interop\src\Java.Interop\obj\Debug\net6.0\Java.Interop.ImplicitNamespaceImports.cs(2,1):
    error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater.
    [C:\src\xamarin-android\external\Java.Interop\src\Java.Interop\Java.Interop.csproj]

In fact, you can reproduce this by doing:

    dotnet new console
    dotnet build -p:LangVersion=8.0

It seems like `@(Import)` item group should not be present unless the
project is C# 10 or higher?

For now, we can set `$(DisableImplicitNamespaceImports)` to workaround
the issue.
jpobst pushed a commit to dotnet/java-interop that referenced this issue Sep 30, 2021
Context: dotnet/sdk#19050

xamarin-android is hitting this build error with .NET 6 Preview 7:

    C:\src\xamarin-android\external\Java.Interop\src\Java.Interop\obj\Debug\net6.0\Java.Interop.ImplicitNamespaceImports.cs(2,1):
    error CS8400: Feature 'global using directive' is not available in C# 8.0. Please use language version 10.0 or greater.
    [C:\src\xamarin-android\external\Java.Interop\src\Java.Interop\Java.Interop.csproj]

In fact, you can reproduce this by doing:

    dotnet new console
    dotnet build -p:LangVersion=8.0

It seems like `@(Import)` item group should not be present unless the
project is C# 10 or higher?

For now, we can set `$(DisableImplicitNamespaceImports)` to workaround
the issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-ImplicitUsings Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

8 participants