Tag Archives: Visual Studio

Using CNTK with Visual Studio 2017 and Python

In the next few steps will show how to install CNTK and python environment in Visual Studio 2017.

  1. First download the latest CNTK version from the official GitHub page, or just click on the following link: https://github.com/Microsoft/CNTK/releases

The release page will show the latest bits. Click on the CPU only package, accept the license and download the zip file.

  1. Once that you have zip file on your PC, create the folder C:/local on disk and unzip the package in to it.
  2. The next step performs the installation of the library as well as installation of the Python related distribution anaconda 4.1.1.
  3. Open C:\local\cntk\Scripts\install\windows path and run install.bat file. You will need administrative rights in order to successfully install all required components.
  4. The following image shows the installation process:

  1. As can be seen first you have to run batch file (step 2), then press 1 and ENTER in order to continue with the installation process and press ‘y‘, to perform downloading required components.
  2. The installation process takes several minutes to complete. The first component to be installed is Anaconda 4.1.1 which is needed in order to setup  CNTK.

  1. Once the anaconda is installed, the process of CNTK installation starts and passes very quickly since we already download all CNTK bits.

  1. Now that we have CNTK installed, the last installation step is installation of the Visual Studio Tool for Python.
  2. Run the Visual Studio 2017 Installer and after the installed is show, just select the python components similar picture shows below:

  1. Once the installation is completed run Visual Studio 2017.
  2. From the Visual Studio 2017 Tool menu select Python and then select Python Environment:

  1. From the Python Environment window select Anaconda 4.1.1 and update symbols DB, by pressing the button pointed on the image below:

  1. Once we have environment updated, Press “Make this the default environment for the new projects” option in order to apply the environment for the future Python CNTK based projects.
  2. Also the path for Python and Python scripts should be registered in Global Environment OS.

  1. Once the previous steps are performed successfully, we can start writing CNTK aware python code in Visual Studio 2017.
  2. OPen VS 2017 and Anaconda 4.1.1 environment and type.

   import cntk

print(“CNTK verion:”, cntk__version__)

  1. Similar output should be appear
  2. print(“CNTK version:”, cntk.__version__)



Introduction to Microsoft Machine Learning package in Microsoft R Server 9.0

MicrosoftML package

Microsoft has released Microsoft R Server 9.0 (MRS9.0) with very interesting package called MicrosoftML. “Micrsooft ML” stands for Microsoft Machine Learning R package which you can use on R Server. R Server is commercial version of popular R Client distribution, which solves mayor problems when working with R. R Server contains set of cutting-edge technology to work with big data, as well as set of enhanced packages for parallelization and distributing computing.
MRS 9.0 is coming with “MicrosoftML” package which contains set of several Machine Learning algorithms developed in various Microsoft products in the last 10 years. You can combine the algorithms delivered in this package with pre-existing parallel external memory algorithms such as the RevoScaleR package as well as open source innovations such as CRAN R packages to deliver the best predictive analytic.
MicrosoftML package includes the following algorithms:

  • Fast linear learner, with support for L1 and L2 regularization,
  • Fast boosted decision tree,
  • Fast random forest,
  • Logistic regression, with support for L1 and L2 regularization,
  • GPU-accelerated Deep Neural Networks (DNNs) with convolutions,
  • Binary classification using a One-Class Support Vector Machine.

How to start with MicrosoftML package

In order to fully use the power of MicrosoftML, and RevoScaleR you need to download MRS 9.0 from the MSDN or Visual Studio Dev Essentials subscription. Once the zip file is downloaded, unzip it, and run setup file.

The following required components  were missing when my installation is started.  Seems the MRS contains the latest .NET Core components, which is pretty cool:



After the prerequested components installed, the MRS installation process can start.


By clicking the Next button the Installation process starts:


Select the path where you want to install MRS, and press the Next button:


If everything went ok, the installation process is finished after less than minute, and the final dialog window appears:


By clicking the Finish button MRS is installed on you PC.

Run MRS 9.0 by using R Tool fo Visual Studio, RTVS

Now it is time to run some R code. YOu have two posibilities to run R code. The first option is that you use the R Studio proffesion tool for running R code. It is free and open source which you can download from rstudio.com. If you are MS Developer you usualy write the code in the Visual Studio. So you can download RTVS from this link and run R code from Visual Studio.

Now that you have right tool to run R code, we can start with setting the MRS environment.

First thing you should do is to point RTVS to use MRS 9.0 instead of curently using some other distribution. So open the Visual Studio, select R Tools->Edit Options


The Option dialog appears. Set the R Engine to point installation folder of the MRS. Since my installation location was on Program Files folder, the picture below show my installation path.


After you set the right installation folder , restart the Visual Studio:

When the Visual Studio is running, open R Open R Interactive window. You should have similar text if you set up MRS path correctly:


Select New Project from the File->New menu option.


Name it FirstRServerDemo and click Ok. Now you are ready to write first MRS R code:


In the next post we will continue exploration the MicrosoftML library package and new set of Machine Learning algorithms added in this latest version.

Details of my session at ATD12


Today, I gave session at Advanced Technology Day conference in Zagreb. It was very excited to see full room of people at the presentation, mostly developers from .NET world interesting in R and Data Science. This is good sign that the Data Science and the R are becoming more and more popular at daily basis. Most popularity for the R will bring R Tool for Visual Studio, which means the R language became member of the family of the Visual Studio.


For those who were asking about my slides and demo sample here is the information:

  1. Presentation slides can be downloaded here,
  2. Source code of the demo is hosted at git hub at: http://github.com/bhrnjica/R-Workshop
  3. For more information about R , you can see my YouTube channel about R and Machine Learning at this link.

See you next time!

Visual Studio vNext – The New Installer

Download Visual Studio 15 Preview 3

The new version of Visual Studio will come with dramatically new installer, which will allow that you install only stuff you need, without gigabytes of unnecessary never used components. Current version of Visual Studio which is Visual Studio 2015 Update 3 is coming with nearly 8GB installation file. This is to much for the installer, you need special condition when you want to download the installation file. I am doing it by night, when I am sleeping. In some condition the installation process takes an hour to install everything you have specified.

In the next version the installation process will be changed and if you want to see and feel how the future visual studio installer  will look like you can download the preview of the Visual Studio vnext code name  “Visual Studio 15” at this link.

If you try to install Visual Studio 15 preview 3, it will take less than 5 minutes, with very simple installer. In the next five pictures whole installation process is completed.

After you download the installer, run it and the following pictures will appear:

  1. First picture is asking to confirm the installation process:


2. The next picture shows the progress of loading installer


3. The next picture is the main picture which you can select what to install. The whole Visual Studio installer is devided in to the development groups:

  1. Core Stuff of the Visual Studio- this component is required for all developer group
  2. There are for now 4 installer groups: .NET, C++, Python, Game dev.
  3. The more will come later.

4. After you select right developer group/groups installation process starts by pressing Install button.


5. After the installation process is completed, the following picture appear, which you only need to close by pressing the Close button at the right top edge of the window.


As we can see the next version of the Visual Studio will dramatically changed the installation process, offering new simple and effective installer.

Objektno Orjentisano Programiranje- prvi dio

Objektno orijentisano programiranje (OOP) predstavlja način programiranja pri čemu se definišu objekti koji poprimaju osobine objekata iz realnog svijeta. Nastao na ovom konceptu, OOP s jedne strane proširuje funkcionalnosti osnovnih i izvedenih tipova na način da implementaciju enkapsulira (ugrađuje) u sami tip, dok s druge strane uvodi nove osobine tipova poput nasljeđivanja i polimorfizma koji daju nove funkcionalnosti i način implementacije. Sve tri paradigme OOP (enkapsulacija, nasljeđivanje i polimorfizam) čine objektno orjentisano programiranje efikasnije, lakše za kolaboraciju i održavanje te u većem dijelu rješava probleme proceduralnog programiranja.


Tipovi podataka u čistom OO jeziku poput C# označavaju se klasama, koje se mogu podijeliti na osnovne i izvedene tipove. Programski jezik poput C++, osnovne tipove ne tretira kao klase, dok klasama označava samo izvedene odnosno apstraktne tipove. Osnovne tipove poput integer, double, float, bool, char u čisto OOP jeziku zovemo klasama jer u sebi enkapsuliraju metode koje nam omogućuju rad nad samim tipovima, na isti način kako to radimo i sa izvedenim tipovima. Izvedeni tipovi su svi tipovi koji su definisani od strane programera.
U čistom objektno orijentisanom programskom jeziku ne postoji mogućnost izvršavanja koda koji nije dio neke klase, odnosno koji nije definisan unutar određene metode kao članice klase. S druge strane ovo implicira da se u objektno orijentisanom programiranju može izvršiti samo onaj kod koji je definisan unutar određene klase, odnosno instanciranjem objekta i poziva neke metode članice. Ovom činjenicom se shvata naziv objektno orijentisano programiranje, kao programirnje objekata.
Naravno, programski jezici nužno ne poštuju ovu strogu činjenicu, a pored toga imaju mogućnost izvršavanja koda izvan objekata klase. Kako je ranije naglađeno programski jezik koji ima ovakvu dualnu osobinu jeste C++. C++ programski jezik je objektno orijentisani jezik koji podržava sve osobine OO koncepta, dok istovremeno predstavlja klasični proceduralno orjentisani jezik. Zbog te činjenice danas C++ jezik predstavlja najrasprostranjeniji i najviše korišten programski jezik. Pogodan je kako za programiranje sistemskih komponenti operativnih sistema i drivera za uređaje, tako i za projekte zasnovane na poslovnoj logici. Deklaracija klase u C++ sa pripadajućim članovima možemo predstaviti u obliku prijera tipa Osoba.

class Osoba
    //konstruktori/destruktor klase

//clanovi klase /atributi
	string  imePrezime;
	time_t  datumRodjenja;
	string  mjestoRodjenja;  

	//javne metode clanica
	void Init (string ime, string datum);  

	//javne virtualne metode clanice
	virtual string Status();

Prethodni listing predstavlja deklaraciju klase Osoba. Implementacija klase u smislu implementacije konstruktora, destruktora i metoda Init i Status nalazi se izvan tijela klase, a često u posebnoj cpp datoteci. Primjer implementacije klase Osoba vidimo na sljedećem listingu.

//defoltni konstruktor
    imePrezime = "n/a";

//destruktor klase

//virtuelna metoda koja vraca status osobe
string Osoba::Status()
	return "Osoba";

//postavljanje imena i datuma rodjenja osobe
void Osoba::Init(string ime, string datum)
	imePrezime = ime;  

	//konverzija string u datum
	struct tm tm = {0};
	strptime(datum.c_str(), "%d/%m/%Y", &tm);
	datumRodjenja = mktime(&tm);

Prethodni listing čini implementacija kontsruktora koji se poziva prilikom formiranja objekta Osoba, dok se implementacija dstruktora nalazi odmah iza. Metoda Init postavlja ime i datum rođenja za osobu, dok metoda Status vraća string sa nazivom vrste osobe.
C# i Java predstavljaju najpopularnije OO programske jezike pored C++, u kojima sve počinje sa objektima, i nije dozvoljeno definisanje metode izvan klasa. Specijalna metoda koja označava ulaznu ili početnu tačku zove se main metoda. Ovu metodu je dovoljno definisati u bilo kojoj klasi, a kompajler će je prepoznati kao početnu metodu i označiti je kao ulaznu tačku programa. Primjer listing 1 i 2 u C# izgledaju na slijedeći način:

public class Osoba
	//konstruktori/destruktor klase
	public Osoba()
		imePrezime = "n/a";



	//clanovi klase /atributi
	private string      imePrezime;
	private DateTime    datumRodjenja;
	private string      mjestoRodjenja;  

	//javne metode
	public void Init(string ime, string datum)
		imePrezime = ime;
		DateTime dat;
		if(DateTime.TryParse(datum, out dat))
			datumRodjenja= dat;

	//javne virtualne metode clanice
	public virtual string Status()
		return "Osoba";

Iz prethodnih listinga možemo vidjeti određenu razliku u deklarisanju i implementaciji klase i njenih članova. U C++ vidimo da je deklaracija i implementacija metoda članica klase razdvojena. Za razliku od C++ u C# deklaracija i implementacija klase u C# se ne razdvajaju, tako da se svaka metoda članica deklariše i implementira na jednom mjestu.

Using external config files in .NET applications

The config file is place where common variables, database connection strings, web page settings and other common stuff are placed. The config file is also dynamic, so you can change the value of the variable in the config file  without compiling and deploying the .NET app. In multi tenancy environment config file can be complicate for deployment, because  for each tenant different value must be set for most of the defined variables. In such a situation you have to be careful to set right value for the right tenant.

One way of handling this is to hold separate config file for each tenant. But the problem can be variables which are the same for all tenants, and also the case where some variables can be omitted for certain tenant.

One of the solution for this can be defining external config files for only connection strings or appSettings variables, or any other custom config section. In this blog post, it will be presenting how to define connection strings as well as appSettings section in separate config file.

Lets say you have appSettings and connectionStrings config sections, similar like code below:

<?xml version="1.0" encoding="utf-8" ?>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

		<add name="SQLConnectionString01" connectionString="Data Source=sourcename01;Initial Catalog=cat01;Persist Security Info=True;Integrated Security=true;"/>
		<add name="SQLConnectionString02" connectionString="Data Source=sourcename02;Initial Catalog=cat02;Persist Security Info=True;Integrated Security=true;"/>

		<clear />
		<!-- Here are list of appsettings -->
		<add key="Var1" value="Var1 value from config01" />
		<add key="Var2" value="Varn value from config01"/>
		<add key="Var3" value="Var3 value from main config file"/>


There are three appSetting keys Var1 , Var2 and Var3  and two connectionstrings in the app.config.

The config file above can be split in such a way that variables Var1 and Var2 be defined in separated file, but the Var3 can be remain in the main cofing file. Separate config file may be unique for each tenant.

Now the main config file looks like the following:

<?xml version="1.0" encoding="utf-8" ?>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

	<connectionStrings configSource="config\connString01.config"/>

	<appSettings file="config\config01.config">
		<add key="Var3" value="Var3 value from main config file"/>


In the Visual Studio Solution there is config folder in which we created two config files for appSettings section and two config files for Connectionstrings section, in case we have two separate environments for deployments.

The flowing code snippet shows the appSettings section implemented in the external file:

<appSettings file="appSettings.config">

	<!-- Here are list of appsettings -->
	<add key="Var1" value="Var1 value from config02" />
	<!-- ... -->
	<add key="Varn" value="Varn value from config02"/>

The external config file for connection strings looks similar like the flowing:


The simple console application shows how to use this config variables in the code:

static void Main(string[] args)
    var var1Value= ConfigurationManager.AppSettings["Var1"];
    var var2Value = ConfigurationManager.AppSettings["Var2"];
    var var3Value = ConfigurationManager.AppSettings["Var3"];
    var conn1 = ConfigurationManager.ConnectionStrings["SQLConnectionString01"];
    var conn2 = ConfigurationManager.ConnectionStrings["SQLConnectionString02"];

    Console.WriteLine("Values from config01.config and connString01.config files");

    Console.WriteLine("Var2={0}", var2Value);
    Console.WriteLine("Var3={0}", var3Value);
    Console.WriteLine("ConnStr01={0}", conn1);
    Console.WriteLine("ConnStr01={0}", conn2);


The complete source code can be downloaded from this link.

Add EULA to ClickOnce Installation using Visual Studio 2015

ClickOnce technology is very smart and useful when you want simple, small and smart piece of software for deploying your Windows Forms or WFP application. This is specially useful if you deliver application which doesn’t require administrator rights during installation. ClickOnce is very powerful if you wants automatic update of your product, you can decide whenever the update appears before or after app is run. Also by using certificate you can deliver reliable and secure product to your customers. Long time ago I wrote detailed blog post  how to make ClickOnce deployment.

But one big thing is missing in ClickOnce deployment and for most of dev community is the feature which should be included by default. The feature which missing is “End User License Agreement” (EULA).  There is no simple way to implement it. Searching the internet I have found one forum post on Microsoft site describing how to implement it. Only way you can get ELUA at the beginning of the ClickOnce installation proces is by using it as prererquested component. Actually you build a redistributable component which would be seen as prerequsites dialog box under the publish window. To build custom prerequisites component you need a three files:

  1. Product.xml. – which is the file for bootstrapper and Visual Studio to show  a component in prerequisites dialog,
  2. Package.xml – which is the file containing all information about the component to be installed,
  3. EULA.txt – your ELUA text for user to accept.

Those three files must be installed in the location where all components are registered: C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper\Packages

For this blog post I have prepare demo sample which look like the following picture:


As can be seen, there is a two folders and one xml file. Each folder contains two files described earlier. Folders “en” and “de” means we are going to have EULA translated on two languages.

In order to successfully registered perquisites to be visible by Visual Studio we need to define proper content of the product.xml. The following xml code show content of our demo sample:

<?xml version="1.0" encoding="utf-8" ?>

<Product xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper" ProductCode="EULA.Bootstrap.Component">
  <!-- Defines list of files to be copied on build -->
    <PackageFile Name="en/eula.txt"/>
    <!-- Open eula.txt without any parameters -->
    <Command PackageFile="en/eula.txt" Arguments='' >
	  <!-- These checks determine whether the package is to be installed -->
	  <!-- No install conditions -->
	   <!-- Exit codes -->
        <ExitCode Value="0" Result="Success" />
        <DefaultExitCode Result="Fail" FormatMessageFromSystem="false" String="GeneralFailure" />


As we can see xml content is self-described, it contains product information, files to be installed, installation conditions and exit codes.

Each folder (en, de, …) contains package.xml file which holds localized messages and list of files to copied on build. The following xml content shows content of our en demo sample:

<?xml version="1.0" encoding="utf-8" ?>
<Package xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper" Name="ClickOnceWithLicenseAgreement" Culture="Culture" LicenseAgreement="eula.txt">
  <!-- Defines list of files to be copied on build -->
        <PackageFile Name="eula.txt"/>

  <!-- Defines a localizable string table for error messages and url's -->
    <String Name="DisplayName">ClickOnceWithLicenseAgreement 1.0 (x86 and x64)</String>
    <String Name="Culture">en</String>

    <String Name="CancelFailure">User Refuse to Accept to ClickOnceWithLicenseAgreement End User License Agreement.</String>
    <String Name="GeneralFailure">A fatal error occurred during the installation of ELUA Component Execution</String>
    <String Name="AdminRequired">You do not have the permissions required to install this application.  Please contact your administrator.</String>

The EULA.txt file contains the text user need to accept in order to install the product.

For this demo we created folder EULAPackage, put product.xml and two folders en and de because we are going to support two installation languages (see picture above).

Copy the EULAPackage folder in to : C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper\Packages

Now we have set all necessary information about ELUA component and can be included in our demo sample.

  1. Open Visual Studio 2015 and create new WFP application.Name it as “ClickOnceWithLicenseAgreement


2. Right-Click on the Project and select Property menu option, then select Publish tab item of the Project Property window.


3. Click on Prerequisites Button, then you will see your prerequisite component in the standard prerequisites lists.


4. Select ClickOnceWithLicenseAgreement component and click Ok button. Afterwards click Publish button to build installation package.

5. Open publish folder from the disk. DoubleClick Setup.exe and the ELUA window should be appeared:


6. Now user has two choises to accept or Refuse the EULA, which means install or not install the app.

Prerequested demo sample component for EULA can be downloaded from here.

Happy programming.