Xamarin iOS build server on OSX using Jenkins and Nuget - ios

I am currently building a continuous integration pipeline on an iMac in order to build Xamarin iOS apps. We are using Jenkins to control the CI build process but the project contains a number of Nuget packages that are not stored in our Git source repo. As these packages are not downloaded by Jenkins I need to call a Restore on the solution.
Is Nuget.exe installed as part of Xamarin Studio on OSX (and if so where) and if not is there an OSX command line version for El Capitan?

The Mono installer on OS-X supplies a nuget shell script and the nuget.exe CIL-assembly
Default install location of script:
/usr/local/bin/nuget
Script contents:
#!/bin/sh
exec /Library/Frameworks/Mono.framework/Versions/4.4.0/bin/mono $MONO_OPTIONS /Library/Frameworks/Mono.framework/Versions/4.4.0/lib/mono/nuget/NuGet.exe "$#"
Nuget version:
As of Mono 4.4.0, the nuget version is:
NuGet Version: 2.8.5.0
Nuget restore:
In the root of your solution, all you have to do is call nuget restore with your solution, i.e.
>nuget restore mysolution.sln
All packages listed in packages.config are already installed

Related

How can I build Visual Studio 2019 projects on Travis CI?

Travis CI recently added a Windows OS option to its build system. Unfortunately, the preinstalled packages only include Visual Studio 2017.
How can I build Visual Studio 2019 projects (such as .Net Core 3.1 and v142 build tools projects) on Travis?
The key to using updated build tools is Chocolatey, the Windows package manager. As long as the toolset is available on Chocolatey, you can install it on your Travis VM.
For .Net Core, that means installing the dotnetcore-sdk package.
For VC++ build tools, there is the visualstudio2019buildtools package, but note you will have to opt in to the Microsoft.VisualStudio.Component.VC.Tools.x86.x64 feature. See below for syntax. A full list of features is available in the Build Tools component directory.
Here's a full .travis.yml file for a VS 2019 solution containing a C++ project, a .Net Standard 2.0 project and a .Net Core 3.1 project. The test project makes use of the unmanaged DLL.
os: windows
language: cpp
env:
- MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
install:
- choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
- choco install dotnetcore-sdk
- dotnet restore
script:
- export PATH=$MSBUILD_PATH:$PATH
- MSBuild.exe -p:Configuration=Release -p:Platform=x64 CppProject/CppProject.vcxproj
- dotnet build --configuration Release
- dotnet test DotNetProject.Tests/bin/Release/netcoreapp3.1/DotNetProject.Tests.dll

Not possible to build electron package correctly in windows server machine(tfs agent)

I build application using electron framework, I see package is correctly in my local machine(windows 10 64 bit). After the package is built, I am able to run the package.
If I run the application in windows server 2019, I cannot run the application that is built.
More Info, I build the electron package in tfs and the tfs agent is windows server 2019.
Build script inside package.json
"builder": "electron-packager --out winx64 --overwrite --platform win32 --appname MGCenter . --executable-name ClientLMCenter --no-prune --asar"

Building .a NET Core project using Jenkins always references the latest installed SDK version

I'm running a "Build a Visual Studio project or solution using MSBuild" on Jenkins for several projects to generate nuget packages.
The MSBuild used is the latest Visual Studio Build Tools
The version of the .NET Core sdk used in the project is 1.0.4
Company.Core.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
</Project>
However while executing a build the used SDK version is always the latest SDK installed on the machine (2.x).
C:\Program Files\dotnet\sdk\2.1.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5):
error NETSDK1064: Package Microsoft.CSharp, version 4.0.1 was not found.
It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.
[C:\Workspaces\Company.Core\Company.Core.csproj]
After uninstalling the 2.1.400 SDK version i get the error:
C:\ProgramFiles\dotnet\sdk\1.1.10\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(308,5):
error : Assets file 'C:\Workspaces\Company.Core\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. [C:\Workspaces\Company.Core\Company.Core.csproj]
The installation used to support .net Core 1.0.4 was .NET Core 1.0.4 & 1.1.1 SDK 1.0.1 using the instructions:
Windows Server Hosting
If you are looking to host stand-alone apps on
Windows Servers, the ASP.NET Core Module for IIS can be installed
separately on servers without installing .NET Core runtime. You can
download the Windows (Server Hosting) installer and run the following
command from an Administrator command prompt:
DotNetCore.1.0.4_1.1.1-WindowsHosting.exe OPT_INSTALL_LTS_REDIST=0
OPT_INSTALL_FTS_REDIST=0
I also added RuntimeFrameworkVersion in the csproj that had no effect.
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>^
global.json also gets ignored
{
"sdk": {
"version": "1.0.4"
}
}
It looks like you can specify the sdk version in a global.json file:
{
"sdk": {
"version": "1.0.4"
}
}
Source:
https://markheath.net/post/switching-between-netcore-sdk-versions
I think there's some confusion here. .NET Core consists of two almost separate components: the SDK and the Runtime. The SDK is used to build your code and the runtime is needed to run it.
They are versioned differently. For example, the latest SDK is 2.1.403, while the latest Runtime is 2.1.5.
A recent version of SDK can target any version of the runtime released before it. So, a 2.1.403 SDK can build applications that need 2.0 or 1.0 to run.
You can force a particular SDK to be used, by using the global.json file. You need to specify a version of the SDK that is already installed. dotnet new globaljson will generate something that you can edit the versions in. But you shouldn't need to do that. You can just use the latest SDK and ask it to build for an older runtime by setting the TargetFramework as you do.
If you do a dotnet restore, does the error NETSDK1064: Package Microsoft.CSharp, version 4.0.1 was not found. still stick around? The second error, Assets file 'C:\Workspaces\Company.Core\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. backs this up. The project.assets.json is created by dotnet restore. Could you simply be missing that step?

Packaging nuget package on VSTS 'Newtonsoft.Json' already has a dependency defined for 'NETStandard.Library'

Packaging a build use Nuget Packager in VSTS and i get the error:
[error]'Newtonsoft.Json' already has a dependency defined for 'NETStandard.Library'.
Most of the hints that solves this involves updating nuget, but since I am building on Team Services I can't really do this.
It seems that the nuget used by nuget packager is not the latest. After testing locally with latest nuget.exe everything worked so I added a new powershell release step. This solution is appropriate for VSTS, for TFS where you have access to the server I recommend upgrading nuget.exe on the server itself:
This script downloads nuget.exe into the artifacts directory (and outputs the path to the nuget.exe so you can see where it is put.).
I then altered the Nuget Packager build step to use the freshly downloaded nuget.exe.
Had the same issue today.
Using your own build agent
If you are using your own build agents (rather than the hosted agent) you can manually update the version of NuGet to the latest version. In my case, this has resolved my problems.
e.g. C:\agent\externals\nuget\nuget.exe
Using the hosted agent
It's a bit messy but you could just upload the latest nuget.exe into the repo and set the NuGet Packager to use this.
To anyone getting this in 2018, Microsoft have created a new version of the NuGet task that fixes this issue. No need for powershell install steps.
Change the NuGet task version in your build step version to 2.*
This caused some breaking changes for me, that I resolved with the following advanced settings
Nuget Restore
Nuget Pack
Nuget push

Jenkins not finding a nuget package

I'm setting a Jenkins CI server. I got the first step to run properly:
nuget restore -NonInteractive -ConfigFile Nuget.config -Verbosity Detailed -NoCache
That works properly, but when I want to compile the app with:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe
and ${WorkSpace}\src\Weather.App.csproj
It throws this error:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(178,5): error : The package HockeySDK.Core with version 4.1.6 could not be found in C:\WINDOWS\system32\config\systemprofile\.nuget\packages\. Run a NuGet package restore to download the package. [C:\Program Files (x86)\Jenkins\workspace\MyApp\Weather\Weather.App.csproj]
The weird thing is that it the Hockey package clearly exists in the path:
If I run the same command IN my VS2017 local project, everything runs smoothly. But the jenkins server (which is in my same machine) does not build it properly.
Any ideas? Thanks
Here's the trick.
Put nuget.exe somewhere on he build server.
Ensure nuget.exe is in the PATH environment variable.
Restart Jenkins so that it picks up the updated PATH environment variable
Upgrade NuGet to the latest version
nuget.exe update --self
In the Jenkins job calling rebuild against MSBUILD won't successfully restore the nuget packages
Add a Windows Batch step after the MSBUILD Clean and before the MSBUILD Rebuild like so:
nuget restore <your_solution_file>.sln
Path to solution file is workspace relative.
This will create the packages directory as you would expect.

Resources