The .NET Standard Library is a formal specification of .NET APIs that are intended to be available on all .NET runtimes. You can understand another way its expanded, Portable Class Library. It is a single library with a uniform API for all .NET Platforms including .NET Core. You just create a single .NET Standard Library and use it from any runtime that supports .NET Standard Platform.

You can refer following table lists all the versions of .NET Standard and the platforms supported



In this article, you will learn how to create mobile cross platform application using Xamarin Forms with .NET Standard libraries and maximize code sharing.

Create New Xamarin Forms:

Let’s start create new Xamarin Forms application, In Windows machine > Go to Run (Windows key +R) > type Devenv.exe for open Visual Studio and select New project from File menu > New Project (ctrl +Shift+N) or click More project template from VS Start screen.



Click on Ok > You will get following screen. Select Blank App > Select Xamarin Forms UI Technology > Select Code sharing as PCL or Share Project and click on Ok



After click on Ok, VS will automatically create PCL,iOS,Android ,UWP projects .

Create .Net Standard Class library

You can follow below steps for create .Net Standard library,

Right Click on solutions > Add new project > Create Class library (.Net Standard) that targets .net Standard and click on Ok


Install Xamarin Forms in .Net Standard library:

The Xamarin.Forms 2.3.5-prerelease will support with .NET Standard. Right Click on .net Standard library > Select on Manage Nuget package



Select on Browse tab > Search text ‘ Xamarin.Forms ‘ > Select Include prerelease and select Xamarin Forms and click on Install


Customize the Application:

You can follow below steps for customize the platform specific project and .net standard library.

Step 1: 

 Right Click on .Net Standard library > Click on Add Item > Select Cross -Platform >Forms Blank Content Page Xaml > Provide name as MainPage.xaml


Step 2: 

You can add UI design as per your requirement in MainPage.xaml .

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DotNetStandard.MainPage">
<Label Text="Welcome to Xamarin.Forms Apps with .NET Standard!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</ContentPage>

Step 3:

 Copy App.cs and App.xaml from PCL or Shared project and past into .net Standard library and change the namespace from xaml and c# page



Step 4: Remove Shared or PCL Project and Remove PCl project reference from all iOS,Android,UWP project. Now solution look like below


Step 5: 

Add your .Net Standard class library reference to iOS,Android,UWP project.

Step 6:

 Change namespace from following project

In UWP project, updated the namespace from mainPage.cs

LoadApplication(new DotNetStandard.App());

In Android Project , Update the namespace from Main Activity

LoadApplication(new DotNetStandard.App());

In iOS Project , Update the namespace from Appdelegate

LoadApplication(new DotNetStandard .App());

Step 6:

 If you get following error while build the project



You can follow below for resolution Right Click on Xaml page > Select property and Build Action Should be Embedded Resource


Run the Application:

You can run the application (iOS,Android ,Windows) to all the platform



Summary

In this article, you learned how to create mobile cross platform application using Xamarin Forms with .NET Standard libraries.

If you have any questions/ feedback/ issues, please write in the comment box.




Introduction:

Microsoft Cognitive Services awesome APIs and services for developers to create more intelligent applications. You can add more interesting feature like people emotion and video detection, facial, speech and vision recognition and speech and language understanding into our all the application. The following sample image showing for emotion and face detection using cognitive service.



In this article, you will get understand how to Create a Cognitive Services APIs account in the Azure Portal.

Prerequisites:

Create a free trial Azure subscription from Azure portal.
If you are looking paid version, Click here for detail


Create a Cognitive Services Account in Azure:

You can follow below steps for Create a Cognitive Services APIs account in the Azure Portal.

Step 1: 

 Sign in to the Azure portal.

Step 2: 

Click + NEW and Select AI + Cognitive Services


Step 3: 

You can see the entire list of Cognitive Services APIs. Click on the API of your choice to proceed.


Step 4: 

Select on required API and read about the API and Click on Create


Step 5:

 after click on create button, provide the following information for create cognitive service and click on create.



Name: Name of the account, Microsoft recommend a descriptive name. for example, <common name><APIName>Account.
Subscription: Select the available Azure subscriptions.

Location: Select the service locations.

Pricing tier: you can choose your pricing tier. F0 is free service and S0 paid service. based on your usage you can choose the pricing tier


Select the Resource group > confirm the Microsoft notice and Click on create for create the account

Step 6:

 wait for few second and you will get notification after complete. If Cognitive Services account is successfully deployed, click the notification to view the account information.

You can see and copy the Endpoint URL in the Overview section.



You can also copy keys in the Keys section to start making API calls in our Xamarin or other applications.

Summary:

In this article, you learned about how to Create a Cognitive Services APIs account in the Azure Portal.

We can use these keys and end point URL to the next article with app to communicate intelligent feature in Xamarin application.

If you have any questions/ feedback/ issues, please write in the comment box.

Introduction:

Microsoft offer a different service in the Cloud, Mail, Calendar, Contact, Chat and files from common Microsoft portal and also if you want to integrate to your application, you can access unified API wrapper in the Microsoft graph SDK. In this article you will get understand, how to implement login authentication and Send mail using Microsoft graph API in the Xamarin Forms application


Prerequisites:

Download and install Visual 2017 Community Edition or higher.

Create Microsoft Account (If you already register Microsoft account, it’s not required)

Getting Start Create Application:

Step 1:

 You can navigate following URL https://developer.microsoft.com/en-us/graph/quick-start for register app and create sample app.

Step 2: 

Select the platform and Microsoft will create simple app that connects to Office 365 and calls the Microsoft Graph API.

Step 3: 

Register APP ID: You can register the application using click on “Get an app ID” and it will navigate to Microsoft application registration portal where you will be able to get an App ID and redirect URL. You will need either a School / Work /corporate / Azure AD or Microsoft account.


Step 4: 

Registration Success: after login with your Microsoft account and wait for few second appid and redirect url will generate automatically. if you want to modify or manage your app, you can click on application registration portal .

Step 5:

 Manage App in Registration Portal: You can manage or edit application from portal in the following App Name, redirect URL, generate new password, application logo, update the permission and click on Save button.


Step 6: 

Download Sample Code: you can download and unzip the source code > open the source code using Visual Studio. in the Sample application have multiple platform support as iOS, Android, UWP. The code sample will introduce you to authentication and send an email from your account.


Step 7: 

Microsoft Graph Client Library:

Microsoft Graph Client Library allows you to call Office 365, Azure AD and other Microsoft services through a single unified developer experience so right click on your solution and verify below NuGet package installed in the solution.


Step 8: 

Configure the project: Open the App.cs file from XamarinConnect PCL project > replace your client ID and add the user permission scope.
public static string ClientID = "< Update your Client ID > ";

public static PublicClientApplication IdentityClientApp = new PublicClientApplication(ClientID);

public static string[] Scopes = { "User.Read", "Mail.Send", "Files.ReadWrite" };

Step 9: 

Configure Send mail: Open the MainHelper.cs from XamarinConnect PCL project > update ComposeAndSendMailAsync method as per your requirement

public async Task ComposeAndSendMailAsync(string subject,string bodyContent,string recipients)
{

// Get current user photo
Stream photoStream = await GetCurrentUserPhotoStreamAsync();
// If the user doesn't have a photo, or if the user account is MSA, we use a default photo
if (photoStream == null)
{
var assembly = typeof(MailHelper).GetTypeInfo().Assembly;
photoStream = assembly.GetManifestResourceStream("XamarinConnect.test.jpg");
}
MemoryStream photoStreamMS = new MemoryStream();
// Copy stream to MemoryStream object so that it can be converted to byte array.
photoStream.CopyTo(photoStreamMS);
DriveItem photoFile = await UploadFileToOneDriveAsync(photoStreamMS.ToArray());
MessageAttachmentsCollectionPage attachments = new MessageAttachmentsCollectionPage();
attachments.Add(new FileAttachment
{
ODataType = "#microsoft.graph.fileAttachment",
ContentBytes = photoStreamMS.ToArray(),
ContentType = "image/png",
Name = "me.png"
});
// Get the sharing link and insert it into the message body.
Permission sharingLink = await GetSharingLinkAsync(photoFile.Id);
string bodyContentWithSharingLink = String.Format(bodyContent, sharingLink.Link.WebUrl);
// Prepare the recipient list
string[] splitter = { ";" };
var splitRecipientsString = recipients.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
List<Recipient> recipientList = new List<Recipient>();
foreach (string recipient in splitRecipientsString)
{
recipientList.Add(new Recipient { EmailAddress = new EmailAddress { Address = recipient.Trim() } });
}
try
{
var graphClient = AuthenticationHelper.GetAuthenticatedClient();
var email = new Message
{
Body = new ItemBody
{
Content = bodyContentWithSharingLink,
ContentType = BodyType.Html,
},
Subject = subject,
ToRecipients = recipientList,
Attachments = attachments
};
try
{
await graphClient.Me.SendMail(email, true).Request().PostAsync();
}
catch (ServiceException exception)
{
throw new Exception("We could not send the message: " + exception.Error == null ? "No error message returned." : exception.Error.Message);
}
}
catch (Exception e)
{
throw new Exception("We could not send the message: " + e.Message);
}
}

Step 9: Run the Application:

Select iOS,android and Windows project and run the application .

Click on Connect Button from iOS/Android /Windows


Sign in with your personal or work or school account and grant the requested permissions.



4. Click on Send mail button. When the mail is sent, a Success message is displayed.

This mail message includes the photo as an attachment and also provides a sharing link to the uploaded file in OneDrive. Check your mail from Inbox or Spam.


Download Source Code:

You can download the complete source code from MSDN sample. 


Summary:

In this article, you learned about how to implement login authentication and Send mail using Microsoft graph API in the Xamarin Forms application.

If you have any questions/ feedback/ issues, please write in the comment box.

Introduction:

The Bots Framework that run inside skype ,web chat , Facebook ,Message ,etc. Users can interact with bots by sending them messages, commands and inline requests. You control your bots using HTTPS requests to our bot API.

In this article, how you can integrate a bot right into your Xamarin.Forms application via the Microsoft Bot Framework Web bots.


Create new bot Application:

You can read my previous article for Getting Started with Bots Using Visual Studio 2017 from following URL http://www.c-sharpcorner.com/article/getting-started-with-bots-using-visual-studio-2017/


Publish Bot Application to Azure:

You can read my previous articles for publish bot application to azure from following URL http://www.c-sharpcorner.com/article/getting-started-deploy-a-bot-to-azure-using-visual-studio-2017/

Generate Web Chat Code:

After publish you bots into azure, you can generate web Chat html code from bots portal as per below

Step 1

Sign in to the Bot framework Portal - https://dev.botframework.com/

Step 2

Click My Bots

Step 3

Select your bot that you want to generate code

Step 4:

Click on Get bot embed Codes > Click on Web Chat icon > Click on (Click here to open Web Chat configuration page)


Step 5:

It will navigate to new web page for configuration and click on + Add New Site > Provide site or application name > Click on Done


Step 6:

You can copy your secret keys and embed code for integrate to xamarin forms application


Create new Xamarin .Forms Application :

Go to Run (Windows key +R) > type Devenv.exe or select from Windows Application list and select New project from File menu > New Project (ctrl +Shift+N) or click More project template from VS Start screen.



New Project >select Cross -Platform from Template > Cross platform App(Xamarin.Forms or native). It will show the screen, as shown below.



You can find above screen only on VS 2017. Select Blank apps > select Xamarin.Forms > Select PCL and click on Ok .it will generate all the mobile platform project with PC



Open your MainPage.xaml file add webview control with following code for web chat enable
<StackLayout WidthRequest="300" HeightRequest="500" >
<Image Source="profile.png" WidthRequest="200" HeightRequest="200"></Image>
<Label Text="Live Chat with Suthahar via C Sharp corner" FontSize="20" ></Label>
<WebView x:Name="webview" Source="https://webchat.botframework.com/embed/DevEnvExeBot?s=8XGcUROXkAA.cwA.pZo.8pJ-6oQ3sJRpxq0tqIo9uLPji4oxBQuz2pW5qWobw2c"
WidthRequest="300" HeightRequest=" 300"></WebView>
</StackLayout>

Now you can run the application in windows ,Android and iOS


Download

You can download the complete source code from MSDN sample.


Summary

In this article, your learned how to create a Bot application, publish Bot to Azure and bot implementation to Xamarin Forms using Visual Studio 2017. If you have any questions/ feedback/ issues, please write in the comment box.












Introduction:

The Azure Bot Service is powered by the Microsoft Bot Framework and bot service allows developers to build conversational applications that plug into many popular chat applications including Facebook Messenger, Skype and Office 365, etc. In this article, we can be creating and testing a bot by using the Azure Bot Service.



Create new Bot Service:

Logon to the Azure portal with your registered Azure Microsoft account. If you don’t have azure subscription, you can Create a free trial Azure subscription from Azure portal.
In Azure Portal > click on + Add > Select on Data Analytics


Step 1:

 Select on new Bot service from data analytics menu


Step 2: 

You can provide following information for create new bot service unique App name to your bot’s name. The name is used as the subdomain in azure website (eg DevEnvExeBot.azurewebsites.net).
Select the Azure subscription.
Select the resource group or create new user group.

Select the location. And click on Create button


Step 3:

 After clicking on Create button, wait a few minutes for the Bot Service to be deployed successfully before proceeding. You will get confirmation notification for after success.


Register Bot Application:

You can click on confirmation notification. then, you will get the following screen where you need to create App ID. This is a prerequisite to authenticating your bot with the bot framework.

Step 1: 

Click on Create Microsoft App ID and Password


Step 2: 

App ID and password will generate following screen and click on button for go back to Bot framework


Step 3: 

Select the Programming language and template for developing bot application

Step 4: 

Now bot application successfully created and running in the cloud, you can edit code from Azure Develop code editor and also you can manage channels, analytics and setting.


Test Bot Application:

You can click on Test button and provide sample input text.


Summary

In this article, your learned about create and test a bot by using the Azure Bot Service. If you have any questions/ feedback/ issues, please write in the comment box.

Featured Post

AI Evolution Explained: GenAI vs LLMs vs AI Agents vs Agentic AI vs Intelligent AI

Artificial Intelligence (AI) is one of the most exciting technologies in our world today. But the terms that come with it like GenAI, LLMs, ...

MSDEVBUILD - English Channel

MSDEVBUILD - Tamil Channel

Popular Posts