Is it possible to use monogame in VS code? - directx

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

I wrote this (Windows-only) solution in medium. It's a step-by-step of how to install and run dotnet with MonoGame in the terminal of VSCode.
You need to install:
.NET SDK 5.0
.NET Core SDK 3.1
.NET Runtime 5.0
You can run dotnet in your terminal and see if it's working.
Install MonoGame editor:
dotnet tool install --global dotnet-mgcb-editor
and
mgcb-editor --register
Install MonoGame Templates:
dotnet new --install MonoGame.Templates.CSharp
Create a new project in the chosen template:
dotnet new mgdesktopgl -o ProjectName
Enter in your project with cd ProjectName and add the MonoGame package to it:
dotnet add package MonoGame.Framework.DesktopGL --version 3.8.0.1641
And finally:
dotnet run Program.cs

There is absolutely no reason you cannot work with MonoGame from Visual Studio Code. It will not be an optimal setup since you'll lack debugging, and the setup will be difficult, but if you're okay with that then continue on.
You've already noted that you have no issues creating executable console applications. This is all you really need to be able to do. The key here is that you must build targeting .NET4+ or Mono. If you've followed tutorials that lead you to building .NET Core applications they will not work with MonoGame (at this time). If you are building .NET Core, spend some time looking into how to build Desktop CLR applications using MSBuild or Mono. If you need more information I can expand upon this. You'll also need to be sure you know how to reference other .NET assemblies from your console applications. Please do some research on how to do this before moving on.
For Windows you have the option of targeting DesktopGL (OpenGL) or WindowsDX (DirectX) versions of MonoGame. I'm partial to the DirectX versions myself. You'll need 2 things to get up and running: 1. the MonoGame assemblies, and 2. the MonoGame Pipeline Tool (this is used to compile your content into .XNB files so they may be imported into your game).
To get at MonoGame's assemblies and tools the easiest way I can think of is to install Visual Studio Community Edition and then download and install MonoGame for Visual Studio. This will bring all the tools to you. You'd then need to look at "C:\Program Files (x86)\MonoGame\v3.0\Assemblies" for the appropriate assemblies and "C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools" for the MonoGame Pipeline Tool.
If Visual Studio will not let you install because your machines doesn't meet the requirements then you are not out of luck. The assemblies can be pulled in via nuget. Download the latest nuget.exe here: https://dist.nuget.org/index.html and then run: nuget.exe install MonoGame.Framework.WindowsDX or nuget.exe install MonoGame.Framework.DesktopGL. This will create a directory containing a lib folder that contains a net40 folder which contains the .DLL files you need. For WindowsDX I think you'll also need the DirectX runtime https://www.microsoft.com/en-us/download/details.aspx?id=34429. For OpenGL I think you'll need OpenAL (for audio) https://www.openal.org/downloads/.
Once you have the assemblies you'll need to reference them when you build your code. As you've said you're already familiar with creating and running console applications I'll assume you know how to do this. Just reference every managed .DLL you downloaded with Nuget or pulled from the Assemblies folder from the install.
To test things out, drop this into a .cs file, reference the MonoGame assemblies in your build, build it as you would a console application, and execute:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
public class Game1 : Game
{
GraphicsDeviceManager graphics;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
}
[STAThread]
static void Main()
{
using (var game = new Game1())
game.Run();
}
}
You should get a window with a cornflower blue background. If you don't, then you're not building or referencing things right, or you're missing a dependency.
The trick now is getting your hands on the Pipeline Tool, and MGCB.exe. If you were able to install MonoGame for Visual Studio, great!, these files are in the folder I references above. If not, for whatever reason the MonoGame project doesn't distribute stand alone versions of these, only with the installer. I've taken the contents of what you need and plopped it into a dummy release on GitHub here: https://github.com/srakowski/derp/releases/tag/MG. Download the Pipeline.zip file, extract it, and you should have what you need.
Create an empty Content.mgcb file and open it with Pipeline.exe. You should be able to add and build content files. You'll need to copy these files into the same directory where your .exe lives. Commonly, these are put into a Content folder, and Content.RootDirectory = "Content"; is added to the Game's constructor.
Once you get all this working you should be free and clear to create games as your heart desires. Please let me know if you have troubles and we'll work things out.

I've tried Monogame on Visual Studio and own a Windows PC. So I can safely confirm that Monogame does work on Windows. To answer your question.
However, if you want to try it without Visual Studio, then I don't think you can really get far. as there are several build in tools needed to make a decent one. And you cannot debug it either. You're working really limited if you cannot use Visual Studio.
Try to clean up your PC to make some free space. Visual Studio would really be a better choice to work with.

Related

Cannot create Q# projects

I'm new to quantum computing and I've been trying to follow instructions on https://learn.microsoft.com/en-us/azure/quantum/install-command-line-qdk?tabs=tabid-vscode to dive into this field, but I've run into a problem. Every time I'm trying to create a new Q# application project, I get the following error message
The project file cannot be opened. Unable to find package Microsoft.Quantum.Sdk. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages C:\Program Files\dotnet\sdk\5.0.202\Sdks\Microsoft.Quantum.Sdk\Sdk not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.
and I can't find that package myself either.
I've tried to install Microsoft.Quantum.Development.Kit-0.16.2104.138035 several times, with both .NET 3.1.408 and 5.0.202. I'm using VS 2019 16.9.4 Community Edition on Windows 10.
Looks like nuget.org is not listed as a valid package source in your computer, so dotnet can't find the QDK packages online.
Try running this command:
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
And then try building your Q# project again.
It's unclear to me why nuget.org is not listed as a source, though; it should be included by default when you install the .NET Core.

How to build .NET Framework ASP.NET app using dotnet

We have a mixture of ASP.NET Core and .NET Framework ASP.NET apps. We use a mixture of msbuild and dotnet to build the apps.
I'm trying to go all in on dotnet, but the build always throws an error of:
error MSB4019: The imported project "C:\Program
Files\dotnet\sdk\3.0.100-preview5-011568\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk.
Right now I'm just trying with a very simple command of dotnet msbuild foo.sln. No flags or anything being used for now.
I've tried this on multiple ASP.NET (not Core) apps and they all give the same error.
For ASP.NET Web applications, you need to compile using the following code.
C:\'Program Files (x86)'\'Microsoft Visual Studio'\[year]\[edition]\MSBuild\Current\Bin\msbuild.exe [project.csproj] /p:VisualStudioVersion=[version] /p:DeployOnBuild=true /p:PublishProfile=[profileName]
You can run in cmd or PowerShell.
Replace tags according to the version of Visual Studio installed on your machine and solution version.
For Example:
C:\'Program Files (x86)'\'Microsoft Visual Studio'\2019\Community\MSBuild\Current\Bin\msbuild.exe HelloWorld.csproj /p:VisualStudioVersion=16.0 /p:DeployOnBuild=true /p:PublishProfile=Release
We've solved the Microsoft.WebApplication.targets missing reference by adding it as a NuGet dependency, however the dotnet msbuild command still can't compile all related framework and asp.net projects.
We've also stood up our build server inside a docker container on an ubuntu image, as we were hoping to improve our infra with containerization etc.
However we've hit a wall in building all possible projects using the dotnet executable, even though it has the msbuild command built in.
Anyone had any luck with this?
This answer indicates this is not possible though
https://stackoverflow.com/a/66366638/6578823

F#, Visual Studio 2017 and dotnet new

To create a .NET class library from the command line, you can run the script
dotnet new classlib
Do that in a clean folder, and it will create a csproj file that can then be opened in Visual Studio 2017.
However, run the script
dotnet new classlib -lang f#
in a clean folder, and the fsproj file that is subsequently create cannot be opened in Visual Studio 2017. The error message reads
The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\FSharp.NET.Sdk\Sdk\Sdk.props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
I have searched for clarification of this issue, and it appears that there is work ongoing to fix it, but I wondered in the interim if there are any add-ins I can install to get this working immediately.
The latest preview releases of Visual Studio and .NET Core support loading .fsproj projects, apparently.
See this comment on the GitHub issue:
Closing this now, as these projects load with 15.3. The current way to use them:
Download VS 2017 Update 3 Preview 3 (or a further preview if it's released and you're reading this)
Download the latest CLI/SDK from here: https://github.com/dotnet/cli/tree/release/2.0.0#installers-and-binaries
(Yes, the .NET SDK is independent of VS. You will also need this to get .NET Core 2.0 support in VS 2017 Update 3 Previews).

Is there a way to install F# 3.0 without Visual Studio?

I was hoping to upgrade to F# 3.0 but I can't find either a packaged F# 3.0 compiler on Microsoft site, nor if there is an express version to use. Is it possible to install F# 3.0 for use from the command line or a simple IDE and if so, how?
The standalone version of F# is not available yet, but F# tools for Visual Studio Express have been released just 2 days ago, so you can get F# 3.0 for free.
Announcing F# Tools for Visual Studio Express 2012 for Web!
As far as I know, there are definitely plans for open-source release (that can be integrated with MonoDevelop) and it would make sense to have a stand-alone installer too (otherwise you could still just compile the open-source release), but I don't think there are specific dates for that.
The easiest way I've got it to run:
http://www.heartysoft.com/build-fsharp-3-on-build-server-without-vs
Essentially using the direct download link on the Web PI tools.
I have successfully make a standalone F# 3.0 works without Visual Studio 2012.
First, find a workstation with F# 3.0 installed. (source)
Duplicate all the things to destination workstation.
-> C:\Program Files (x86)\Microsoft SDKs\F#
-> C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp
-> C:\Windows\Microsoft.NET\assembly\GAC_MSIL\FSharp*
Install .NET 4.5 at destination.
Export all the registry item with FSC.exe string to destination.
Export all the registry item with FSharp string to destination.
f# 3.0 registry.rar
if you don't know how to export the registry items, please download this file and use powershell to import all this .reg file.
PowerShell script: (put the .reg files into c:\xxx suppossedly )
cd c:\xxx
dir *.reg | %{ ('reg import "' + $_.Name + '"') | cmd }
I'm assuming most of you seeking an answer to this question by now probably wouldn't mind the most recent version, which is 4.0. You can download this as a standalone at F# 4.0 . This does not include the supporting assemblies and will fail by itself. So you'll also have to download and install the Microsoft Build Tools 2015 . Should be all set to go from there, no installing the mega-massive visual studio. Of course if you need an IDE you'll need to seek out a free one.
You can use Nuget CLI to install the F# Compiler Tools without relying on Visual Studio. As a plus, this procedure does not require admin rights.
Visit nuget.org/downloads and download the latest nuget.exe file.
Instruct your browser to save the file to a folder of your choice.
Add the folder where you placed nuget.exe to your PATH environment variable to use the CLI tool from anywhere.
Open a command prompt and navigate to the folder where you want to install F# Tools.
Run "nuget install FSharp.Compiler.Tools -Version {version}", where {version} is replaced with a version from https://www.nuget.org/packages/FSharp.Compiler.Tools
Add the 'tools' directory to your PATH Environment Variable and then you will be able to use fsc and fsi from the command line.
There is not currently a standalone version of F# 3.0. However, one has been promised
I run F# 3.0 from the cygwin command line on Windows 7. You need to know a little about Linux/Unix to use cygwin, but the basics are not too difficult. You need the basic cygwin shell (command interpreter) and an editor. I am used to vi, so cygwin has vim (there exists a nice F# syntax color addon to vim).
You need to:
Install visual studio in order to get F#
in /users/myname/.bashrc add the location of Fsc.exe, which in my case is
/cygdrive/c/Program Files (x86)/Microsoft SDKs/F#/3.0/Framework/v4.0
to your PATH.

Webapplication.targets missing when building a MVC4 project in MonoDevelop on OS X 10.7.4

I am trying to build a test MVC4 project on OS X 10.7.4 using Mono 2.10.9. I created a new empty MVC4 web application in Visual Studio used git to transfer the source code from Windows to Mac OS X. I then ran xbuild for .nuget package restore, but when I build in monodevelop I get a weird error:
/Users/tamasnagy/Developer/Spellbound/Spellbound/Spellbound.csproj: Error: /Library/Frameworks/Mono.framework/Versions/2.10.9/lib/mono/xbuild/Microsoft/VisualStudio/v10.0/WebApplications/Microsoft.WebApplication.targets: Project file could not be imported, it was being imported by /Users/tamasnagy/Developer/Spellbound/Spellbound/Spellbound.csproj: Imported project: "/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/mono/xbuild/Microsoft/VisualStudio/v10.0/WebApplications/Microsoft.WebApplication.targets" does not exist. (Spellbound)
What could this mean? This also happens when I simply create a new MVC project in MonoDevelop and press build. Any ideas?
Create a symlink:
cd /usr/lib/mono/xbuild/Microsoft/VisualStudio/v9.0
ln -s v9.0 v10.0
I have the same exact ubuntu 12.04 distro on two different computers and could not figure out why mono would compile on one computer and not the other. But oh well, symlink solved the problem.
Change your csproj file to import v9.0, as so...
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
Mono's MSBuild implementation (xbuild) does not have an implementation of the targets for ASP.NET projects.
You might be able to build in MonoDevelop. Make sure you have the experimental xbuild integration turned off in MonoDevelop preferences.
I know this is an old question, but it came up when searching for how to use WebApplications.targets on OSX, so it's still worth answering. With the current version of Mono (5.x), Webapplication.targets is included, so now all you have to do, is to set the VSToolsPath, and everything should just work.
If you are using standard bash shell, the .profile file is the place to put it:
export VSToolsPath=/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild/Microsoft/VisualStudio/v15.0/

Resources