Visual Studio provide the many inbuilt templates for create a project, In this article we can create a new project template as per your client or product requirement and use the your project template on multiple developer. Visual Studio provides wizards to help you generate templates from projects that are open in the integrated development environment (IDE).

Project template will allow a developer to create new projects based on your exported project. The developer will be able to utilize your template for the new project dialog box


Create New Project:

Let start with creating a new Xamarin or any Project using visual studio 2017.

Open Run > Type Devenev.Exe and press Enter > New Project (Ctrl+Shift+N) -> Select any project Template and customize the project as per your requirement.


Click on Ok and edit the project until it is ready to be exported as a template.

Export Project Template:

In this article, we are export only one project. If you have more than one project in your current solution, I will explain in my next article.

Edit the project as per your requirement > Select the project menu from Visual Studio > Select on Export Template.


Choose template Type:

Choose the project template and select your project and click on Next


Export Template Wizard:

Fill out the template options as you want and click on Finish

Provide Template Name is Project template display name .

Provide Template Description is a detailed description about your template

Provide Icon Image and icon image will display near to the project Template name

Provide preview image and preview image will display near to describe.

Check the checkbox for auto import the template into visual studio or after export, will generate zip file and you can move the zip file to following location C:\Users\<username>\Documents\Visual Studio 2017\Templates\ProjectTemplates


Edit Template:

The file explorer should pop up with My Exported Templates where your newly exported project is packed into a .zip file.


You can extract the template and if you want to edit the template, edit form MyTemplate.vstemplate file .

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>csharpcornerProjectTemplate</Name>
<Description>csharpcornerProjectTemplate</Description>
<ProjectType>CSharp</ProjectType>
<ProjectSubType>
</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>csharpcornerProjectTemplate</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>__TemplateIcon.png</Icon>
<PreviewImage>__PreviewImage.png</PreviewImage>
</TemplateData>
<TemplateContent>
<Project TargetFileName="csharpcornerProjectTemplate.csproj" File="csharpcornerProjectTemplate.csproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="true" TargetFileName="App.xaml">App.xaml</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="App.xaml.cs">App.xaml.cs</ProjectItem>
<Folder Name="Assets" TargetFolderName="Assets">
<ProjectItem ReplaceParameters="false" TargetFileName="LockScreenLogo.scale-200.png">LockScreenLogo.scale-200.png</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="SplashScreen.scale-200.png">SplashScreen.scale-200.png</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Square150x150Logo.scale-200.png">Square150x150Logo.scale-200.png</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Square44x44Logo.scale-200.png">Square44x44Logo.scale-200.png</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Square44x44Logo.targetsize-24_altform-unplated.png">Square44x44Logo.targetsize-24_altform-unplated.png</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="StoreLogo.png">StoreLogo.png</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Wide310x150Logo.scale-200.png">Wide310x150Logo.scale-200.png</ProjectItem>
</Folder>
<ProjectItem ReplaceParameters="false" TargetFileName="csharpcornerProjectTemplate_TemporaryKey.pfx">csharpcornerProjectTemplate_TemporaryKey.pfx</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="MainPage.xaml">MainPage.xaml</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="MainPage.xaml.cs">MainPage.xaml.cs</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Package.appxmanifest">Package.appxmanifest</ProjectItem>
<Folder Name="Properties" TargetFolderName="Properties">
<ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Default.rd.xml">Default.rd.xml</ProjectItem>
</Folder>
</Project>
</TemplateContent>
</VSTemplate>

Custom Visual Studio template:

You can now restart Visual studio and go to New Project in Visual Studio and find the Project template like below

After click on Ok , project will automatically create new project with your default functionality .


Summary:

In this article, you learned how to create a project template using visual studio

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











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.












Featured Post

How to Get an Free Azure Subscription for Learning

This guide will help you get started with Microsoft Azure for free. It explains three easy ways: using a Free Azure Account Signing up for A...

MSDEVBUILD - English Channel

MSDEVBUILD - Tamil Channel

Popular Posts