Reputation: 111
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?
Upvotes: 5
Views: 2265
Reputation: 433
Try setting the TargetFrameworkRootPath
to where you have xamarin installed.
<TargetFrameworkRootPath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\</TargetFrameworkRootPath>
or on the command line
dotnet build -clp:ErrorsOnly -p:MSBuildExtensionsPath="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild"/ -p:TargetFrameworkRootPath="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/ReferenceAssemblies/Microsoft/Framework/"
Upvotes: 1
Reputation: 5506
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
.
Upvotes: 8