C
C#2y ago
razkanaz

✅ Main() bug with 2 files

so basically, i this this folder, and it has a lot of different cs files each one individual from the last, and i'm noticing that once i have a Main() method in one file, i can't make one in the other, i get an error, how do i fix this?
50 Replies
sibber
sibber2y ago
you dont you cant have more than one main method how would that work
razkanaz
razkanazOP2y ago
no uhh it's 2 different files one file has a main method another file has one it's 2 seperate projects
sibber
sibber2y ago
yeah how would that work
razkanaz
razkanazOP2y ago
wdym?
sibber
sibber2y ago
oh i only see one project file tho and you cant nest projects afaik at least
razkanaz
razkanazOP2y ago
it's the "hex-code-checkers" wdym? it works if they're in the same folder
sibber
sibber2y ago
where is the other project file
razkanaz
razkanazOP2y ago
.
sibber
sibber2y ago
thats a code file project files end in .csproj
razkanaz
razkanazOP2y ago
no i mean
sibber
sibber2y ago
you cant have multiple entrance points in one project
razkanaz
razkanazOP2y ago
it's a different project, not a different project file oh so i have to make a different csproj for every file?
sibber
sibber2y ago
because how would it pick which one to run
razkanaz
razkanazOP2y ago
pick the file and f5
sibber
sibber2y ago
different project means different csproj c# doesnt run files
razkanaz
razkanazOP2y ago
that's weird
sibber
sibber2y ago
its project based
razkanaz
razkanazOP2y ago
because it works on a different folder
sibber
sibber2y ago
all the files in a project get compiled to a single assembly which you run
razkanaz
razkanazOP2y ago
ok hold on
razkanaz
razkanazOP2y ago
this works
sibber
sibber2y ago
it would work if you moved the file to a directory higher than the project file, because then its not part of the project
razkanaz
razkanazOP2y ago
each one has a different Main file
sibber
sibber2y ago
each one of what
razkanaz
razkanazOP2y ago
no, that's not what i mean each .cs file
sibber
sibber2y ago
each one has a main method?
razkanaz
razkanazOP2y ago
huh it worked yesterday that's weird well so it has to be a different folder for each file? that's very annoying
sibber
sibber2y ago
no
razkanaz
razkanazOP2y ago
oh?
sibber
sibber2y ago
you just cant have more than one main method doesnt matter where the file is or what the name of the class or struct is you just cant define multiple entry points
razkanaz
razkanazOP2y ago
for 1 project? for 1 .csproj file?
sibber
sibber2y ago
for one project yeah
razkanaz
razkanazOP2y ago
ah got it
sibber
sibber2y ago
aka csproj
razkanaz
razkanazOP2y ago
how do i connect a csproj to a .cs file ?
sibber
sibber2y ago
you put the cs file in the same folder as the project file or in a folder under it
razkanaz
razkanazOP2y ago
got it so would this work? hold on
sibber
sibber2y ago
would what work
razkanaz
razkanazOP2y ago
so imagine there is a folder called c# and inside there are 2 folders in each there is a .csproj and a seperate .cs file in each would that work?
sibber
sibber2y ago
yes because those are 2 seperate projects
razkanaz
razkanazOP2y ago
ok thanks
sibber
sibber2y ago
typically we have a solution file that kind of groups the projects so you can build the solution and it builds all the projects or run tests on the "solution" and it would run all the test projects in it
razkanaz
razkanazOP2y ago
how do i do that?
sibber
sibber2y ago
dotnet sln command - .NET CLI
The dotnet-sln command provides a convenient option to add, remove, and list projects in a solution file.
sibber
sibber2y ago
basically
dotnet new sln --name MySolution
dotnet sln add <path to project>
dotnet new sln --name MySolution
dotnet sln add <path to project>
razkanaz
razkanazOP2y ago
ok, i think i'm gonna have to restructure a few gits
sibber
sibber2y ago
dotnet sln list
dotnet sln list
will list the projects
razkanaz
razkanazOP2y ago
tysm!!! i'm finally diving into the deeper end of C# so i'm learning these things for the first time thank you shoould i /close?
sibber
sibber2y ago
yup learning is cool np $close
MODiX
MODiX2y ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server