Provide AndroidSDK path to mdtool on mac - macos

I am building Xamarin.Adnroid project with an mdtool from rakefile as a step in TeamCity build configuration.
The call is:
/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool build "--configuration:Debug" -p:"Project.Droid" -t:Build "Project.sln"
This (and even if I set -p:AndroidSdkDirectory=/Users/user/AndroidSDK) gives an error:
error: The Android SDK could not be found, please set the path to it
in the Xamarin.Android SDKs settings panel.
I can use xbuild to build the project and specify the AndroidSDKPath via:
/usr/local/bin/xbuild Droid/Project.Droid.csproj /p:Configuration=Debug /t:SignAndroidPackage /p:AndroidSdkDirectory=/Users/user/AndroidSDK
but sine my solution hots both, Android and iOS projects, I'd like to be able to build both with mdtool.
Note that this question is unrelated to this one since the later of deals with the UI builds which work great in my case.

I suggest to open Xamarin Studio on the build host and configure the SDK path under Preferences > SDK Locations > Android. That should fix your problem.

Related

Visual Studio Mac, build from command line?

I'm considering using Visual Studio and Xamarin to build a cross-platform app but I prefer to use Sublime Text as my editor. Currently I can't find any information on 3rd party tool integration with Visual Studio.
Does Visual Studio have any way to build from the command line like Xcode does using the "xcodebuild" utility? Ideally I want to make a shell script which can build as if I pressed the build button in VS and return errors I can parse and display in Sublime Text.
Any suggestions are greatly appreciated.
We've use the command line like the following:
msbuild /p:Configuration="AppStore" /p:Platform="iPhone" /p:IpaPackageDir=bin/iPhone/AppStore /p:BuildIpa=true /target:xxxxxxx.sln
Finding doco for what options are required has taken time via Google. Hope this helps.
I use 'vstool' located at "/Applications/Visual Studio.app/Contents/MacOS/vstool" this way:
vstool build -t:Build -c:"Release|iPhone" "MyProject.sln";
As mentioned in vstool help:
Visual Studio Build Tool
build [options] [build-file]
-p --project:PROJECT Name of the project to build.
-t --target:TARGET Name of the target: Build or Clean.
-c --configuration:CONFIGURATION Name of the solution configuration to build.
-r --runtime:PREFIX Prefix of the Mono runtime to build against.
Supported targets:
Build: build the project (the default target).
Clean: clean the project.

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
According to the error and your description, you need also check if your build agent has corresponding capability to support vsbuild.
Take a look at this related question MacOS - Visual Studio Support and give a try with this workaround:
As a work around we set the Xamarin.iOS variable manually in the build
agent and changed the mdtool path in the Xamarin iOS Build step to
"/Applications/Visual Studio.app/Contents/MacOS/vstool".
Besides you could also try to use the suggestion from Matt in the comment above.
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.

ASP.NET CORE 2.1 Preview "SharedCompilationId" parameter is not supported by the "Csc" task

I am trying run the project with views in separate class library on Mac OSX as described in below article
https://blogs.msdn.microsoft.com/webdev/2018/03/01/asp-net-core-2-1-razor-ui-in-class-libraries/
The problem is that I cannot build the class library project with Visual Studio Community 7.4 on Mac OS.
Project builds with command line (donet build) without problems but when I try to build it with Visual Studio it throws two errors:
/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.aspnetcore.razor.design/2.1.0-preview1-final/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.Compilation.targets(10,10): Error MSB4064: The "SharedCompilationId" parameter is not supported by the "Csc" task. Verify the parameter exists on the task, and it is a settable public instance property. (MSB4064)
/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.aspnetcore.razor.design/2.1.0-preview1-final/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.Compilation.targets(5,5): Error MSB4063: The "Csc" task could not be initialized with its input parameters. (MSB4063)
When I change RazorCompileOnBuild to false or remove Content from Content Build project compiles without errors.
Go to Nuget Console and add:
Install-Package Microsoft.Net.Compilers -Version 2.8.2
You will no longer get above mentioned error.
I had this problem on the build server but not locally.
The solution:
Install the updated Visual Studio on the build server. In my case 2017.15.4
As I find you can solve this issue in two ways.
Solution 1
Add Microsoft.Net.Compilers compilers package to the project.
Solution 2
Build the project using the command line. dotnet build
In my case, I had installed the .NET Core 2.1 SDK, but not the runtime.
Strange how Microsoft don't include the runtime in the SDK.
If you face this problem there are three steps you need to take:
Ensure that Nuget package and Target Framework match.
Ensure that the referenced runtime and sdk are installed.
Ensure that Visual Studio is up to date.

Xamarin Archive Build from msbuild/xbuild using the same certs and provisioning profiles fails to install

If I "Archive for Production" my iOS project in Xamarin Studio, I can then sign and create the IPA file. Then I upload to hockeyapp.net and my users can download and install without issue.
If I use xbuild or msbuild from the CLI with all the correct args:
xbuild App/App.iOS.csproj /p:SolutionDir="$HOME/projects/App" /p:Configuration="Ad-Hoc" /p:Platform=iPhone /target:build /p:ArchiveOnBuild=true
and then go into Xamarin Studio to sign and create the IPA, after uploading to hockeyapp.net my users can download but when it's installing, it will fail with a message about being unable to download.
I am using the latest Xamarin Studio and my certs and provisioning profiles are all fine.
Does anyone know what is the difference in the two methods that may be causing my error?
HockeyApp is now Visual Studio App Center. But your problem still exists :-).
From msbuild I know only the configuration debug and release. I don't know if your custom configuration will pick the right provisioning profiles.
You can add CodesignKey and CodesignProvision as properties to msbuild or xbuild to enforce the cert and profile, see the example here:
xbuild … /p:CodesignKey="iPhone Distribution: My Company (0123456789)" /p:CodesignProvision="Automatic:AdHoc" /p:platform="iPhone" /p:configuration="Release"

Universal application with visual studio online

I'm currently setting up project in Visual Studio Online (VSO) and having troubles with setting up automated build.
My solution contains projects targeted as Universal Windows
VSO uses msbuild to run my project.
During build I see strange error messages like:
Error CS0518: Predefined type 'System.Void' is not defined or imported
Error CS0518: Predefined type 'System.Object' is not defined or imported
Error CS0246: The type or namespace name 'Uri' could not be found (are you missing a using directive or an assembly reference?)
msbuild is invoked with following parameters:
C:\Program Files (x86)\MSBuild\14.0\bin\amd64\msbuild.exe "C:\a\b0d9e3fd\test\src\Shipping.sln" /nologo /m /nr:false /fl /flp:"logfile=C:\a\b0d9e3fd\test\src\Shipping.sln.log" /dl:CentralLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:Platform=Win32 /p:TargetVersion=”Windows10” /p:TargetPlatformVersion=”10.0.10010.0” /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="14.0"
What's wrong with this? Are there any other additional parameters required to build universal windows app with msbuild?
Are you targeting the Windows 10 SDK? If so note that it is not installed on the TFS hosted build servers. Consequently you will not be able to build apps that use the Windows 10 SDK. You can see the complete list of installed software here.
Just found the solution.
If build UWP app, from VS it resolves NuGet dependencies automatically. By default VS 10 projects uses NuGet of 3rd version, which was not installed on our build machine. That's why we had such issue.
The problem was fixed with installing NuGet 3 onto build agent and configure script which resolves NuGet packages before build.
If you can't customize the software of your build agent (aka: the free Hosted Agent) another work-around is to just check in your project.lock.json file.
This is because NuGet v2.8.7 can read both project.json and project.lock.json files but it cannot generate a project.lock.json file from a project.json file.
And, if at such a time Microsoft updates NuGet for their default build agents, you can just remove it from source-control and let it generated automatically as part of Nuget -restore. Until then, just check it in.

Resources