Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet build xamarin project fails using console

When I try to build my .csproj file with dotnet it throws an error, but when I build project at Visual Studio 2019 it succeeds.

I need to build with dotnet because my Azure pipeline job uses it.

This is the error:

dotnet build MyProject.Mobile.Droid.csproj --configuration Release --force

MyProject.Mobile.Droid.csproj(584,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.1.100\\Xamarin\Android\Xamarin.Android.CSharp.targets was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.100\\Xamarin\Android\Xamarin.Android.CSharp.targets" is correct, and the file exists on disk.

Build FAILED.

(Also as a screenshot.)

If I set the path parameter in my .csproj to this:

<MSBuildExtensionsPath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild</MSBuildExtensionsPath>

Then the error changes:

The reference assemblies for MonoAndroid,Version=v1.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

Any suggestions on how to solve this?

like image 322
cm44 Avatar asked Mar 04 '23 02:03

cm44


1 Answers

You'll need to use msbuild (like msbuild MySolution.sln) to build a Xamarin project today.

You can build the individual netstandard2.x projects using dotnet build, however the Mono based platform projects (i.e. the Android and iOS projects) need to be built using msbuild.

like image 117
Stuart Avatar answered Mar 05 '23 15:03

Stuart