4 Installation

In this section we discuss how to install and setup the MOSEK Fusion API for .NET.

Important

Before running this MOSEK interface please make sure that you:

  • Installed MOSEK correctly. Some operating systems require extra steps. See the Installation guide for instructions and common troubleshooting tips.
  • Set up a license. See the Licensing guide for instructions.

Compatibility

The Fusion API for .NET is compatible with the Microsoft .NET framework version 4.5 and later, Mono v.1.2 and later, and .NET Core 2.0 and later.

Locating files in the MOSEK Optimization Suite

The relevant files of the Fusion API for .NET are organized as reported in Table 1.

Table 1 Relevant files for the Fusion API for .NET.
Relative Path Description Label
<MSKHOME>/mosek/8/tools/platform/<PLATFORM>/bin Libraries <LIBDIR>
<MSKHOME>/mosek/8/tools/examples/fusion/dotnet Examples <EXDIR>
<MSKHOME>/mosek/8/tools/examples/fusion/data Additional data <MISCDIR>

where

  • <MSKHOME> is the folder in which the MOSEK Optimization Suite has been installed,
  • <PLATFORM> is the actual platform among those supported by the MOSEK, i.e. win32x86, win64x86.

Setting up paths

To compile a .NET program using MOSEK the correct path to mosekdotnet.dll must be provided. For example, using the Microsoft .NET compiler this is done with the command line option

csc /r:"<LIBDIR>\mosekdotnet.dll" lo1.cs

To run applications the system must be able to locate mosekdotnet.dll, either in the current directory or in the Global Assembly Cache.

4.1 Testing the Installation and Compiling Examples

This section describes how to verify that MOSEK has been installed correctly, and how to build and execute the .NET examples distributed with MOSEK.

Compiling and running from the command line

To compile an example, say lo1, with the Microsoft .NET compiler, open a DOS box with paths for Visual Studio set up (usually in the Start menu, the sub-menu for Visual Studio contains an entry that starts a DOS box with everything set up).

To compile the example lo1.cs distributed with MOSEK:

  • Go to the examples directory <EXDIR>.

  • To compile the code and produce an executable, type:

    csc /r:"<LIBDIR>\mosekdotnet.dll" lo1.cs
    

    or for Visual Basic:

    vbc /r:"<LIBDIR>\mosekdotnet.dll" lo1.vb
    
  • Copy mosekdotnet.dll into the directory where lo1.exe was created, and run the program with:

    lo1
    

Compiling the examples using nmake

A makefile for use with nmake, named Makefile is available in <EXDIR>. To compile all examples using this makefile use the command

make /f Makefile all

4.2 Other platforms: .NET Core, Mono

The library mosekdotnet.dll may be used from any .NET compatible language such as Visual Basic, Microsoft C# or Microsoft Managed C++ and with .NET Core and Mono. Both the examples and the library should also work with Mono on most 32-bit platforms. If the file mosekdotnet.dll is not included in the MOSEK distribution for your platform, use mosekdotnet.dll included in the Windows distribution.

Note that the library accesses methods in the native MOSEK library, which is considered unsafe from a .NET point of view. This means that use of the library in certain restricted contexts is not possible — building an ordinary application and running it from a local drive should not be a problem.

4.2.1 Mono

Mono is a free implementation if the .NET platform available at http://mono-project.com/. To use it install MOSEK as described in the Installation Manual. Set the environment variable

MONO_PATH

to point to mosekdotnet8_1.dll for the 64-bit Mono. You should now be able to compile and run the distributed .NET examples using Mono.

4.2.2 IronPython

It is possible to use the MOSEK .NET API interactively from .NET languages which implement a command-line interpreter, for example IronPython, available at http://ironpython.net/. This can be used to create and examine the problems and solutions from MOSEK more easily.

4.2.3 MOSEK and .NET Core

The MOSEK NuGet package Mosek.8.1.70.nupkg is a complete cross-platform .NET Core compatible distribution that works on Windows, Linux and OS X.

The NuGet package Mosek.8.1.70.nupkg is available for download from https://mosek.com/downloads. Assuming that the Mosek.8.1.70.nupkg file has been downloaded in a directory local-nupkgs, modify the configuration file *.csproj to add the following entry

<PropertyGroup>
  <RestoreSources>$(RestoreSources);local-nupkgs</RestoreSources>
</PropertyGroup>

Now, add the dependency on MOSEK to the project:

dotnet add package Mosek

and the project using MOSEK API can be built:

dotnet build
dotnet run

Installation instructions for different .NET Core compatible environments may vary.