Runtime: Can't seem to build a simple .NET Core 2.0 Hello World Project via CLI

Created on 9 Sep 2017  路  7Comments  路  Source: dotnet/runtime

Hi all,

Having an issue during what I think should be a simple scenario -- a domain class lib and a console app that references it, where the domain project does nothing and the console app is the standard Hello World.

NOTE: I previously had .NET Core 1.x on my system, but I uninstalled it as part of trying to troubleshoot this issue.

Components Involved

  • Windows 10
  • .NET Core 2.0
  • VS Code 64-bit -- latest update
  • I also tried to get the proj to build on VS 2017. Didn't work there either as far as I can tell.

Code Sample of Repro

Code sample that repros the issue on my system can be found at https://github.com/SeanKilleen/corefx-23906-issuerepro.

Reproduction Steps (have done this multiple times on my system)

  • Within the VS Code terminal, I open a command prompt and navigate to a temp directory
  • I run dotnet new solution -o PingPong. This creates new empty solution in the PingPong directory
  • I cd into the PingPong directory.
  • Run dotnet new console -o PingPong.Console which creates a folder and the console app
  • Run dotnet new console -o PingPong.Domain which creates a folder and the class lib project
  • Add the projects to the solution using dotnet sln PingPong.sln add PingPong.Console\PingPong.Console.csproj and dotnet sln PingPong.sln add PingPong.Domain\PingPong.Domain.csproj
  • Reference the domain project from the console project via dotnet add PingPong.Console\PingPong.Console.csproj reference PingPong.Domain\PingPong.Domain.csproj
  • Run dotnet restore PingPong.sln to update the packages
  • Run dotnet build PingPong.sln to build the solution

Here I hit my first snag, an error: Program.cs(9,13): error CS0234: The type or namespace name 'WriteLine' does not exist in the namespace 'PingPong.Console' (are you missing an assembly reference?)

Command Prompt repro

To show the steps I'm taking in case something is crucially wrong:

Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\Users\Sean\Desktop\temp\issuerepro> dotnet new solution -o PingPong
The template "Solution File" was created successfully.
PS C:\Users\Sean\Desktop\temp\issuerepro> cd .\PingPong\
PS C:\Users\Sean\Desktop\temp\issuerepro\PingPong> dotnet new console -o PingPong.Console
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on PingPong.Console\PingPong.Console.csproj...
  Restoring packages for C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Console\PingPong.Console.csproj...
  Generating MSBuild file C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Console\obj\PingPong.Console.csproj.nuget.g.props.
  Generating MSBuild file C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Console\obj\PingPong.Console.csproj.nuget.g.targets.
  Restore completed in 260.07 ms for C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Console\PingPong.Console.csproj.


Restore succeeded.

PS C:\Users\Sean\Desktop\temp\issuerepro\PingPong> dotnet new console -o PingPong.Domain
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on PingPong.Domain\PingPong.Domain.csproj...
  Restoring packages for C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Domain\PingPong.Domain.csproj...
  Generating MSBuild file C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Domain\obj\PingPong.Domain.csproj.nuget.g.props.
  Generating MSBuild file C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Domain\obj\PingPong.Domain.csproj.nuget.g.targets.
  Restore completed in 200.18 ms for C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Domain\PingPong.Domain.csproj.


Restore succeeded.

PS C:\Users\Sean\Desktop\temp\issuerepro\PingPong> dotnet sln PingPong.sln add PingPong.Console\PingPong.Console.csproj
Project `PingPong.Console\PingPong.Console.csproj` added to the solution.
PS C:\Users\Sean\Desktop\temp\issuerepro\PingPong> dotnet sln PingPong.sln add PingPong.Domain\PingPong.Domain.csproj
Project `PingPong.Domain\PingPong.Domain.csproj` added to the solution.
PS C:\Users\Sean\Desktop\temp\issuerepro\PingPong> dotnet add PingPong.Console\PingPong.Console.csproj reference PingPong.Domain\PingPong.Domain.csproj
Reference `..\PingPong.Domain\PingPong.Domain.csproj` added to the project.
PS C:\Users\Sean\Desktop\temp\issuerepro\PingPong> dotnet restore PingPong.sln
  Restoring packages for C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Console\PingPong.Console.csproj...
  Restore completed in 16.47 ms for C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Domain\PingPong.Domain.csproj.
  Restore completed in 170.16 ms for C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Console\PingPong.Console.csproj.
PS C:\Users\Sean\Desktop\temp\issuerepro\PingPong> dotnet build PingPong.sln
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  PingPong.Domain -> C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Domain\bin\Debug\netcoreapp2.0\PingPong.Domain.dll
Program.cs(9,13): error CS0234: The type or namespace name 'WriteLine' does not exist in the namespace 'PingPong.Console' (are you missing an assembly r
eference?) [C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Console\PingPong.Console.csproj]

Build FAILED.

Program.cs(9,13): error CS0234: The type or namespace name 'WriteLine' does not exist in the namespace 'PingPong.Console' (are you missing an assembly r
eference?) [C:\Users\Sean\Desktop\temp\issuerepro\PingPong\PingPong.Console\PingPong.Console.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:04.51
PS C:\Users\Sean\Desktop\temp\issuerepro\PingPong>

Most helpful comment

Can't see repo, so guess:

Namespace PingPong.Console is taking precedence over System so it can't find the class Console?

All 7 comments

Can't see repo, so guess:

Namespace PingPong.Console is taking precedence over System so it can't find the class Console?

Gahhhhh that was it! Simple fix. Always nice when the hour I lost on new tooling is actually something dumb and obvious. 馃槅 Thanks for the pointer!

Argh, glad this is here! Ran into the same issue.

Face plant! Ran into same issue.

I have now done this twice and found this issue twice... 馃槅

I'm new to this stuff but if I create a Console app in Visual studio i get:
using System;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

Which compiles happily. So what's the difference when using Command prompt?

@Elracorey if you are having an issue still, please open a new issue with repro steps.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omajid picture omajid  路  3Comments

btecu picture btecu  路  3Comments

jamesqo picture jamesqo  路  3Comments

Timovzl picture Timovzl  路  3Comments

bencz picture bencz  路  3Comments