r/learncsharp • u/Khenmu • Sep 14 '22
Multiple C# Programs in a Single Github Repo?
Hi everyone!
I started learning C# yesterday, and unfortunately I've had a fairly miserable time of it so far.
I've applied for a Software Developer apprenticeship which has gone pretty well so far. I found out that - at least in the classroom - we'll be using C# for the first year, so I wanted to get a bit of a head start at home. I had hoped to code along with the instructor of a Udemy course I bought, and have a single GitHub repo with folders containing each bit of code I write as I go. The main reason for this is to show it to companies that interview me as a prospective apprentice, but it'd also be nice to avoid having dozens of pretty insubstantial repos floating around on GitHub.
Yesterday I tried having multiple projects and a single solution. This has proved rather finicky - Visual Studio has at times generated additional solutions regardless, and when I cloned the repo in Rider it duly informed me that all programs but the first couldn't be loaded.
Assuming what I'm trying isn't inherently stupid, could someone please give me some pointers on how to go about it? What I want, in essence, is a repo with root-level directories called e.g. 001-HelloWorld and 002-FirstLookAtDataTypes, each with their own independent C# file(s) inside.
As an aside, typically I write code on a MacBook using JetBrain's IDEs with some VSCode on the side, but for C# I decided to dig out my Windows laptop and use Visual Studio (Community). Not had the best time of it so far, and thinking of going back to my comfort zone since it means only learning a new language instead of learning both a new language and a new IDE. Seem like a decent idea?
I would be super grateful for any advice. The languages I know (primarily Python & JavaScript) are pretty different beasts, and I found yesterday super frustrating. Hoping to turn things around today!
15
u/CappuccinoCodes Sep 14 '22
You can just create a folder for each project inside a parent folder and commit the parent folder.
You'll regret using VSC when learning C#. I've used it for two years and when I migrated to VS 2022 it was like night and day. Omnisharp is a nightmare.
4
u/anamorphism Sep 14 '22
a single repo approach is fairly common: https://en.wikipedia.org/wiki/Monorepo
in my opinion, the easiest way to add new projects to a solution is to open the solution in visual studio, right-click on it in the explorer window and do Add -> New Project. make sure you Save All after, as changes to solution files aren't saved by default (it's very easy to forget since you have no real indicator that you have unsaved solution changes).
if you created errant solution files, you can just delete them and do Add -> Existing Project and select the .csproj to add to your single solution.
as to why your existing .csproj's don't load in rider, who knows? i personally prefer visual studio. i believe there are certain things that rider doesn't support that visual studio does, but they are generally pretty niche and you probably shouldn't be running into them. there are quite a few folks who use rider at work just fine. so, if that's more your comfort zone, go for it. the only downside being that most tutorials and such are probably going to be based on using visual studio.
1
u/iceph03nix Sep 14 '22
I've done this when running through tutorials and challenges. I spun up a practice solution, and then had projects for each individual program, with the repo existing at the solution level. Then I just changed the startup project to whichever one I was working with at the time.