Is it possible to use monogame in VS code?

AzuxirenLeadGuy picture AzuxirenLeadGuy · Dec 17, 2016 · Viewed 10.4k times · Source

I am using an iball notebook and I don't have enough memory to install Visual Studio. I am having no problems using VS code and i am able to make and create executables of my console applications. I need to learn game development but everyone keeps saying that i need to install visual studio for it

However i did find a fourm on monogame on the topic and found that it is possible(At least on Linux) to use Monogame in VS code.

http://community.monogame.net/t/visual-studio-code-and-monogame/2371

Please Help me out.I want to know if it's really possible to compile and run a monogame app in windows.

Answer

AzuxirenLeadGuy picture AzuxirenLeadGuy · Aug 31, 2018

Answer edited as Monogame released official dotnet project templates

I finally got it working.

I realized that all I needed was to create a monogame project (*.csproj) and Compile/Build it without Visual Studio. VS Code is just a feature-rich text editor and I would need other toolset for it.

MSBuild tool is used to Compile/Build monogame project and is available as a CLI. It is available without installing Visual Studio. For C# project building, dotnet core is required. executing the script

dotnet new [Template]

creates a new Project. We need to add a template for monogame here.

As per the latest update by the Monogame Team, you can install the templates by executing

dotnet new --install "MonoGame.Templates.CSharp"

Use the script

dotnet new -h

to check out all the templates available.

Now, to generate the project, use the following

dotnet new mgwindows

On successful execution, this will generate [FolderName].csproj, Game1.cs, Program.cs and other files/folders of monogame project. Please not that this csproj is on .NET Framework (version 4.5 if I'm not wrong....) and therefore it might not work with dotnet run command. (If you're a bit stubborn, you might need to copy the Monogame installed folder(which contains, among many other files, Monogame.target file) in your dotnet installed folder.)

In other words, use msbuild to build and run the project

msbuild

If the program does not contain any compile time errors, the .exe file will be built successfully and you will get to see the the Output file path which you get to execute.

If you're working on Linux or have some other reason not to use MSBuild, you should not generate a mgwindows project. You can rather chose

dotnet new desktopgl

which works on dotnet core (i.e you can use dotnet run command to execute it).