Xamarin installed with vs installer but targets file not found with dotnet tool

In Visual Studio 2019 I can add MonoGame Android projects to solutions and everything is working.

When I try to use the command line / dotnet tool from git bash / powershell the required targets file is not found where the dotnet tool expects it to be.

What can I do to make the dotnet tool work too?

dotnet run --project test/test.Android
C:\test\test.Android\test.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.

So the question is, is the import declaration right in the csproj file? Or do I have to update something or change the configuration somewhere?

I know this post is as old as the hills. Lol, but I was looking for a solution, and saw your post, so I figure others may come upon the post, when they have the same problem.
Hence I decided there is no harm in “awakening the dead” :joy:, to share a fix that worked for me. Copy the Xamarin directory from C:\Program Files (x86)\MSBuild to C:\Program Files\dotnet\sdk\x.x.xxx.
It should work. :smile:

1 Like

Thanks for sharing!
At the moment though I am to busy to try that out myself but maybe eventually I will get to it?!

1 Like