I have project on .net 6.0.106, and when i build it, it gives me error:
BuildingPassport/HousePassport.Domain/obj/Debug/net6.0/HousePassport.Domain.GlobalUsings.g.cs(1,1): Error CS0116: A namespace cannot directly contain members such as fields or methods (CS0116) (HousePassport.Domain)
and when i go to this file, it gives me this:
// <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;
One of my collegue said, that on windows, it has on project options have tab General->Global Usings as in the image:
But i cannot found it in VS for mac, what's my problem?
I have Visual Studio for Mac Community(v8.10.25(build 2))
Here's details:
Visual Studio Community 2019 for Mac
Version 8.10.25 (build 2)
Installation UUID: 78cd4d01-f097-4a1a-9faf-b2ee9edbfae3
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)
Package version: 612000182
Mono Framework MDK
Runtime:
Mono 6.12.0.182 (2020-02/6051b710727) (64-bit)
Package version: 612000182
Roslyn (Language Service)
3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb
NuGet
Version: 5.9.0.7134
.NET SDK (x64)
SDK: /usr/local/share/dotnet/x64/sdk/6.0.106/Sdks
SDK Versions:
6.0.106
5.0.408
3.1.420
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks
.NET Core Runtime
Runtime: /usr/local/share/dotnet/x64/dotnet
Runtime Versions:
6.0.6
5.0.17
3.1.26
Operating System
Mac OS X 13.0.1
Darwin 22.1.0 Darwin Kernel Version 22.1.0
Sun Oct 9 20:14:30 PDT 2022
root:xnu-8792.41.9~2/RELEASE_ARM64_T8103 x86_64
here's additional .csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
The underlying problem is that global usings requires C# 10.0 and Visual Studio for Mac 8.10 (2019) uses Mono to build .NET SDK style projects, and Mono does not support C# 10.0.
> which csc
/Library/Frameworks/Mono.framework/Versions/Current/Commands/csc
> csc "/langversion:?"
Supported language versions:
default
1
2
3
4
5
6
7.0
7.1
7.2
7.3
8.0
9.0 (default)
latestmajor
preview
latest
Your options are:
This PackageReference allows C# 10.0 code to be compiled.
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.0.1" />
</ItemGroup>