❔ I am learning and I do not know what is wrong
I am following a brackeys tutorial and have only changed the text to be written.
50 Replies
Do you have another .cs file by any chance?
in the same folder
Every project must have 1 only one entry point which is Main() method
Looks like you have 1 more Main() method too
u can try
string? username = Console.ReadLine();
I do
that's the thing
when you run a project in C#, you don't run a .cs file
you run the whole thing
and the whole thing discovers all your .cs files
and then it finds all Main() methods in your .cs files
and tries to run them
but beacuse you have more than one
it doesn't know which one to run
So what should I do to fix it?
There are a few options
one sec
hmmm
yeah so you have three options
1. You can create separate projects for each homework. (recommended)
2. You can specify the Main method that needs to be run. To do it, add
in your .csproj file. Make sure to specify the class and the namespace. E. g. if you decide to create another file and create class
Homework3
, you will need to replace that line with Projects.Homework3
3. You can use interactive environments, like VSC Notebooks, to play around C#. Then you don't need to create any projects at allWhat do you mean by separate projects? make more folders?
no, more projects
project is a folder with
.csproj
file
to create a project, you type dotnet new console -n Homework5
Solutions contains Projects
Projects contains .cs files (with folders or not)
1 Solution can contain more than 1 project
eh, no need for solution here, just stay with projects
If he just send us ss to project explorer on left side(or right) it would be better actually
assuming it's VSC, there's no project explorer 😄
see, you have Projects.csproj
it's one project
you need another one
oh I see you're typing
you need to get one level up
cd ..
or create projects however you wish, just make sure not to nest them accidentallyso hit enter on the command in the terminal and then I can copy paste what I have into that new file right?
yes, but if you're in the same folder right now where your csproj is, then you will mess up things
can you run "dir" where you are right now
and show the output
(since you're on VSC, I highly recommend learning some basics of terminal and dotnet CLI)
yeah
give me a sec
okay we need to clear up here a bit
actually it's fine
so do
cd ..
so that your prompt says "D:\Microsoft VS Code>"
and run the command dotnet new console -n Homework2
there
then there will be a folder D:\Microsoft VS Code\Homework2
containing your second homework
if you want to keep them all in Projects
folder, you need to create Homework1 folder in Projects and move all stuff there
(feel free to use graphical software like Explorer for manipulating with files if you don't feel comfortable with terminal)so I need to do that for every new project correct?
where do I find the new file?
in your "Homework2" folder
your previous project was inside the "Projects" folder, but not within a subfolder
you might want to move stuff around a bit
I found it in the file explorer and put it in the project file
make sure you move the files that were already in
Projects
to a subfolder then
something like Homework1
you did what
what did you move where
this is bad.
hol up there
can you explain what you just did
I think he moved the new
Homework2
folder into Projects
yes
that's exactly the opposite of what should be done
we did
cd ..
to avoid it
basically here's a problem
your new project will work fine
but your old project
called Projectsthen how would I access it?
will break now
whats why I said to move the old stuff to a subfolder.
you can keep it one level up OR
you need to move your HomeWork 1.cs and HomeWork 2.cs and Projects.csproj into Homework1 folder
like pobiega suggested
so I have the main folder Projects and the for every project I need to make a new folder in that folder?
dotnet new
creates a folder automatically
just need to specify the name of a new project with -n Name
So is this how it should be?
yep
Yes
you got it
and every time I make a new project do cd.. and then dot net new -n and whatever I want to name it?
you need to make sure your prompt says the path where you want a new project to be created
get to
Projects
as your current working directory however you do that
then you dotnet new console -n Homework3
or whatever name you wantwhenever I make a terminal it brings me to make a folder in project
I understand what I did wrong and how to not do it now
?
opening a new terminal in VSCode by default opens the current open directory
which is Projects here
This is what opens whenever I make a new terminal
then I just type dotnet new console -n yada yada?
yes
you can try and see
you can then delete ofc
Thank you very much for the helkp
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.