Lesson objectives
At the end of this lesson, you will know…
- How to create a program (solution) in Visual Studio
- How, and why, to have separate projects in your solution
How to build your first solution in Visual Studio
People generally use “program”, “application”, and “project” interchangeably. However, Visual Studio calls a program a “solution”.
A “solution” is broken into smaller pieces that Visual Studio calls “projects”. The solution must have at least one project.
In these lessons, I’ll use “program” to talk about the game, “solution” for all the files used to make the game, and “project” for the different groups of files within the solution.
Deciding how many projects the solution needs
When I create a solution, there are always at least two projects.
One is for the user interface (UI), the part of the program that reads and writes to the screen. The second project is for the “logic” of the program.
I do this is for a couple of reasons.
First, it makes the program easier to test.
We won’t do it in these tutorials, but it’s possible to write automated tests to make sure the program does what it’s supposed to do. If you have “logic” in the user interface, this is difficult to automate.
Second, sometimes you’ll want to use one of your projects in another program.
One example might be the code to read from, and write to, a database. That could be useful for any program you write that needs to access a database.
If the database code is in the UI project, you won’t be able to use it in another project, unless it needs to use the same screens from the UI project.
So you put that all that database access code into a separate project, and you can copy it to your next project that uses a database.
When we write the game, you’ll see how I decide what to put in the Engine project.
NOTE: For a large business program, you might have dozens of projects in a solution – which sometimes leads to problems with keeping track of everything.
Creating a solution with two projects
Here’s a video of how to create the solution for your game.
Step 1: Start Visual Studio Express 2013 for Desktop
Step 2: Create a new solution with a “Windows Forms” project (File -> New Project -> Windows Form Application). Make sure you are using the using the project templates listed under “Visual C#”.
NOTE (for Visual Studio 2017 users): You can create this project under Visual C# -> Windows Classic Desktop -> Windows Forms App (.NET Framework). The “Engine” project will be under Visual C# -> Windows Classic Desktop -> Class Library (.NET Framework)
A Windows Form application is a user interface project, one that will display the program on the screen, wait for the user’s input, and update the information on the screen.
We’ll name the program “SuperAdventure”, and save it in the C:\Projects directory.
If you give your UI project a different name, click here to see how to fix the namespace (so you won’t have problems in the rest of the lessons).
Step 3: Now we’ll create the “logic” project.
Right-click on the name of the solution “SuperAdventure”, in the Solution Explorer and select Add -> New Project…, to bring up the project selection screen.
For the project type, select Visual C# -> Windows Classic Desktop -> Class Library (.NET Framework). Name the project “Engine”. (See the image above)
NOTE: If you are using Visual Studio Community Edition 2015, you want the project type that just says “Class Library”, NOT “Class Library (Portable)” or “Class Library (Package)”
The project didn’t need to be named “Engine”. That’s just what I like to name it. However, use “Engine” when you create yours, so it will match what’s in the other lessons and videos.
Step 4: When you create a Class Library project, Visual Studio automatically adds a “Class1” class. You don’t need it, so right-click on it and select delete, to get rid of it.
Step 5: When you create a Windows Form project, Visual Studio creates a “Form1” screen by default.
You don’t need to rename it, but I always do. Right-click on it, select “Rename”, and rename it to SuperAdventure (be sure to leave the “.cs” on at the end).
The form name does not need to match the project name. That’s just what I chose to name it for this program.
Step 6: For the UI project to use the code in the Engine project, we need to connect them.
This is called “setting a reference”.
In the SuperAdventure project, right-click on References -> Add References… -> Solution (which will show you the other projects in the solution) -> Engine -> OK.
Now you can see that “Engine” is listed as a reference in SuperAdventure.
This means that the SuperAdventure project will be able to use the code in the Engine project.
Step 7: Now you can run the program.
Click on the “Start” button to see what the game looks like.
It’s not much yet, but you have to start somewhere.
NOTE: When you create the solution, Visual Studio says “New Project…”, when it really should say “New Solution…”, to use the correct term.
Summary
Now, everything is ready to start writing the program.
The solution has two projects – one for the UI, the other for the code to do all the calculations and logic for the game.
If you had any problems, or have any questions, please leave a comment below.
Next Lesson: Lesson 03.1 – Building the first screen
Previous lesson: Lesson 02.1 – Installing Visual Studio Community 2017
All lessons: Learn C# by Building a Simple RPG Index
Hi Scott! I’m using Visual Studio Community 2015 and I’m having trouble adding the Engine class library.
First of all, when I go to Add Item (“Add Project” is no longer an option) Class Library is not listed as a valid template.
If I go to New Project then there are a few options: Class Library (Portable for iOS, Android, and Windows), Class Library, and Class Library (Portable).
However, I’ve tried making each of these and I can’t seem to add them as a reference to the SuperAdventure project. If I choose Add Reference and go to browse, it’s by default searching for .dll, .tlb, .olb, .ocx., .exe, or .manifest files, none of which seem to be in any of the Engine class libraries I’ve tried creating. Any ideas?
Hi Jason,
When you add the Engine project, do you right-click on the solution file (in the Solution Explorer section), and see these menu options? This is where you would create the new project in the SuperAdventure solution.
The project type for the Engine project should be “Class Library” – without the “Portable”, or “Portable for iOS”.
When you add the reference, do you select the “Projects” section on the left side of the Reference Manager popup screen? That should show the projects in the solution. It should look like this:
Please tell me if those do not fix the problem.
Ah, I was right clicking on the project instead of the solution, stupid mistake! Thank you so much for the quick response.
You’re welcome
Hi, Just wanted to Say Thanks For this Brief Tutorial, Really helps. Love the way you Describe Parts of the Solution as you talking to “Dummies”, Makes it all the more easier for ANYONE to learn from you. GOOD JOB!
You’re welcome! I tried to make it so a beginner, without any experience, could follow the lessons.
When starting a new project I don’t have an option to choose location or solution name, only “Name:”. Also I’ve done this and when right clicking and trying to add class library, add project is not an option.
Are you creating the solution by clicking on the “File” menu option (double-check with the video to make sure you are in the correct place)?
If you are, can you take a screenshot, and upload it someplace for me to look at? Make sure it includes the Solution Explorer area of Visual Studio (the upper-right section).
Hey Scott, I’m having some trouble following this. You’re saying find form1 or delete class1 and I don’t see either. I’m not sure if I’m looking in the wrong place though, but was wondering if you could make some quick screen captions? Or maybe kind of describe where to find them. I’m using VS 2017 and used the .NET class framework option. Please let me know, and thank you for making this for noobs like me! lol
When you have your solution open in Visual Studio, do you see the “Solution Explorer” section in the right part of the screen? That is where the files are. The picture below is a little blurry, because I got it from a screenshot of the video.
If you do not see the Solution Explorer when your solution is loaded, go to Visual Studio’s menu and select “View” -> “Solution Explorer”. That should make it visible.
Please tell me if you still do not see the files.
Hi there! thanks a bunch. I was wondering, if I’m running Visual Studio on Mac OS, what would be the equivalent to a windows forms app? I’m guessing: Forms App? Will I be able to follow through the whole tutorial? Cheers.
I have never tried Visual Studio on the Mac. But, I expect there will be some differences. I don’t know what features are available in a Visual Studio for Mac Forms App, but that’s probably your best chance – unless you can create a VM (Virtual Machine) with a program like Parallels, and install Windows in the VM.
Yup, I did a partition and installed Windows 10, now I have Visual Studio Community 2017, this tutorial was way too good to pass! So, my recommend: If you have a Mac and you want to follow this tutorial: Boot Camp Helper! Thanks Scott, I’m on my way, will let you know of my progress. I’m planning on creating a browser text-based rpg sports sim, something in the likes of simhorseracing.com I’m thinking this tutorial is a great place to start.
P.S.- Another comment though, when you download Visual Studio Community 2017 make sure to install all the .NET packages or you won’t be able to find: Class Library. Thanks again.
Cool! Thanks for sharing the tips for other Mac users who might want to do these lessons.
Hey just wanted to let everyone know that the other option for Mac developers is to follow along with the WPF tutorial instead of the Windows Form tutorial. ASP.NET Core does not support Windows Forms (I imagine Microsoft will be phasing this out over the next few years) but it does support Web Forms Projects! To access this simply:
1. Click on “New Solution”
2. Scroll down on the template screen until you see “Other”
3. Click on “.NET”
4. Click on “ASP.NET Web Forms Projects” at the bottom
5. Click “Next” and then follow the WPF tutorial on the remaining screens!
Thanks for sharing. I saw the Mac version had XAML in web projects, but did not know if they could do everything we need. The game only uses basic XAML, so the WPF version of the source code could work (or require minor changes).
When I try creating the project and saving it to C:/Projects it says I don’t have permission. Help?
Did you try using the other slash “\”? If you did, and it still gives an error, can you take a screenshot with the error?
Hey, I can’t hear anything in the video, watching it from here and from YouTube. Is it supposed to be silent?
There is no audio for most (maybe all) the videos for this course.
When you first take off in the tutorial explaining the type of file to create…you say to use windows forms. I’m using VS 2017 and there are several options under windows forms. Is there a particular one i should use and am I going to be able to complete this tutorial in VS 2017 without too many discrepancies?
You will be able to use this with Visual Studio 2017. When you create the projects, choose “Visual C#” -> “Windows Classic Desktop” -> “Windows Forms App (.NET Framework)” for the SuperAdventure project, and “Class Library (.NET Framework)” for the Engine project.
Thank you….i hadn’t downloaded the proper add on.
You’re welcome
Hello,
I have a question which may be silly. I have a MacBookPro and installed visual studio community. I don’t see an option for windows forms. Does anyone know if the Xamarin.Forms is the same thing or do i need to install another part of VB to get Windows Forms? Or can I not program for Windows Forms on the MAC?
Thanks
Hi Ryan,
I don’t believe Windows Forms projects are available in the Mac version of .NET. If you can create a XAML UI project, you might be able to use the lessons from the WPF version of this course – but I don’t know if anyone has tried this, or if it really works.
The only guaranteed way for it to work would be to use a Virtual Machine program – like Parallels, VMWare, or VirtualBox – to create a virtual Windows computer on your Mac.
Hi Scott.
I have VS Community 2017 and I don’t see “Windows Classic Desktop”. I don’t see C# for “installed”, it’s only in the “online” tab. When I look down at the bottom of the pop-up screen, there’s a message that says “not finding what you’re looking for?” with a link to re-open visual studio installer, I’m assuming I need to install something specific to have “windows classic desktop” in my “installed” folder when creating a new project. Do you know what that might be or how I can do this?
I have a screenshot if you want me to email you for a better understanding of what I’m talking about I can do that!
Thanks,
Jesse
Hi Jesse,
Are you running a Windows computer or a Mac? If you’re on Windows, run the Visual Studio Installer, and check that you have “.NET Desktop Development” checked (see the image below). If that doesn’t work, can you post a link to a screenshot?
I’m using VS 2019 Preview, which doesn’t have an option to add a new project to the solution.
Hi Jorin,
I’m using Visual Studio Community 2019, Version 16.2.5, and was able to add a new project. Make sure you right-click on the solution in Solution Explorer, and not the project. In the screenshot below, I already have other projects added to the solution, but the important thing is to make sure you try to add the project to the solution.
Let me know if you still can’t add the project.
Hi, Scott.
I’m using Visual Studio Community 2019 version 16.5.5 and I ‘m facing some troubles in two steps after creating the Engine project.
When I try to delete Class1.cs file, I receive the following error message after confirming that I want it deleted:
“This operation is not allowed while holding an active upgradeable read or write lock from an AsyncReaderWriterLock.”
After clicking on ok button, the file seems to be deleted anyway because it is removed from the Solution Explorer.
After that I tried to add the Engine project as a reference in SuperAdventure project. However, I receive a pretty much similar error message saying:
“A reference to ‘Engine’ could not be added. This operation is not allowed while holding an active upgradeable read or write lock from an AsyncReaderWriterLock.”
After clicking in ok button, Engine project is not listed among the references listed in SuperAdventure project.
What should I do? I appreciate any help. Thank you!
Hi Marcelo,
I have not seen that error before. Maybe run the Visual Studio Installer and update to version 16.6.0, then reboot your computer. Let me know if that does not fix the problem.
So I struggled with this same issue for some time and after circumventing it and scouring the internet then deleting Class 1 last, I think I figured it out?
I believe that since deleting the class is the first step, Visual studio’s latest versions can not connect a reference with an inoperable class. Something it appears the 2013 version used in the tutorial does no problem.
I have seen some strange behavior in Visual Studio 2019 – mostly (I think) because I have ReSharper installed.
I’d be interested in seeing your solution, to track down the root problem. Can you upload your solution (including the directories under it, and all the files in those directories) to GitHub or Dropbox, so I can look at it?
Thanks!
Hello, I am using Visual Studio 19, and i cant get the reference to “engine” to work.
That usually happens if the project types are not .NET Framework. When you created the projects, if you picked .NET Core, or .NET Standard, for one of the projects you might not be able to set the reference.
If that is not the source of the problem, can you upload your solution (including the directories under it, and all the files in those directories) to GitHub or Dropbox, so I can look at it?
Love your guide! If you do not have Windows Class Desktop as an option due to Visual Studio being the latest version, is there another equivalent for the Engine?
Thanks!
I made a video, since that might be an easier way to show how to find the projects. Let me know if this doesn’t work, or if you have any other questions.
https://youtu.be/dbMQiB7UO1g
Hey Guys!
First, thank you so much Scott for this tutorial. It is literally like finding gold as a newbie c# writer. Second for anyone on VS 2019 who has run into the referencing issue after deleting Class 1 from their engine, the solution I found was to match the .Net versions of the two projects. Otherwise the engine cannot be referenced because (I assume) the different versions of .Net are being read as versions of Core or Standard. This was at least what I took away from the error messages. (After about 20 attempts) I finally got it working by using version 4.0 of the .Net framework. Anyways I hope this helps and once again thank you so much!
Thanks for sharing that, Henry. In the seven years since I wrote these lessons, Microsoft has changed a lot (.NET Core, .NET 5, new versions of Visual Studio). Most of the problems people encounter are from using non-.NET Framework projects.
When I create the Forms, it starts with 0 projects in it, and can’t reference. I’m using VS 2019, maybe I am dumb?
Hi Bastian,
When you create the solution, start by selecting “Create a new project”

Then, enter “framework” in the search box and select “C#” projects. For the first SuperAdventure (UI) project, select “Windows Forms App (.NET Framework)”. Later, when you create the Engine project, select “Class Library (.NET Framework)”.

Please let me know if that doesn’t work, or if you have any other questions.
Ah, I was using the Windows Forms App without the (.NET), problem solved, thanks
You’re welcome
I am running in Visual Studio Community 2019. (16.11.2)
-Windows Form App (.NET Framework)
-Class Library
Dependencies: Selected Enginer
Visual Studio cannot start debugging because the debug target C:\Users/username
source\repos\SuperAdventure.exe’ is missing. Please build the project and retry, or set the OutputPath and AssemblyName properties appropriately to point at the correct location for target assembly.
Believe it’s confused on .NET Framework, but many of the Installation Details aren’t listed anymore, i.e.: .NET Core 2.1 development tools, .NET Core 2.0 development tools. Would love some assistance!
Hi Ainsley,
Can you upload your solution (including the directories under it, and all the files in those directories) to GitHub, Dropbox, or some other file-sharing location so I can look at it?
Unfortunately, because this tutorial was written several years ago, the iterations of VS has changed multiple times. Now, I cannot follow along easily because I just keep getting errors that are nonsensical. Looking up those errors just provide more confusing answers that don’t properly simply it for beginners like me.
Can you upload your solution (including the directories under it, and all the files in those directories) to GitHub, Dropbox, or some other file-sharing location so I can look at it?
I do not find projrct btype “Visual C# -> Windows Classic Desktop -> Class Library (.NET Framework).” I do see Windows desktop. Can I use that?
Hi Ron,
Microsoft changed Visual Studio a lot over the years. If you have a newer version, do you see a screen like the one below? If so, look for the highlighted projects. If those aren’t there, can you let me know what version of Visual Studio you have and maybe send a screenshot of the projects you see?
There seems to be a bit of a problem. The project cannot build because of an error.
The error is about referencing the projects in two versions.
The WinForms is running on .NET4.7.2 but the ClassLibrary is running on .NET6.0.
I can’t seem to find any option to change the version. How do I fix this problem?
Thanks!
Hi Aayush,
Unfortunately, there isn’t a simple way to convert .NET Framework projects to .NET Core/5/6/7. The easiest thing to do (especially since you are at the start) is to remove the Engine project from the solution (and delete the directory/files) and re-add the Engine project as .NET Framework. Or, delete the complete solution and add both projects as .NET 6.
Please let me know if there are any problems doing that.