C
C#9mo ago
Nicoder

✅ Having trouble compiling a C# 11 file (not mine) on Mac

Using mcs throws a whole bunch of compiler errors since it doesn't support C# 11 syntax yet.
error CS1525: Unexpected symbol `)', expecting `(' or `type'
error CS1010: Newline in constant
error CS1525: Unexpected symbol `-'
error CS1525: Unexpected symbol `-'
error CS1012: Too many characters in character literal
error CS1525: Unexpected symbol `-'
error CS1525: Unexpected symbol `Multiple'
error CS1010: Newline in constant
error CS1001: Unexpected symbol `.', expecting identifier
error CS1001: Unexpected symbol `]', expecting identifier
error CS1525: Unexpected symbol `?'
error CS1525: Unexpected symbol `:', expecting `,' or `;'
error CS1525: Unexpected symbol `//', expecting `,' or `;'
error CS1525: Unexpected symbol `?'
error CS1525: Unexpected symbol `:', expecting `,' or `;'
error CS1525: Unexpected symbol `//', expecting `,' or `;'
error CS1525: Unexpected symbol `)', expecting `(' or `type'
error CS1525: Unexpected symbol `)', expecting `(' or `type'
error CS1010: Newline in constant
error CS1525: Unexpected symbol `-'
error CS1525: Unexpected symbol `-'
error CS1012: Too many characters in character literal
error CS1525: Unexpected symbol `-'
error CS1525: Unexpected symbol `Multiple'
error CS1010: Newline in constant
error CS1001: Unexpected symbol `.', expecting identifier
error CS1001: Unexpected symbol `]', expecting identifier
error CS1525: Unexpected symbol `?'
error CS1525: Unexpected symbol `:', expecting `,' or `;'
error CS1525: Unexpected symbol `//', expecting `,' or `;'
error CS1525: Unexpected symbol `?'
error CS1525: Unexpected symbol `:', expecting `,' or `;'
error CS1525: Unexpected symbol `//', expecting `,' or `;'
error CS1525: Unexpected symbol `)', expecting `(' or `type'
Using dotnet build results in this error:
getcwd() failed: Operation not permitted
MSBuild version 17.9.6+a4ecab324 for .NET
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
System.UnauthorizedAccessException: Access to the path is denied.
---> System.IO.IOException: Operation not permitted
getcwd() failed: Operation not permitted
MSBuild version 17.9.6+a4ecab324 for .NET
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
System.UnauthorizedAccessException: Access to the path is denied.
---> System.IO.IOException: Operation not permitted
39 Replies
333fred
333fred9mo ago
MCS will never support C# 7, let alone C# 11
Nicoder
NicoderOP9mo ago
Then what do I do
333fred
333fred9mo ago
You figure out what you've configured wrong with modern .NET
Nicoder
NicoderOP9mo ago
I don't even know how to configure .NET I have no idea what I'm doing I just want to run someone else's code
333fred
333fred9mo ago
Well, what you've said so far isn't really enough to help you. Presumably you're on either mac or linux, since you tried to use mcs, but how did you install .NET? How did you get this person's code? How are you trying to build it?
Nicoder
NicoderOP9mo ago
I'm on mac as I said in the title Specifically a 2020 Mac M1 running Ventura 13.2.1
Nicoder
NicoderOP9mo ago
Microsoft
Download .NET 8.0 (Linux, macOS, and Windows)
.NET 8.0 downloads for Linux, macOS, and Windows. .NET is a free, cross-platform, open-source developer platform for building many different types of applications.
Nicoder
NicoderOP9mo ago
I got the person's code from GitHub I am trying to build it using dotnet build
333fred
333fred9mo ago
What github?
Nicoder
NicoderOP9mo ago
Do I need to share the exact repo?
333fred
333fred9mo ago
I mean, that would be the fastest way for someone to help you...
Nicoder
NicoderOP9mo ago
Even if I change the Program.cs file to just Console.WriteLine("Hello World");, the same issue persists That means it has nothing to do with the code, and therefore there is no point in sharing the code
333fred
333fred9mo ago
Unless it has something to do with the project file 🙂
Nicoder
NicoderOP9mo ago
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
333fred
333fred9mo ago
Go into another directory entirely. Run dotnet new console --name Test && cd Test && dotnet run Not a nested directory, to be clear; somewhere completely separate I would probably just do it from ~
Nicoder
NicoderOP9mo ago
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /Users/[my IRL name here]/Test/Test.csproj:
Determining projects to restore...
Restored /Users/[my IRL name here]/Test/Test.csproj (in 160 ms).
Restore succeeded.
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /Users/[my IRL name here]/Test/Test.csproj:
Determining projects to restore...
Restored /Users/[my IRL name here]/Test/Test.csproj (in 160 ms).
Restore succeeded.
333fred
333fred9mo ago
Did run work too?
Nicoder
NicoderOP9mo ago
Yes
333fred
333fred9mo ago
Alright. Then my best guess is that you ran something as sudo in the other project, and permissions are messed up in various locations
Nicoder
NicoderOP9mo ago
Hold on dotnet new console --name Test && cd Test && dotnet build && dotnet run still results in Hello World even if I change the code of Program.cs
333fred
333fred9mo ago
Of what Program.cs? Because frankly, what you're describing there is far easier to attribute to you doing something wrong than the laws of the universe having broken 🙂
Nicoder
NicoderOP9mo ago
Obviously I'm doing something wrong I just don't know what That's why I asked for help
333fred
333fred9mo ago
.
Nicoder
NicoderOP9mo ago
The one in my current dir Wait, the console command doesn't copy over the same files to another dir, it just creates default ones?
333fred
333fred9mo ago
Yes, that creates a new project from the standard template. That's why I asked which Program.cs 😄 My goal with that command was to troubleshoot your base install of dotnet
Nicoder
NicoderOP9mo ago
Oh ok
333fred
333fred9mo ago
It succeeded, so we know that at least the minimal example works And any access denied errors are likely specific to the project files that you've cloned: either one of the scripts you ran when trying to build it ran something as sudo and messed up the directory, or the files have some weird permissions checked into the repo
Nicoder
NicoderOP9mo ago
Would a chmod 777 fix all the permissions?
333fred
333fred9mo ago
I would guess not. sudo is the more likely thing And it may be that something under ~/.nuget is also owned by the wrong thing now too because of it I'm going to bed now. Good luck figuring it out
Mayor McCheese
Mayor McCheese9mo ago
Honestly it's way easier to brew .net for future reference
Nicoder
NicoderOP9mo ago
Ok
Lex Li
Lex Li9mo ago
However, installation from homebrew is not considered officially supported I think, as you need to follow a Microsoft Learn article 👀
Mayor McCheese
Mayor McCheese9mo ago
I suppose, maybe MS should create homebrew package.
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
jcotton42
jcotton429mo ago
Homebrew just uses the official package iirc
Lex Li
Lex Li9mo ago
Then maybe find a way to update the official doc to include that 😅
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Mayor McCheese
Mayor McCheese9mo ago
I mean it's the cask or formula or whatever is maintained by someone other than MS even though it uses the official package.
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server