Today I realized the part for the Android project has to be done a little different because since it is Android we now deal with an Activity1.cs rather than a Program.cs. A manual test showed that it is possible to set everything up so that the shared content is also used by the Android project. So the next step is to figure out how to automatically do everything via MonoGame Kickstarter meaning putting the manual steps into the monogame-kickstarter.sh script. But it is probably more than this alone because I think git bash now gets in the way and from there the Android target is not available. So the dotnet commands for adding the reference to the .NET Core Standard project (to the Android project) and then later the adding of the Android project to the solution file is not possible without getting an error. The errors I am getting from the git bash command line are:
################################################################################
The template "MonoGame NetStandard Library" was created successfully.
################################################################################
The template "MonoGame Cross-Platform Desktop Application (OpenGL)" was created successfully.
Reference `..\auto.NetStandardLibrary\auto.NetStandardLibrary.csproj` added to the project.
################################################################################
The template "MonoGame Android Application" was created successfully.
Project `C:\MonoGame.Kickstarter\auto\auto.Android\auto.Android.csproj` could not be evaluated. Evaluation failed with following error:
The imported project "C:\Program Files\dotnet\sdk\3.1.401\Xamarin\Android\Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.401\Xamarin\Android\Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk. C:\MonoGame.Kickstarter\auto\auto.Android\auto.Android.csproj.
Usage: dotnet add <PROJECT> reference [options] <PROJECT_PATH>
Arguments:
<PROJECT> The project file to operate on. If a file is not specified, the command will search the current directory for one.
<PROJECT_PATH> The paths to the projects to add as references.
Options:
-h, --help Show command line help.
-f, --framework <FRAMEWORK> Add the reference only when targeting a specific framework.
--interactive Allows the command to stop and wait for user input or action (for example to complete authentication).
################################################################################
The template "Solution File" was created successfully.
Project `auto.NetStandardLibrary\auto.NetStandardLibrary.csproj` added to the solution.
Invalid project `C:\MonoGame.Kickstarter\auto\auto.Android\auto.Android.csproj`. The imported project "C:\Program Files\dotnet\sdk\3.1.401\Xamarin\Android\Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.401\Xamarin\Android\Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk. C:\MonoGame.Kickstarter\auto\auto.Android\auto.Android.csproj.
Project `auto.OpenGL\auto.OpenGL.csproj` added to the solution.
Also when I try to run it with the dotnet run command:
dotnet run --project auto/auto.Android
C:\MonoGame.Kickstarter\auto\auto.Android\auto.Android.csproj(76,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.1.401\Xamarin\Android\Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.401\\Xamarin\Android\Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk.
The build failed. Fix the build errors and run again.
With Powershell:
dotnet run --project auto/auto.Android
C:\MonoGame.Kickstarter\auto\auto.Android\auto.Android.csproj(82,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.1.401\Xamarin\Android\Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.401\\Xamarin\Android\Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk.
The build failed. Fix the build errors and run again.
The last post is a bit long and nobody likes to read verbose stuff…
I guess the main problem which is blocking me at the moment is that like the errors above tell me there is no Xamarin folder at the mentioned path and so no targets file which is required for the commands to work properly:
C:\MonoGame.Kickstarter\auto\auto.Android\auto.Android.csproj(76,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.1.401\Xamarin\Android\Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.401\\Xamarin\Android\Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk.
I noticed there is a double backslash in the error message… Is this normal? Could somebody try / test if they can generate an Android project from the git bash command line and / or from the Powershell?
Or does somebody know if I need to update anything? Where are those targets supposed to be?
The project generation works with the script. And in Visual Studio I can add the project to the solution and also the reference to the net standard project. So everything should work I guess from the command line to but it doesn’t
I searched for the Xamarin.Android.CSharp.targets file and I found one at
At this point some testers with Windows 10 and installed git / git bash would really be helpful to check if this issue(s) are related to my setup / configuration or it is something other than that.
I pushed everything to the GitHub repository onto the android branch.
Testing is as easy as follows:
git clone / change to the android branch.
open git bash and cd to the cloned repository
run ./monogame-kickstarter.sh test
This will generate a folder named test and try to setup the solution and projects (default OpenGL and Android at the moment). Make sure you have installed the requirements like Xamarin via Visual Studio installer. If you are able to target Android under Linux the information if the script works in this case would also be helpful.
Would a template solution be flexible meaning I can choose which projects I want to have each time I use it? Where can I get more information how to setup templates with MonoGame projects? I mean like what would the work flow look like? What is your advice how to set this up?
I can look into template creation but for it to work I guess I will have to make the dotnet tool work with the simpler templates first. In this case the mgdesktopgl and mgwindowsdx templates work but the mgandroid does not.
Is the import declaration correct? Or is my system setup / configuration not correct? Or what is the problem?
It is simply not possible at the moment to work with Xamarin.Android projects from the dotnet CLI until .NET 6 will be out in November 2021. See comments / discussion on GitHub https://github.com/MonoGame/MonoGame/issues/7350
So for MonoGame Kickstarter this means that while the mgdesktopgl and mgwindowsdx projects can be setup automatically by the script and everything just works for Android you would have to do some steps by hand.
Using e.g. Visual Studio 2019 the additional steps after running the MonoGame Kickstarter script (with Android project generation enabled to have it generate the project template) are:
Open the solution and add the Android project
Add a reference to the Android project to the NetStandardLibrary project
Inside Visual Studio delete or exclude the Game1.cs from the Android project (it should be marked as not found already because it was deleted already on disk by the script)
Right click the Android project and select Set as Startup Project from the context menu.
Add to line 68 in the android.csproj an entry for the content from the NetStandardLibrary project so the shared content is available (replace SOLUTIONNAME !!!).
This way the Android project has content available from the shared content mgcb from the NetStandardLibrary project and also the default content which the template provides for Android projects.
I pushed everything to GitHub to the android branch if yomebody wants to test it. The script will also output the info about how to do the manual steps.
At this point the manual steps are not tested very much. I will test it if I have more time.
The mid term goal was to automate the setup of at least the project types mgdesktopgl and mgwindowsdx which MonoGame Kickstarter can provide. To have the mgandroid project to be included as well would have been nice but as described that is not available via the dotnet CLI yet until it will be supported by .NET 6 in November 2021. At least with some manual steps the remaining setup steps for an optional Android project can be done with Visual Studio 2019 as described.
As suggested there is also the alternative to the MonoGame Kickstarter script of creating a dotnet template. This way the automated setup of all projects should be possible if someone wants to create their own solution.
Thank you, I hope the project is of some use for the community.
To answer your question the script is using the locally installed MonoGame templates. So it is using 3.8 or newer depending what is installed.
To install / update the dotnet CLI templates you only need one command
dotnet new --install MonoGame.Templates.CSharp
MonoGame Kickstarter checks at some point if the MonoGame templates are installed since they are required and prints the command if none are found.
The command is from the official MonoGame documentation.
Since MonoGame Kickstarter is at the core only just using the dotnet CLI you can modify and add or remove anything you want later from the generated solution and / or projects.
Looking into this again. I would like to add automatically generated Android projects! They can be generated already but there are manual steps necessary after project creation. So what I want to add is the scripted version of the manual steps needed to get a visual studio solution with everything just working from the start (shared code and content through a net standard library project, a windows dx, opengl / desktop project and an android project.
One of the steps is to manually add the existing Android project to the solution. I looked into what is different after adding the project to the solution and it isn’t of course just a line somewhere, it is a lot of stuff. And I don’t really know how the internals work and would prefer a somewhat robust way of adding the project to the solution. Anybody here knows how I could achieve this through bash scripting?
Normally the dotnet cli command with sln add would do it (like for the other project types). But for Android it does not work as described in the thread.
Second option which I thought about for a moment was just using visual studio from the command line and add the project this way. But this would rely on visual studio and would complicate everything even more and I don’t think it is reasonable to follow that path.
At the moment it supports creating DesktopGL, WindowsDX and Android (more or less meaning manually adding the project to the visual studio solution is necessary after the script has finished).
I need to fix some things first before I want to update the git repo. Of course you can check the bash script out and edit and or replace things however you like to make it work for you.
That’s not what I need. I hope that eventually there will be a collection of templates available which do what the script is doing so I don’t need the script anymore.
What I would like to have is a template which creates 4 projects android, windowsdx, desktopgl, net standard class library for the shared code and content and a visual studio solution. I just don’t like to run all comands and edit the csproj files and do a lot of manual steps in vs for new projects.
Is something like this available somewhere?