Lesson 02.2 – Building the solution for the game

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.



Link to video on YouTube


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.

Important note!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.



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

82 thoughts on “Lesson 02.2 – Building the solution for the game

  1. 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?


    1. 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.

      1. Ah, I was right clicking on the project instead of the solution, stupid mistake! Thank you so much for the quick response.

  2. 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!

  3. 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.

    1. 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).

  4. 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

    1. 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.

  5. 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.

    1. 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.

      1. 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.

        1. 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!

          1. 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).

          2. When I try creating the project and saving it to C:/Projects it says I don’t have permission. Help?

  6. Hey, I can’t hear anything in the video, watching it from here and from YouTube. Is it supposed to be silent?

  7. 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?

    1. 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.

  8. 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?


    1. 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.

  9. 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!



    1. 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?

    1. 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.

  10. 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!

    1. 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.

      1. 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.

        1. 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?


    1. 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?

  11. 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?

Leave a Reply

Your email address will not be published. Required fields are marked *