Search code examples
xamarintfsmsbuildnugetvisual-studio-mac

Xamarin vstool build cannot find NuGet MSBuild targets


Background

I recently converted my Xamarin.Forms app from PCL to Net Standard format. All of my projects now use PackageReference in the csproj file. Which means no more package.config or package.json.

We use TFS 2015 to build, sign, package our .ipa and .apk files. After conversion, the default MSBUILD build steps do not work as they look for mdtool and the new Visual Studio has vstool instead. So, I updated the build steps to use new tools via command line.

All my projects are NetStandard now (including iOS and Android).

Issue

I can successfully restore NuGet packages using restore MySolution.sln -force on Mac build server. But when I run vstool build MySolution.sln after that, I get this error:

error: NuGet packages need to be restored before building. NuGet MSBuild targets are missing and are needed for building. The NuGet MSBuild targets are generated when the NuGet packages are restored.

I am able to successfully run the nuget restore and vstool build locally on the build machine. But only when TFS runs the command via agent, it shows that error message.

Setup

Builds: TFS 2015 on Mac agent running Visual Studio 7.5


Solution

  • Ok. I was finally able to get a successful iOS build on Mac server. This is the setup that works,

    • Using PackageReference in iOS .csproj
    • No package.config, project.json, or AssemblyInfo.cs file.
    • Running nuget restore .sln before building the iOS project.
    • Build solution using <path-to-vstool>\vstool build .sln -c:<configuration>

    Now, I am working on the Windows machine for Android setup. Once I have that working, I will post my findings here.