Namespace XNA missing

I started a new project from the templates provided by the Visual Studio 2019 extension. The NuGet packages “MonoGame.Content.Builder” and “MonoGame.Framework.DesktopGL” (started with crossplatform template) seem to be pre-loaded.

Now the problem: Most of the code throws error as "The type or namespace name “Xna” does not exist in the namespace “Microsoft”.
Just to be sure I also installed the latest MonoGame release (from here, the Visual Studio version), which didn’t help.

I want to also point out that I don’t see the element “References” in the solution explorer.
Google didn’t help so I hope you guys can.

Quick side-question: Is the MonoGame release necessary (meaning would the NuGet-packages be enough)?

Thank you very much for your attention!

Well, I saw another guy a few days back get the advise to install a previous version of monogame, because the new one is still being debugged.

I can’t speak to the validity of this claim, but if you have nothing else to do anyway…

Anyway, if I may ask you, it’s been so long since I installed xna/mg I don’t remember, isn’t there some step by step instruction set on setting it all up in VS? To me it sounds like you did something beyond the click-to-install routine. Like what’s all this nuget, cross-platform template talk? Surely that’s above the level of a new user? (seeing as how you are new here, I’m wondering if you are taking an alternative route intentionally)

1 Like

Does the extension contain the new 3.8 templates? Yes the NuGet packages alone are enough. The “preview” part is that they’re still being debugged, but I don’t think the final release will have anything other than NuGet packages, templates, and online docs.

Interesting that you don’t see references. Can you share the contents of your csproj?

If it can’t find the namespace, that usually means it couldn’t restore NuGet packages. Try right-clicking on the solution node in the solution explorer and force it to restore. Also check the Output tab and select Package Manager from the dropdown to see if there are any errors.

1 Like

I downloaded the extension via the Visual Studio Marketplace, where it just says version 1.0.0.

Those are the contents of my Solution:
Annotation 2020-06-12 085913

I tried restoring the NuGet packages and it failed. The error stated:

NU1103 Unable to find a stable package MonoGame.Framework.DesktopGL with version (>= 3.8.0)
NU1102 Unable to find package MonoGame.Content.Builder with version (>= 3.8.0)

This was the CrossPlatform template. I checked the NuGet packages under Tools > NuGet Package Manager > Manage NuGet Packages for Solution… and the installed packages showed both version 3.8.0.
However, all the other available MonoGame NuGet packages show version

Does that mean the templates are still to new for the NuGet packages?
If so, is there any insight as to when the extension and the NuGet packages will be ‘aligned’?

EDIT: I changed the dependency of the solution to be version 3.7.* rather than 3.8.* and now the NuGet packages are successfully loaded. The original error, however, still persists.

I found a solution:

Apparently, MonoGame is moving away from Visual Studio templates and towards CLI templates.
This requires .NET Core SDK (available as workload in Visual Studio 2019):

PS> dotnet new --install MonoGame.Templates.CSharp
PS> dotnet new mgdesktopgl -o MyGame

This creates a CrossPlatform application.
I got this solution from this post.

Thanks to @jnoyola for pointing me to the right direction!

I was creating new project, and it happened, i just hit the play test button anyway. And it sorted itself out.