2

I'm just learning C# so I don't know if I'm just messing up the setup or what, but I used dotnet to create a new project where I'm keeping ALL of my little test scripts. I'm using VS Code as my editor. I create a path variable for csc to compile.

I can compile a Hello World project no problem, but I'm working through this course online and the next part was to make a simple gradebook.

I have GradeMain.cs

namespace Grades
{
    public class GradesMain 
    {
        static void Main (string[] args) 
        {
            GradeBook book = new GradeBook();
            book.AddGrade(91);
        }
    }
}

And GradeBook.cs

using System.Collections.Generic;

namespace Grades
{
    public class GradeBook
    {        
        public void AddGrade (float grade) 
        {
            grades.Add(grade);
        }

        List<float> grades = new List<float>(); 
    }    
}

When I try to compile using csc I get the following error

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

My intellisense shows that my GradeBook has two references from GradeMain. I saw this post Referenced Project gets "lost" at Compile Time but since I'm not using visual studio I wasn't sure if it was related / how to check my dotnet client profile.

maccettura
  • 10,514
  • 3
  • 28
  • 35
Peter Nguyen
  • 129
  • 2
  • 7
  • 1
    What command are you running? – SLaks Apr 09 '18 at 15:59
  • You didn´t provide the code where `Grades` is used. – MakePeaceGreatAgain Apr 09 '18 at 16:04
  • You need either the code of a class "Grades" in your project. Or a compiled .NET/CLI dll/exe with the class as part. Wich is added as a project reference. I asume in this case you are supposed to do the former. – Christopher Apr 09 '18 at 16:05
  • @SLaks I'm running csc GradesMain.cs – Peter Nguyen Apr 09 '18 at 16:16
  • @HimBromBeere it's being used in GradesMain.cs. – Peter Nguyen Apr 09 '18 at 16:21
  • @Christopher yeah when I keep it in one class, it's fine. Sorry I don't understand what "Or a compiled .NET/CLI dll/exe with the class as part. Wich is added as a project reference" Could you pass a link along that I could read? Or a search term? The guide that I'm going through is using Visual Studio Community not code, but I don't really want to install the whole IDE. But I would like to understand how I can use multiple script files in a single project – Peter Nguyen Apr 09 '18 at 16:22
  • 1
    If you're using Visual Studio Community, you should build your project in Visual Studio (under the Build menu). Using csc from the command-line requires a lot of arguments and isn't normally something you would do. – NextInLine Apr 09 '18 at 16:30
  • You should compile both files together in one command. – SLaks Apr 09 '18 at 16:34
  • @SLaks that works! Thanks so much! – Peter Nguyen Apr 09 '18 at 16:38

1 Answers1

0

For me what worked is what @SLaks suggested which was to compile both files with csc.

So runing csc GradesMain.cs GradeBook.cs worked perfectly.

Peter Nguyen
  • 129
  • 2
  • 7