geeko
geeko

Reputation: 2852

CS0246: The type or namespace name 'System' could not be found

I am using the dotnet 3.1 CLI with .NET Core 3.1 on my Mac to learn msbuild and create project files from scratch. I tried the walkthrough on Microsoft MSBuild documentation, but it failed with this error:

CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)

What am I doing wrong? How can I reference System namespace in my project?

program.cs

using System;

class HelloWorld {

    static void Main() {
#if DebugConfig
        Console.WriteLine("WE ARE IN THE DEBUG CONFIGURATION");
#endif

        Console.WriteLine("Hello, world!");
    }
}

project.csproj

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <Compile Include="program.cs" />
    </ItemGroup>

    <Target Name="Build">
        <Csc Sources="@(Compile)"/>
    </Target>
</Project>

CLI:

dotnet msbuild project.csproj -t:Build

Upvotes: 0

Views: 4483

Answers (1)

Pavel Anikhouski
Pavel Anikhouski

Reputation: 23238

Your project file looks outdated

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <Compile Include="program.cs" />
    </ItemGroup>

    <Target Name="Build">
        <Csc Sources="@(Compile)"/>
    </Target>
</Project>

For .NET Core development new SDK-style projects are used, something like that

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
      <OutputType>Exe</OutputType>
      <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
</Project>

Follow the MSDN tutorial how to build initial solution on Mac OS

Upvotes: 2

Related Questions