C
C#2y ago
ERR404

❔ 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
WhiteBlackGoose
Do you have another .cs file by any chance? in the same folder
Servator
Servator2y ago
Every project must have 1 only one entry point which is Main() method Looks like you have 1 more Main() method too
EvenEasy
EvenEasy2y ago
u can try string? username = Console.ReadLine();
ERR404
ERR404OP2y ago
I do
Pobiega
Pobiega2y ago
WhiteBlackGoose
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
ERR404
ERR404OP2y ago
So what should I do to fix it?
WhiteBlackGoose
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
<StartupObject>Projects.Homework</StartupObject>
<StartupObject>Projects.Homework</StartupObject>
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 all
ERR404
ERR404OP2y ago
What do you mean by separate projects? make more folders?
WhiteBlackGoose
no, more projects project is a folder with .csproj file to create a project, you type dotnet new console -n Homework5
Servator
Servator2y ago
Solutions contains Projects Projects contains .cs files (with folders or not) 1 Solution can contain more than 1 project
WhiteBlackGoose
eh, no need for solution here, just stay with projects
Servator
Servator2y ago
If he just send us ss to project explorer on left side(or right) it would be better actually
ERR404
ERR404OP2y ago
WhiteBlackGoose
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 accidentally
ERR404
ERR404OP2y ago
so hit enter on the command in the terminal and then I can copy paste what I have into that new file right?
WhiteBlackGoose
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)
ERR404
ERR404OP2y ago
WhiteBlackGoose
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)
ERR404
ERR404OP2y ago
so I need to do that for every new project correct?
ERR404
ERR404OP2y ago
ERR404
ERR404OP2y ago
where do I find the new file?
Pobiega
Pobiega2y ago
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
ERR404
ERR404OP2y ago
I found it in the file explorer and put it in the project file
Pobiega
Pobiega2y ago
make sure you move the files that were already in Projects to a subfolder then something like Homework1
WhiteBlackGoose
you did what what did you move where
Pobiega
Pobiega2y ago
this is bad.
WhiteBlackGoose
hol up there can you explain what you just did
Pobiega
Pobiega2y ago
I think he moved the new Homework2 folder into Projects
ERR404
ERR404OP2y ago
yes
WhiteBlackGoose
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 Projects
ERR404
ERR404OP2y ago
then how would I access it?
WhiteBlackGoose
will break now
Pobiega
Pobiega2y ago
whats why I said to move the old stuff to a subfolder.
WhiteBlackGoose
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
ERR404
ERR404OP2y ago
so I have the main folder Projects and the for every project I need to make a new folder in that folder?
WhiteBlackGoose
dotnet new creates a folder automatically just need to specify the name of a new project with -n Name
ERR404
ERR404OP2y ago
So is this how it should be?
Pobiega
Pobiega2y ago
yep
WhiteBlackGoose
Yes you got it
ERR404
ERR404OP2y ago
and every time I make a new project do cd.. and then dot net new -n and whatever I want to name it?
WhiteBlackGoose
you need to make sure your prompt says the path where you want a new project to be created
Pobiega
Pobiega2y ago
get to Projects as your current working directory however you do that then you dotnet new console -n Homework3 or whatever name you want
ERR404
ERR404OP2y ago
whenever 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
Pobiega
Pobiega2y ago
? opening a new terminal in VSCode by default opens the current open directory which is Projects here
ERR404
ERR404OP2y ago
This is what opens whenever I make a new terminal
ERR404
ERR404OP2y ago
then I just type dotnet new console -n yada yada?
WhiteBlackGoose
yes you can try and see you can then delete ofc
ERR404
ERR404OP2y ago
Thank you very much for the helkp
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server