<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.NET &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/category/dotnet/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Fri, 13 Oct 2023 09:57:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>.NET &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>.NET 8 New and Efficient Way to Check IP is in Given IP Range</title>
		<link>https://www.sibeeshpassion.com/net-8-new-and-efficient-way-to-check-ip-is-in-given-ip-range/</link>
					<comments>https://www.sibeeshpassion.com/net-8-new-and-efficient-way-to-check-ip-is-in-given-ip-range/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Fri, 13 Oct 2023 09:54:45 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET8]]></category>
		<category><![CDATA[DOTNET8]]></category>
		<category><![CDATA[How to check IP is in IP Ranges]]></category>
		<category><![CDATA[IP in IP Ranges]]></category>
		<category><![CDATA[IPNetwork Class DOTNET8]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=14633</guid>

					<description><![CDATA[The .NET 8 has introduced a new type IPNetwork with a Contains method. It retruns true if the given IPAddress is part of the IP network. Otherwise, returns false. Here in this post, we will see how we can implement the same.]]></description>
										<content:encoded><![CDATA[
<p>In our <a href="https://sibeeshpassion.com/async-client-ip-safelist-for-dot-net/" data-type="link" data-id="https://sibeeshpassion.com/async-client-ip-safelist-for-dot-net/">last post</a> we have seen how we can restrict the access to your application by implementing IP restrictions using ActionFilterAttribute but we were checking the IP addresses and was missing a feature to support the IP Ranges. The good news is that the .NET 8 has a new and efficient way to do this. Here in this post, we will see how we can implement the same. Let&#8217;s begin. </p>



<h1 class="wp-block-heading">Source Code</h1>



<p>You can also see the codes in&nbsp;<a href="https://github.com/SibeeshVenu/DotNetIpFilter/" target="_blank" rel="noreferrer noopener">this repository</a>.</p>



<h1 class="wp-block-heading">Enablling .NET8 for Your Application</h1>



<p>As you might have already guessed, the first step is to download the .NET8 from <a href="https://dotnet.microsoft.com/en-us/download/dotnet/8.0" data-type="link" data-id="https://dotnet.microsoft.com/en-us/download/dotnet/8.0">here</a>. Let&#8217;s now change the TargetFramework in our both <code>DotNetIpFilter.csproj</code> and <code>DotNetIpFilter.Test.csproj</code> files. You can get the application code from the repositroy mentioned above. </p>



<pre class="wp-block-code"><code>&lt;TargetFramework&gt;net8.0&lt;/TargetFramework&gt;</code></pre>



<p>You will also need to update your <code>Microsoft.AspNetCore.OpenApi</code> package to .NET8.</p>



<h2 class="wp-block-heading">Enable Preview .NET 8 in Visual Studio 2022</h2>



<p>If you are trying to create a new application using Visual Studio 200, you may be missing an option to chose the .NET8 framework, to mak sure to get this option, do the following. </p>



<p>1. Update your Visual Studio 2022</p>



<p>2. Go to Tools -&gt; Manage Preview Features</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><a href="/wp-content/uploads/2023/10/image.png"><img fetchpriority="high" decoding="async" width="696" height="1024" src="/wp-content/uploads/2023/10/image-696x1024.png" alt="" class="wp-image-14636" style="aspect-ratio:0.6796875;width:336px;height:auto" srcset="/wp-content/uploads/2023/10/image-696x1024.png 696w, /wp-content/uploads/2023/10/image-204x300.png 204w, /wp-content/uploads/2023/10/image-768x1130.png 768w, /wp-content/uploads/2023/10/image-400x588.png 400w, /wp-content/uploads/2023/10/image-408x600.png 408w, /wp-content/uploads/2023/10/image.png 1038w" sizes="(max-width: 696px) 100vw, 696px" /></a><figcaption class="wp-element-caption">.NET 8 Manage Preview Features</figcaption></figure>
</div>


<p>3. Select checkbox <code>Use preview of the .NET SDK (requires restart)</code></p>



<p>4. Make sure to restart after enabling this</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><a href="/wp-content/uploads/2023/10/image-1.png"><img decoding="async" width="1024" height="655" src="/wp-content/uploads/2023/10/image-1-1024x655.png" alt="" class="wp-image-14637" style="aspect-ratio:1.5633587786259542;width:550px;height:auto" srcset="/wp-content/uploads/2023/10/image-1-1024x655.png 1024w, /wp-content/uploads/2023/10/image-1-300x192.png 300w, /wp-content/uploads/2023/10/image-1-768x491.png 768w, /wp-content/uploads/2023/10/image-1-1536x982.png 1536w, /wp-content/uploads/2023/10/image-1-2048x1310.png 2048w, /wp-content/uploads/2023/10/image-1-400x256.png 400w, /wp-content/uploads/2023/10/image-1-938x600.png 938w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption class="wp-element-caption">Use .NET Previews of the .NET SDK</figcaption></figure>
</div>


<h1 class="wp-block-heading">Use .NET8 Contains Method from <code>IPNetwork</code></h1>



<p>Let&#8217;s change our IpActionFilter.cs file code as below, to use the Contains method from .NET8 IPNetwork class. </p>



<script src="https://gist.github.com/SibeeshVenu/3700843ab923f85e192b0bded299327d.js"></script>



<p>In the code above the variable addressRange is a string that represents IP Address Range and ipAddressToCheck is the IP Address to check. The code for the IPNetwork is&nbsp;<a href="https://github.com/dotnet/aspnetcore/blob/main/src/Middleware/HttpOverrides/src/IPNetwork.cs">here</a>. You can learn more about this IPNetwork.Contains(IPAddress) method&nbsp;<a href="https://learn.microsoft.com/en-us/dotnet/api/system.net.ipnetwork.contains?view=net-8.0#system-net-ipnetwork-contains(system-net-ipaddress)">here</a>. Make sure to select the version .NET 8 for the doc. If you can&#8217;t use .Net 8, you can implement your own class by taking the code from&nbsp;<a href="https://github.com/dotnet/aspnetcore/blob/main/src/Middleware/HttpOverrides/src/IPNetwork.cs">here</a>.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>I also have a detailed StackOverflow answer <a href="https://stackoverflow.com/a/76928408/5550507" data-type="link" data-id="https://stackoverflow.com/a/76928408/5550507">here</a> on this topic.</p>
<cite>StackOverflow answer</cite></blockquote>



<h1 class="wp-block-heading">Test IP Filtering with Ranges</h1>



<p>Now, it is time to test our new implementation. Go to the <code>IpFilterService.cs</code> file and then edit the <code>GetAdminSafeIpList</code> method. Assign a few IP address ranges to the variable ipListArray, remember this is where you get a list of IP addresses and ranges from any of your middleware service using an async function. To make it simpler, I am assigning some of the IP addresses and ranges to that variable manually. </p>



<p>When you run the application you can see that the addresses and the ranges we set is getting validated in our <code>OnActionExecuting</code> method in <code>IpActionFilter.cs</code>. </p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><a href="/wp-content/uploads/2023/10/image-5.png"><img decoding="async" width="1024" height="548" src="/wp-content/uploads/2023/10/image-5-1024x548.png" alt="" class="wp-image-14641" srcset="/wp-content/uploads/2023/10/image-5-1024x548.png 1024w, /wp-content/uploads/2023/10/image-5-300x161.png 300w, /wp-content/uploads/2023/10/image-5-768x411.png 768w, /wp-content/uploads/2023/10/image-5-1536x822.png 1536w, /wp-content/uploads/2023/10/image-5-400x214.png 400w, /wp-content/uploads/2023/10/image-5-1121x600.png 1121w, /wp-content/uploads/2023/10/image-5.png 2000w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption class="wp-element-caption">Compare IP Addresses and Ranges</figcaption></figure>
</div>


<p>The Contains method retruns true if the given IPAddress is part of the IP network. Otherwise, returns false.</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><a href="/wp-content/uploads/2023/10/image-3.png"><img decoding="async" width="1024" height="206" src="/wp-content/uploads/2023/10/image-3-1024x206.png" alt="" class="wp-image-14639" style="aspect-ratio:4.970873786407767;width:825px;height:auto" srcset="/wp-content/uploads/2023/10/image-3-1024x206.png 1024w, /wp-content/uploads/2023/10/image-3-300x60.png 300w, /wp-content/uploads/2023/10/image-3-768x155.png 768w, /wp-content/uploads/2023/10/image-3-1536x310.png 1536w, /wp-content/uploads/2023/10/image-3-400x81.png 400w, /wp-content/uploads/2023/10/image-3.png 1861w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption class="wp-element-caption">Returns false when IP Address is not in Ranges</figcaption></figure>
</div>


<p>If you inspect the Contains method, you can see the code as below. This works with both IPV4 and IPV6. </p>



<script src="https://gist.github.com/SibeeshVenu/cd88ae1dcc383a6f1596e4a8eef270da.js"></script>



<h1 class="wp-block-heading">Conclusion</h1>



<p>In this post we have seen how easily we can check an IP address is in a given IP address ranges or not. Before this .Net8 release, we had to have our own implementaion, but now it is so easy and less codes. Less code is less maintenance, right. The .NET8 has many features just like this, checkout <a href="https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8" data-type="link" data-id="https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8">here</a>. </p>



<h1 class="wp-block-heading">About the Author</h1>



<p>I am yet another developer who is passionate about writing and sharing knowledge. I have written more than 500 blogs on my&nbsp;<a rel="noreferrer noopener" href="https://sibeeshpassion.com/" target="_blank">blog</a>. If you like this content, consider following me here,</p>



<ul class="wp-block-list">
<li><a href="https://github.com/SibeeshVenu">GitHub</a></li>



<li><a href="https://medium.com/@sibeeshvenu">medium</a></li>



<li><a href="https://twitter.com/sibeeshvenu">Twitter</a></li>
</ul>



<h1 class="wp-block-heading">Your turn. What do you think?</h1>



<p>Thanks a lot for reading. Did I miss anything that you may think is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/net-8-new-and-efficient-way-to-check-ip-is-in-given-ip-range/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Async Client IP safelist for Dot NET</title>
		<link>https://www.sibeeshpassion.com/async-client-ip-safelist-for-dot-net/</link>
					<comments>https://www.sibeeshpassion.com/async-client-ip-safelist-for-dot-net/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Fri, 11 Aug 2023 13:58:43 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Action filters in dot net 7]]></category>
		<category><![CDATA[Async call on Program file]]></category>
		<category><![CDATA[Async Client IP safelist for ASP.NET Core]]></category>
		<category><![CDATA[Async Startup]]></category>
		<category><![CDATA[IP Restrictions on Net 7]]></category>
		<category><![CDATA[Net 7 Web API]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=14617</guid>

					<description><![CDATA[Here, in this post we will see, how we can get the Safe List IP addresses asynchronously and add that to configure our ActionFilterAttribute and apply the same to the Web API to make sure that the unidentified requests gets 403 Forbidden.]]></description>
										<content:encoded><![CDATA[
<p>I have a .Net Web API project and I wanted to implement a mechanism via code to make sure that only certain IP addresses are allowed to call that API. We could do this by configuring the networking rules, Virtual Network, NSG implementations or even Azure App Access Restrictions if we host the Web API in an Azure App Service. However, the reason why I wanted to implement this via code is that the IP addresses list gets updated frequently and I wanted to make sure that there is very less maintenance on the service. Here, in this post we will see, how we can get the Safe List IP addresses asynchronously and add that to configure our ActionFilterAttribute and apply the same to the Web API to make sure that the unidentified requests gets 403 Forbidden.</p>



<h2 class="wp-block-heading">Create an IP Action Filter</h2>



<p>Before you do this, I assume that you already have the .Net Web API. For this post I am using .Net 7. Create a Services folder and then create a class IpActionFilter that is inherited from ActionFilterAttribute.</p>



<script src="https://gist.github.com/SibeeshVenu/cb8e6850d8809247847063ca44ec6dd7.js"></script>



<p>The implementation is a clone of this <a href="https://learn.microsoft.com/en-us/aspnet/core/security/ip-safelist?view=aspnetcore-7.0#action-filter">doc</a>. As you can see from that doc, there it the safe IP addresses list are static and is added to the App Settings manually. However in my scenario, I had to get this from an Async service call.</p>



<h1 class="wp-block-heading">Get the IP addresses from an Asyn service call</h1>



<p>We will create a new Service IpFilterService that implements IIpFilterService. Here we will mimic the async call to make this post more concrete. </p>



<script src="https://gist.github.com/SibeeshVenu/9a016d75d5c43173e1df9bf5f55a3b9b.js"></script>



<script src="https://gist.github.com/SibeeshVenu/dad0b02781b69c76515934e2bff88347.js"></script>



<h1 class="wp-block-heading">Async call to set the configuration</h1>



<p>If you just have a few IP addresses that can easily set in the App Settings. You can just add them manually as in this <a href="https://learn.microsoft.com/en-us/aspnet/core/security/ip-safelist?view=aspnetcore-7.0#ip-address-safelist">post</a>. As I wanted to update this list via an async service call, there are a few additional changes we must do. One of them is creating a Hosted Service that implements IHostedService and add that to the builder using builder.Services.AddHostedService. Let&#8217;s create IpHostedService. </p>



<script src="https://gist.github.com/SibeeshVenu/21bc246fddc07aad9b04ded1f02b4900.js"></script>



<p>As you can see from the code above, we are setting the AdminSafeIpList configuration to our App Settings via the code. Now all we need to add is to add this to the builder. </p>



<h1 class="wp-block-heading">Configure the builder</h1>



<p>To make sure that the AdminSafeIpList is updated to the App Settings, we will need to add our IpHostedService as a HostedService. You can learn more about this service <a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-7.0&amp;tabs=visual-studio">here</a>. The code for Program.cs after this changes is below. </p>



<script src="https://gist.github.com/SibeeshVenu/a857e6b16005eb36b8161bfc000fdaf8.js"></script>



<p>So we are passing the AdminSafeIpList to the IpActionFilter. </p>



<h1 class="wp-block-heading">Enable IpActionFilter as a ServiceFilter</h1>



<p>As we have implemented the action filter and other required services, we now can add the IpActionFilter as a ServiceFilter in the controller or the actions. Add the code [ServiceFilter(typeof(IpActionFilter))] to top of controller or actions. </p>



<script src="https://gist.github.com/SibeeshVenu/9412bd9798bf78fc3d1ae62abdc61e50.js"></script>



<h1 class="wp-block-heading">Finally, Add some unit tests</h1>



<p>Let&#8217;s try to add some unit tests for our IpActionFilter.</p>



<script src="https://gist.github.com/SibeeshVenu/a92f899949943b044acc644ae3a118fa.js"></script>



<h1 class="wp-block-heading">Output</h1>



<p>Let&#8217;s build and run our API. You should see the preceeding response. </p>



<p><strong>With External IPs:</strong></p>



<figure class="wp-block-image size-large"><a href="/wp-content/uploads/2023/08/403-Forbidden-Result.png"><img decoding="async" width="1024" height="607" src="/wp-content/uploads/2023/08/403-Forbidden-Result-1024x607.png" alt="" class="wp-image-14619" srcset="/wp-content/uploads/2023/08/403-Forbidden-Result-1024x607.png 1024w, /wp-content/uploads/2023/08/403-Forbidden-Result-300x178.png 300w, /wp-content/uploads/2023/08/403-Forbidden-Result-768x455.png 768w, /wp-content/uploads/2023/08/403-Forbidden-Result-400x237.png 400w, /wp-content/uploads/2023/08/403-Forbidden-Result-1012x600.png 1012w, /wp-content/uploads/2023/08/403-Forbidden-Result.png 1255w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<p><strong>With Internal IPs:</strong></p>



<figure class="wp-block-image size-large is-resized"><a href="/wp-content/uploads/2023/08/Without-IP-restrictions.png"><img decoding="async" src="/wp-content/uploads/2023/08/Without-IP-restrictions-839x1024.png" alt="" class="wp-image-14620" style="width:840px;height:1024px" width="840" height="1024" srcset="/wp-content/uploads/2023/08/Without-IP-restrictions-839x1024.png 839w, /wp-content/uploads/2023/08/Without-IP-restrictions-246x300.png 246w, /wp-content/uploads/2023/08/Without-IP-restrictions-768x937.png 768w, /wp-content/uploads/2023/08/Without-IP-restrictions-400x488.png 400w, /wp-content/uploads/2023/08/Without-IP-restrictions-492x600.png 492w, /wp-content/uploads/2023/08/Without-IP-restrictions.png 846w" sizes="(max-width: 840px) 100vw, 840px" /></a></figure>



<h1 class="wp-block-heading">Source Code</h1>



<p>You can also see the codes in&nbsp;<a href="https://github.com/SibeeshVenu/DotNetIpFilter/" target="_blank" rel="noreferrer noopener">this repository</a>.</p>



<h1 class="wp-block-heading">Conclusion</h1>



<p>Here in this post we have seen,</p>



<p>1. How we can restrict the accesse to our Web APIs by providing the Safe IP addresses list</p>



<p>2. How to create a new Action Filter and use that for Controllers</p>



<p>3. One of the challenge was to get the IP Address safe list from an Async service call and update the App Settings. </p>



<h1 class="wp-block-heading">About the Author</h1>



<p>I am yet another developer who is passionate about writing and video creation. I have written more than 500 blogs on my&nbsp;<a rel="noreferrer noopener" href="https://sibeeshpassion.com/" target="_blank">blog</a>. If you like this content, consider following me here,</p>



<ul class="wp-block-list">
<li><a href="https://github.com/SibeeshVenu">GitHub</a></li>



<li><a href="https://medium.com/@sibeeshvenu">medium</a></li>



<li><a href="https://twitter.com/sibeeshvenu">Twitter</a></li>
</ul>



<h1 class="wp-block-heading">Your turn. What do you think?</h1>



<p>Thanks a lot for reading. Did I miss anything that you may think is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/async-client-ip-safelist-for-dot-net/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Migrate or Port Your Old Legacy .NET Projects to the .NET5</title>
		<link>https://www.sibeeshpassion.com/migrate-or-port-your-old-legacy-net-projects-to-the-net5/</link>
					<comments>https://www.sibeeshpassion.com/migrate-or-port-your-old-legacy-net-projects-to-the-net5/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 02 Jun 2021 15:10:50 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.net framework to .net core]]></category>
		<category><![CDATA[.net migration]]></category>
		<category><![CDATA[.net5]]></category>
		<category><![CDATA[amazon dot net tool for migration]]></category>
		<category><![CDATA[dotnet 5]]></category>
		<category><![CDATA[migrate legacy application to .net5]]></category>
		<category><![CDATA[migrate old .net to new]]></category>
		<category><![CDATA[port from .net framework to .net5]]></category>
		<category><![CDATA[porting assistant .net tool]]></category>
		<category><![CDATA[porting assistant for .net]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=14339</guid>

					<description><![CDATA[If you are looking for a tool to migrate your legacy old .NET framework projects to the .NET5 version, then you are in the right place. Recently, I got a chance to migrate one legacy application to .NET5, and here in this post, I will be explaining the steps.]]></description>
										<content:encoded><![CDATA[
<p>The word migration means a lot to us, developers, every day we upgrade ourselves by learning new technologies and the situation should not be different when we work on the legacy application. That&#8217;s when the use of some cool migration tools coming into the picture. If you are looking for a tool to migrate your legacy old .NET framework projects to the .NET5 version, then you are in the right place. Recently, I got a chance to migrate one legacy application to .NET5, and here in this post, I will be explaining the steps. Throughout the process, I will be using two different tools, &#8220;Porting assistant for .NET&#8221; by Amazon and .NET Upgrade Assistant by Microsoft. Both tools are Open Source and maintained by the community, free to use. Let&#8217;s get started.</p>



<h1 class="wp-block-heading">Prerequisites </h1>



<p>Download the Targeting framework, and install it. In my case, NET5. You can download them from <a rel="noreferrer noopener" href="https://dotnet.microsoft.com/download/dotnet/5.0" target="_blank">here</a>.</p>



<h2 class="wp-block-heading">Upgrade Assistant tool by Microsoft</h2>



<p>If you choose to use the Upgrade Assistant tool by Microsoft, all you have to do is to <a rel="noreferrer noopener" href="https://visualstudio.microsoft.com/downloads/?WT.mc_id=DT-MVP-5001828" target="_blank">install visual studio</a>,  install the <a rel="noreferrer noopener" href="https://github.com/dotnet/try-convert" target="_blank">try-convert tool</a> by running the preceding command.</p>



<pre class="wp-block-code"><code>Install try-convert: dotnet tool install -g try-convert
Update try-convert: dotnet tool update -g try-convert</code></pre>



<p>Now install the upgrade assistant by executing the below command.</p>



<pre class="wp-block-code"><code>dotnet tool install -g upgrade-assistant</code></pre>



<p>Just like any other tools, to update the tool, just run the below command. </p>



<pre class="wp-block-code"><code>dotnet tool update -g upgrade-assistant</code></pre>



<p>To get more info about the installation, you can visit <a rel="noreferrer noopener" href="https://github.com/dotnet/upgrade-assistant#installation" target="_blank">this document</a>.</p>



<h2 class="wp-block-heading">Porting Assistant tool by Amazon</h2>



<p>If choose to use this tool, please make sure that you have done the preceding things.</p>



<ul class="wp-block-list"><li>Signup an <a rel="noreferrer noopener" href="https://aws.amazon.com/free/" target="_blank">account with AWS</a></li><li>Log in to the AWS account and collect the security credentials. We will be using this info in our migration. Visit <a rel="noreferrer noopener" href="https://console.aws.amazon.com/iam/home?#/security_credentials" target="_blank">this site</a>, click on the Access Keys section, and then click on the Create New Access Key button. This will generate a new key, download the same and keep it in a safe location. </li></ul>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/06/image.png"><img decoding="async" width="1024" height="776" src="/wp-content/uploads/2021/06/image-1024x776.png" alt="" class="wp-image-14340" srcset="/wp-content/uploads/2021/06/image-1024x776.png 1024w, /wp-content/uploads/2021/06/image-300x227.png 300w, /wp-content/uploads/2021/06/image-768x582.png 768w, /wp-content/uploads/2021/06/image-1536x1164.png 1536w, /wp-content/uploads/2021/06/image.png 2035w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Amazon access keys</figcaption></figure></div>



<ul class="wp-block-list"><li>Go to this <a rel="noreferrer noopener" href="https://aws.amazon.com/porting-assistant-dotnet/" target="_blank">link</a>, click on the Download Porting Assistant for the .NET button to download and install. You can also use the Visual Studio extension from <a rel="noreferrer noopener" href="https://marketplace.visualstudio.com/items?itemName=AWSPA.AWSPortingAssistant" target="_blank">here</a>.</li></ul>



<h1 class="wp-block-heading">Port the Application</h1>



<p>In this section, let&#8217;s see how we can use both tools.</p>



<h2 class="wp-block-heading">Using Upgrade Assistant tool</h2>



<p>Using the upgrade assistant tool is as easy as you type some writing some basic commands in CLI. If you have worked with any CLI tools before, this would be very easy. </p>



<p>Once you have installed the tool, you can run the preceding command to start the process. </p>



<pre class="wp-block-code"><code>upgrade-assistant upgrade &lt;Path to csproj or sln to upgrade&gt;</code></pre>



<p>This will analyse your solution or the project and give you the commands to perform as in the preceding image. The first step is to select the entry point from your solution, if you are trying to port the entire solution.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/06/image-8.png"><img decoding="async" width="650" height="239" src="/wp-content/uploads/2021/06/image-8.png" alt="" class="wp-image-14420" srcset="/wp-content/uploads/2021/06/image-8.png 650w, /wp-content/uploads/2021/06/image-8-300x110.png 300w" sizes="(max-width: 650px) 100vw, 650px" /></a><figcaption>Upgrade Assistant initial commands</figcaption></figure></div>



<p>The next step is to select the project and select the commands to perform each task. Please remember that you will have to do this for each project. In my case, I was having 43 projects, if you have more projects it can be a pain. Your screen should look like the preceding image.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/06/image-9.png"><img decoding="async" width="1000" height="589" src="/wp-content/uploads/2021/06/image-9.png" alt="" class="wp-image-14421" srcset="/wp-content/uploads/2021/06/image-9.png 1000w, /wp-content/uploads/2021/06/image-9-300x177.png 300w, /wp-content/uploads/2021/06/image-9-768x452.png 768w" sizes="(max-width: 1000px) 100vw, 1000px" /></a><figcaption>Upgrade Assistant porting task</figcaption></figure></div>



<p>Please keep in mind that I am upgrading my MVC application, and the commands will be slightly different for other .NET framework app types. See more <a rel="noreferrer noopener" href="https://dotnet.microsoft.com/platform/upgrade-assistant" target="_blank">here</a>. Once the tool has gone through all the projects, the last step is to finalize the upgrade. As always, all you have to do is selecting the command. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/06/image-10.png"><img decoding="async" width="1024" height="423" src="/wp-content/uploads/2021/06/image-10-1024x423.png" alt="" class="wp-image-14422" srcset="/wp-content/uploads/2021/06/image-10-1024x423.png 1024w, /wp-content/uploads/2021/06/image-10-300x124.png 300w, /wp-content/uploads/2021/06/image-10-768x317.png 768w, /wp-content/uploads/2021/06/image-10-1536x635.png 1536w, /wp-content/uploads/2021/06/image-10.png 1580w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Upgrade assistant finalize step</figcaption></figure></div>



<p>You should get a message as preceding once the upgrade has been completed. </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>[22:43:27 INF] Upgrade has completed. Please review any changes.<br>[22:43:27 INF] Deleting upgrade progress file at C:\sourcecode\solution-name.upgrade-assistant<br>PS C:\sourcecode\solution-name&gt;</p><cite>Upgrade output</cite></blockquote>



<p>It is worth noting that you will have to manually do a lot of changes in your solution according to how complex your solution is. Some of the warnings/errors that this tool gives are given below. </p>



<ul class="wp-block-list"><li>No version of System.Configuration.ConfigurationManager found that supports [&#8220;net46&#8221;]; leaving unchanged</li><li>No version of System.ServiceModel.Federation found that supports [&#8220;net46&#8221;]; leaving unchanged</li><li>.NET Upgrade Assistant analyzer NuGet package reference cannot be added because the package cannot be found</li><li>Package AutoMapper has been upgraded across major versions (4.2.0 -&gt; 5.2.0) which may introduce breaking changes</li><li>No version of EnterpriseLibrary.TransientFaultHandling found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>No version of EnterpriseLibrary.TransientFaultHandling.Data found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>No version of Microsoft.AspNet.WebApi.OData found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>No version of Microsoft.Azure.CosmosDB.Table found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>No version of Microsoft.Azure.DocumentDB found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>No version of Microsoft.Bcl.Async found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>Package Microsoft.Web.Xdt has been upgraded across major versions (2.1.1 -&gt; 3.1.0) which may introduce breaking changes</li><li>Package Microsoft.Azure.NotificationHubs has been upgraded across major versions (1.0.9 -&gt; 2.0.2) which may introduce breaking changes</li><li>No version of SharePointPnPCoreOnline found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>Package Microsoft.Azure.NotificationHubs has been upgraded across major versions (1.0.9 -&gt; 2.0.2) which may introduce breaking changes</li><li>No version of System.ServiceModel.Federation found that supports [&#8220;net46&#8221;]; leaving unchanged</li><li>No version of Microsoft.Azure.ActiveDirectory.GraphClient found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>Package Microsoft.Azure.WebJobs has been upgraded across major versions (1.1.2 -&gt; 2.3.0) which may introduce breaking changes</li><li>No version of Microsoft.ApplicationInsights.Web found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>No version of Microsoft.AspNet.WebApi.Owin found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>No version of StackifyHttpModule found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>No version of System.IdentityModel.Tokens.ValidatingIssuerNameRegistry found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>No version of WebApiContrib.Formatting.Jsonp found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>No version of Microsoft.AspNet.WebApi.Cors found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>No version of Microsoft.AspNet.WebApi.Tracing found that supports [&#8220;net5.0-windows&#8221;]; leaving unchanged</li><li>Package NJsonSchema.CodeGeneration has been upgraded across major versions (1.39.5923.31344 -&gt; 2.65.6055.39156) which may introduce breaking changes</li></ul>



<h2 class="wp-block-heading">Using Posting Assistant tool</h2>



<p>This is how you can use the Porting Assistant tool.</p>



<h3 class="wp-block-heading">Configure the Porting Assistant tool</h3>



<p>Once the tool is installed, open the same and click on the Get started button.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/06/image-1.png"><img decoding="async" width="650" height="331" src="/wp-content/uploads/2021/06/image-1.png" alt="" class="wp-image-14341" srcset="/wp-content/uploads/2021/06/image-1.png 650w, /wp-content/uploads/2021/06/image-1-300x153.png 300w" sizes="(max-width: 650px) 100vw, 650px" /></a><figcaption>Get started with Porting Assistant for .NET tool</figcaption></figure></div>



<p>In the new screen, select the target framework and then click on the Add named profile link and provide the Access key information we get from the AWS console. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/06/image-2.png"><img decoding="async" width="1024" height="815" src="/wp-content/uploads/2021/06/image-2-1024x815.png" alt="" class="wp-image-14342" srcset="/wp-content/uploads/2021/06/image-2-1024x815.png 1024w, /wp-content/uploads/2021/06/image-2-300x239.png 300w, /wp-content/uploads/2021/06/image-2-768x611.png 768w, /wp-content/uploads/2021/06/image-2.png 1498w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>AWS named profile</figcaption></figure></div>



<p>Click on the Add button, if you want to know more about the named profile, <a rel="noreferrer noopener" href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html" target="_blank">this has</a> everything documented. This is how your screen should look like now.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/06/image-3.png"><img decoding="async" width="1024" height="668" src="/wp-content/uploads/2021/06/image-3-1024x668.png" alt="" class="wp-image-14343" srcset="/wp-content/uploads/2021/06/image-3-1024x668.png 1024w, /wp-content/uploads/2021/06/image-3-300x196.png 300w, /wp-content/uploads/2021/06/image-3-768x501.png 768w, /wp-content/uploads/2021/06/image-3-1536x1001.png 1536w, /wp-content/uploads/2021/06/image-3.png 2040w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Porting assistant framework selection</figcaption></figure></div>



<h3 class="wp-block-heading">Using the porting assistant tool</h3>



<p>From the above screen, click on the button Next. From here you can select your solution file that holds all of your projects. The tool will start analysing your solution bytes by bytes, depending on the complexity of your solution, this can take a while. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/06/image-4.png"><img decoding="async" width="1024" height="334" src="/wp-content/uploads/2021/06/image-4-1024x334.png" alt="" class="wp-image-14344" srcset="/wp-content/uploads/2021/06/image-4-1024x334.png 1024w, /wp-content/uploads/2021/06/image-4-300x98.png 300w, /wp-content/uploads/2021/06/image-4-768x251.png 768w, /wp-content/uploads/2021/06/image-4-1536x502.png 1536w, /wp-content/uploads/2021/06/image-4-2048x669.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Porting assistant tool analyse screen</figcaption></figure></div>



<p>The system will give a message as in the preceding image once the analysing is finished. The screen will also contain information about your Incompatible packages, Incompatible APIs, Build Errors, Porting actions, etc.  </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/06/image-5.png"><img decoding="async" width="1024" height="287" src="/wp-content/uploads/2021/06/image-5-1024x287.png" alt="" class="wp-image-14345" srcset="/wp-content/uploads/2021/06/image-5-1024x287.png 1024w, /wp-content/uploads/2021/06/image-5-300x84.png 300w, /wp-content/uploads/2021/06/image-5-768x215.png 768w, /wp-content/uploads/2021/06/image-5-1536x430.png 1536w, /wp-content/uploads/2021/06/image-5-2048x573.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Porting assistant tool success message</figcaption></figure></div>



<p>Click on the solution name, in the screen you will be able to either select all the projects or one by one at a time and start the porting process. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/06/image-6.png"><img decoding="async" width="1024" height="542" src="/wp-content/uploads/2021/06/image-6-1024x542.png" alt="" class="wp-image-14346" srcset="/wp-content/uploads/2021/06/image-6-1024x542.png 1024w, /wp-content/uploads/2021/06/image-6-300x159.png 300w, /wp-content/uploads/2021/06/image-6-768x406.png 768w, /wp-content/uploads/2021/06/image-6-1536x812.png 1536w, /wp-content/uploads/2021/06/image-6-2048x1083.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Porting assistant porting action</figcaption></figure></div>



<p>Clicking on the button Port solution redirect you to another screen, that is where you can change the versions of your packages. And once you finalized that, click on the port button. You should now see a notification saying that the porting has started. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/06/image-7.png"><img decoding="async" width="651" height="181" src="/wp-content/uploads/2021/06/image-7.png" alt="" class="wp-image-14416" srcset="/wp-content/uploads/2021/06/image-7.png 651w, /wp-content/uploads/2021/06/image-7-300x83.png 300w" sizes="(max-width: 651px) 100vw, 651px" /></a><figcaption>Porting assistant porting operation</figcaption></figure></div>



<p>You will also be getting an option to view the logs at the end.</p>



<h1 class="wp-block-heading">Things to keep in mind</h1>



<ul class="wp-block-list"><li>These tools are just a starting point, and according to the complexity of your application, and the number of APIs or packages incompatible, you may have to manually edit the code and change the package references. </li><li>It will be helpful if you choose to save the accessed solution in the same place if you use any Git branch so that you can see the changes and act accordingly.</li><li>If you use Microsoft Upgrade Assistant, you can choose the given order to perform the port or if you use Amazon Porting Assistant, you can select which project you should be migrated first according to the graph in the Project references tab.</li></ul>



<h1 class="wp-block-heading">More information about the tools</h1>



<p>The .NET Upgrade Assistant is a CLI tool introduced by Microsoft, and with this tool, you can easily migrate any old application to new versions. You can read more about this tool <a href="https://docs.microsoft.com/en-gb/dotnet/core/porting/upgrade-assistant-overview?WT.mc_id=DT-MVP-5001828" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p>The tool &#8220;Porting Assistant for .NET&#8221; is developed by Amazon. You can read more about this tool <a rel="noreferrer noopener" href="https://aws.amazon.com/porting-assistant-dotnet/" target="_blank">here</a>.</p>



<p>To get more understanding about this &#8220;Porting Assistant for .NET&#8221; tool, I recommend you to watch the preceding video. </p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Porting Assistant for .NET" width="1200" height="675" src="https://www.youtube.com/embed/mMu7qahc9-0?start=231&#038;feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div><figcaption>Porting Assistant for .NET Overview</figcaption></figure>



<h1 class="wp-block-heading">Conclusion</h1>



<p>In this post, we learned the preceding things.</p>



<ul class="wp-block-list"><li>What is Upgrade Assistant tool from Microsoft</li><li>How to configure and use Upgrade Assistant tool from Microsoft</li><li>How to migrate from old .NET framework project to new .NET 5 version</li><li>What is the Porting Assistant for the .NET tool</li><li>How to configure the Porting Assistant for the .NET tool</li></ul>



<p>I will be updating this post if I find any information needs to be added in the future. </p>



<h1 class="wp-block-heading">About the Author</h1>



<p>I am yet another developer who is passionate about writing and video creation. I have written close to 500 blogs on my&nbsp;<a href="https://sibeeshpassion.com/" target="_blank" rel="noreferrer noopener">blog</a>. And I upload videos on my YouTube channels&nbsp;<a href="https://www.youtube.com/njanorumalayali" target="_blank" rel="noreferrer noopener">Njan Oru Malayali</a>&nbsp;and&nbsp;<a href="https://www.youtube.com/SibeeshPassion" target="_blank" rel="noreferrer noopener">Sibeesh Passion</a>. Please feel free to follow me.</p>



<ul class="wp-block-list"><li><a href="https://github.com/SibeeshVenu">GitHub</a></li><li><a href="https://medium.com/@sibeeshvenu">medium</a></li><li><a href="https://twitter.com/sibeeshvenu">Twitter</a></li></ul>



<h1 class="wp-block-heading">Your turn. What do you think?</h1>



<p>Thanks a lot for reading. Did I miss anything that you may think is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.</p>



<p>Kindest Regards</p>



<p>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/migrate-or-port-your-old-legacy-net-projects-to-the-net5/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>UWP Application Signin, Release, Distribute, Deploy With Azure DevOps Pipeline</title>
		<link>https://www.sibeeshpassion.com/uwp-application-singin-release-distribute-deploy-with-azure-devops-pipeline/</link>
					<comments>https://www.sibeeshpassion.com/uwp-application-singin-release-distribute-deploy-with-azure-devops-pipeline/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sun, 03 Nov 2019 10:52:58 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[UWP]]></category>
		<category><![CDATA[App Center Distribute UWP]]></category>
		<category><![CDATA[Azure DwevOps]]></category>
		<category><![CDATA[Azure Pipeline]]></category>
		<category><![CDATA[Tasks in YAML]]></category>
		<category><![CDATA[UWP Build Signin]]></category>
		<category><![CDATA[UWP Release Pipeline Azure]]></category>
		<category><![CDATA[YAML]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13934</guid>

					<description><![CDATA[[toc] Introduction Building a UWP application is fun but releasing them not. At least that is the experience I had, I was facing a bunch of issues when I try to configure the pipeline to build and release to the app center. Yes, it includes the creation of a certificate too, and here we will see the best practice to handle your certificate. And we will also use the option Variables in the Azure DevOps. Here in this article, we will create the pipelines from the scratch we will create a certificate and save it under the secured files we [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>Building a UWP application is fun but releasing them not. At least that is the experience I had, I was facing a bunch of issues when I try to configure the pipeline to build and release to the app center. Yes, it includes the creation of a certificate too, and here we will see the best practice to handle your certificate. And we will also use the option Variables in the Azure DevOps. </p>



<p>Here in this article, </p>



<ul class="wp-block-list"><li>we will create the pipelines from the scratch </li><li>we will create a certificate and save it under the secured files</li><li>we will use the certificate to signin the build in the pipeline</li><li>we will create variables for our pipeline</li><li>we will also use some of the existing tasks like, copy, archive etc</li><li>and at the end, we will distribute our artifact to the app center</li></ul>



<p>If any of the above points mentioned felt interesting, then you are in the right place. Let&#8217;s read further.</p>



<h2 class="wp-block-heading">Welcome to the Pipeline World</h2>



<p>Azure DevOps pipeline has a lot to offer, and I am yet to experience all the features it provides. Here I am assuming that you already have a UWP application, and if you have not you can get some sample UWP applications from the official GitHub repositories, I will leave this task to you.</p>



<h3 class="wp-block-heading">Creating a certificate</h3>



<p>The first thing that we need to do is to create our certificate file (PFX). To do that, we already have a <a href="https://docs.microsoft.com/en-us/windows/msix/package/create-certificate-package-signing/?WT.mc_id=DT-MVP-5001828">nice tutorial on the Docs</a>. If you have followed the tutorial, at the end you should be having a PFX file saved in some folder as per your preference.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="415" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/Create-Certificate-PFX-File-1024x415.png" alt="" class="wp-image-13935" srcset="/wp-content/uploads/2019/11/Create-Certificate-PFX-File-1024x415.png 1024w, /wp-content/uploads/2019/11/Create-Certificate-PFX-File-300x122.png 300w, /wp-content/uploads/2019/11/Create-Certificate-PFX-File-768x312.png 768w, /wp-content/uploads/2019/11/Create-Certificate-PFX-File-425x172.png 425w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Create Certificate PFX File</figcaption></figure>



<p>Please make a note of the location you had saved your PFX file and the Thumbprint.  </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>What is the difference between a PFX file and Cert file?</p><p>A PFX will have both private and public key in it, and cert file will have only public key in it. Thus sharing a PFX file outside your organization is not a good idea.</p><cite>PFX VS Cert</cite></blockquote>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>What is a Thumbprint?</p><p>A Thumbprint is a hexadecimal string that can be used to identify the certificate</p><cite>Thumbprint</cite></blockquote>



<p>Now somehow you forgot your Thumbprint, the same can be easily found in this location in Windows.</p>



<pre class="wp-block-code"><code>C:\Users\sibee\AppData\Roaming\Microsoft\SystemCertificates\My\Certificates</code></pre>



<h3 class="wp-block-heading">Setting up the variables </h3>



<p>As we now have our certificate and the details ready, let us set up our variables in the Azure DevOps pipeline. To do that, go to the library section of the pipeline and click on the +Variable group.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="556" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/Varibale-Group-in-Azure-DebvOps-1024x556.png" alt="" class="wp-image-13936" srcset="/wp-content/uploads/2019/11/Varibale-Group-in-Azure-DebvOps-1024x556.png 1024w, /wp-content/uploads/2019/11/Varibale-Group-in-Azure-DebvOps-300x163.png 300w, /wp-content/uploads/2019/11/Varibale-Group-in-Azure-DebvOps-768x417.png 768w, /wp-content/uploads/2019/11/Varibale-Group-in-Azure-DebvOps-425x231.png 425w, /wp-content/uploads/2019/11/Varibale-Group-in-Azure-DebvOps.png 1299w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Variable Group in Azure DevOps</figcaption></figure>



<p>Below is the Variable Group I had created with all the details. </p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="957" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/Variable-Group-With-Details-Pipeline-1024x957.png" alt="" class="wp-image-13937" srcset="/wp-content/uploads/2019/11/Variable-Group-With-Details-Pipeline-1024x957.png 1024w, /wp-content/uploads/2019/11/Variable-Group-With-Details-Pipeline-300x280.png 300w, /wp-content/uploads/2019/11/Variable-Group-With-Details-Pipeline-768x717.png 768w, /wp-content/uploads/2019/11/Variable-Group-With-Details-Pipeline-425x397.png 425w, /wp-content/uploads/2019/11/Variable-Group-With-Details-Pipeline.png 1490w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Variable Group With Details Pipeline</figcaption></figure>



<p>Please do not forget to enable the &#8220;Allow access to all pipeline&#8221; or else you will always get an error in your pipeline. Here the signingCert.secureFilePath is the file path of our PFX file, which we will upload to our secure file section of the pipeline. We will talk about the appSlug and distributionGroupId when we create the distribute to app center task in our pipeline.</p>



<h4 class="wp-block-heading">Upload the certificate to the Secure Files</h4>



<figure class="wp-block-image"><img decoding="async" width="1024" height="583" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/Upload-Secure-Files-in-Azure-DevOps-1024x583.png" alt="" class="wp-image-13938" srcset="/wp-content/uploads/2019/11/Upload-Secure-Files-in-Azure-DevOps-1024x583.png 1024w, /wp-content/uploads/2019/11/Upload-Secure-Files-in-Azure-DevOps-300x171.png 300w, /wp-content/uploads/2019/11/Upload-Secure-Files-in-Azure-DevOps-768x437.png 768w, /wp-content/uploads/2019/11/Upload-Secure-Files-in-Azure-DevOps-425x242.png 425w, /wp-content/uploads/2019/11/Upload-Secure-Files-in-Azure-DevOps.png 1237w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Upload Secure Files in Azure DevOps</figcaption></figure>



<p>To upload our PFX file generated, click on the Library and then Secure files, and upload the file by clicking on the +Secure file.</p>



<h3 class="wp-block-heading">Generate build number automatically (Optional)</h3>



<p>This step is optional. Unfortunately by default the Azure DevOps release to app center task will not increase the build number, thus you will always see the same version number as 1.0.0 in the app center.</p>



<figure class="wp-block-image"><img decoding="async" width="919" height="228" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/Release-App-Center-With-Same-Build-Number.png" alt="" class="wp-image-13939" srcset="/wp-content/uploads/2019/11/Release-App-Center-With-Same-Build-Number.png 919w, /wp-content/uploads/2019/11/Release-App-Center-With-Same-Build-Number-300x74.png 300w, /wp-content/uploads/2019/11/Release-App-Center-With-Same-Build-Number-768x191.png 768w, /wp-content/uploads/2019/11/Release-App-Center-With-Same-Build-Number-425x105.png 425w" sizes="(max-width: 919px) 100vw, 919px" /><figcaption>Release App Center With Same Build Number</figcaption></figure>



<p>And if you want to change it to something like the preceding image, then you can consider reading this step.</p>



<figure class="wp-block-image"><img decoding="async" width="967" height="723" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/App-Center-Release-With-Different-Version-Number.png" alt="" class="wp-image-13940" srcset="/wp-content/uploads/2019/11/App-Center-Release-With-Different-Version-Number.png 967w, /wp-content/uploads/2019/11/App-Center-Release-With-Different-Version-Number-300x224.png 300w, /wp-content/uploads/2019/11/App-Center-Release-With-Different-Version-Number-768x574.png 768w, /wp-content/uploads/2019/11/App-Center-Release-With-Different-Version-Number-425x318.png 425w" sizes="(max-width: 967px) 100vw, 967px" /><figcaption>App Center Release With Different Version Number</figcaption></figure>



<p>The first thing that you need to do is to install <a href="https://marketplace.visualstudio.com/items?itemName=richardfennellBM.BM-VSTS-Versioning-Task">this package to your organization</a>. Once you have done that, you should be able to see related tasks when you search for the term &#8220;Version&#8221; in the pipeline.</p>



<figure class="wp-block-image"><img decoding="async" width="550" height="1024" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/Version-Build-Tool-550x1024.png" alt="" class="wp-image-13941" srcset="/wp-content/uploads/2019/11/Version-Build-Tool-550x1024.png 550w, /wp-content/uploads/2019/11/Version-Build-Tool-161x300.png 161w, /wp-content/uploads/2019/11/Version-Build-Tool-295x550.png 295w, /wp-content/uploads/2019/11/Version-Build-Tool.png 711w" sizes="(max-width: 550px) 100vw, 550px" /><figcaption>Version Build Tool</figcaption></figure>



<h3 class="wp-block-heading">Create the Pipeline</h3>



<p>Below is my fully functioned YAML file, I will be explaining all the tasks here.</p>



<script src="https://gist.github.com/SibeeshVenu/a882961e72cb5651b581ca50bd56d79a.js"></script>



<p>To start with I wanted to make sure that my build is manual, so I started editing my YAML file as follows.</p>



<script src="https://gist.github.com/SibeeshVenu/6bb0a20435a217cd04ada17d7c675b74.js"></script>



<p>As I was mentioning before, we wanted to make sure that the version number of our app releases are different, thus I assigned the name property as below.</p>



<pre class="wp-block-code"><code>name: $(MajorVersion).$(MinorVersion).$(date:yy)$(DayOfYear)$(rev:.r)</code></pre>



<p>Do you remember that we created a Variable Group and now it is the time use it.</p>



<script src="https://gist.github.com/SibeeshVenu/a0202c1a349cba1f17cbb92c8c228f0f.js"></script>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Please be noted that you must use the format -name: &#8220;&#8221; value: &#8220;&#8221;</p><cite>Tip for Pipeline Variable Configuration</cite></blockquote>



<p>Once this is done we install all of our Nuget Packages. This is something that  we do for all our pipeline thus I am not going to explain this task.</p>



<p>Now it is time to <strong>download our certificate</strong> from the secured files. To do that we need to add the task below.</p>



<script src="https://gist.github.com/SibeeshVenu/d42ff3a522d2f31c8c739116863f7398.js"></script>



<p>As you can see that we use the variable signingCert.secureFilePath to locate the secure file. Please also be noted that the name property, we will be using this in upcoming tasks. </p>



<p>As we downloaded the certificate already, now it is time to <strong>install our certificate in our agent</strong> so that we can do the package siginin. </p>



<script src="https://gist.github.com/SibeeshVenu/98c83c323b825bfb0ddfa31a002892df.js"></script>



<p>Did you notice that we used mySecureFile.secureFilePath to get our certificate and the password from the variable? </p>



<p>Once this is done, we can add a task to automatically increase the build number of our artifacts. Remember that we installed a package to do so? If not, please consider read this article from the start again, just kidding!.</p>



<script src="https://gist.github.com/SibeeshVenu/60148b868f6d9ff94e375fed5ff72f2a.js"></script>



<p>As we have a UWP application, we should use the task Version APPX manifest, please remember that the task names are different for the other types of applications. This task will update the related environment variables.</p>



<p>Now let us add a task to <strong>build our application</strong>.</p>



<script src="https://gist.github.com/SibeeshVenu/d63f64a610021a6938b5b403aedd739f.js"></script>



<p>Please be noted that these build arguments.</p>



<ul class="wp-block-list"><li>p:AppxPackageSigningEnabled=true</li><li>p:PackageCertificateThumbprint=&#8221;$(signingCert.thumbprint)&#8221;</li><li>p:PackageCertificateKeyFile=&#8221;$(mySecureFile.secureFilePath)&#8221;</li><li>p:PackageCertificatePassword=&#8221;$(signingCert.password)&#8221;</li></ul>



<p>These are the settings that you need to enable to do the build signin.</p>



<p>So far so good, as per the weight of your application, the build task can take longer than expected. <strong>Please keep in mind that the default timeout value of the Azure DevOps pipeline is 60 minutes</strong>, so if your build is taking more than an hour, then your build will be failing.</p>



<p>Once the build is successful, we can <strong>copy and publish our artifacts</strong>. Are you ready?</p>



<script src="https://gist.github.com/SibeeshVenu/4be7923b104a7d0661267f1c2414886e.js"></script>



<p>Yay!. We are almost done. I was facing an issue as &#8220;Ask the app developer for a new app package. This one isn&#8217;t signed with a trusted certificate (0x800B0100) &#8221; when I try to install the application after downloading the application from the app center.  And <a href="https://github.com/damienaicheh/UWP-Pipeline/issues/1">this GitHub post</a> helped me to fix the same. </p>



<p>So as a fix, I had to upload the entire artifacts to the app center instead of the APPX file alone, to do so, we have to create an Archive task as follows. </p>



<script src="https://gist.github.com/SibeeshVenu/e04889e0ff003215e98d0e20cc1cb984.js"></script>



<p>So now we have our complete artifacts ready to <strong>upload to the app center</strong>. Let&#8217;s create the task for that. Below is my task, I will explain the inputs needed for this task.</p>



<script src="https://gist.github.com/SibeeshVenu/1348ea35f0502a65997d0224eb9715c9.js"></script>



<p> Before you add that task, make sure that you get the values for the below inputs. </p>



<ul class="wp-block-list"><li>Server End Point</li><li>App Slug</li><li>Distribution Group Id</li></ul>



<p>Now let&#8217;s get these values. The server end point is the name of the connection that you should create. You will be asked to do this while you add the App Distribute Task to the YAML file. Please make sure that you have enough permission to do so.</p>



<figure class="wp-block-image"><img decoding="async" width="660" height="434" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/App-Center-Connection.png" alt="" class="wp-image-13943" srcset="/wp-content/uploads/2019/11/App-Center-Connection.png 660w, /wp-content/uploads/2019/11/App-Center-Connection-300x197.png 300w, /wp-content/uploads/2019/11/App-Center-Connection-425x279.png 425w" sizes="(max-width: 660px) 100vw, 660px" /><figcaption>App Center Connection</figcaption></figure>



<p>You should also need to create an API token in your App Center to create this connection, you need to go to  <a href="https://appcenter.ms/settings/apitokens">https://appcenter.ms/settings/apitokens</a>  and then click on the New API Token button.</p>



<figure class="wp-block-image"><img decoding="async" width="649" height="283" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/API-Token-in-App-Center.png" alt="" class="wp-image-13944" srcset="/wp-content/uploads/2019/11/API-Token-in-App-Center.png 649w, /wp-content/uploads/2019/11/API-Token-in-App-Center-300x131.png 300w, /wp-content/uploads/2019/11/API-Token-in-App-Center-425x185.png 425w" sizes="(max-width: 649px) 100vw, 649px" /><figcaption>API Token in App Center</figcaption></figure>



<p>Please make sure that you give Full Access when you create the API Token.</p>



<p>The app slug is in the format of <strong>{username}/{app_identifier}</strong>.  To locate <strong>{username}</strong> and <strong>{app_identifier}</strong> for an app, click on its name from <a rel="noreferrer noopener" href="https://appcenter.ms/apps" target="_blank">https://appcenter.ms/apps</a>, and the resulting URL is in the format of <a rel="noreferrer noopener" href="https://appcenter.ms/users/%7Busername%7D/apps/%7Bapp_identifier%7D" target="_blank">https://appcenter.ms/users/<strong>{username}</strong>/apps/<strong>{app_identifier}</strong></a>. If you are using orgs, the app slug is of the format <strong>{orgname}/{app_identifier}</strong>.</p>



<p>When you are uploading the artifacts in the zip file format, it is mandatory that you should provide the build number in the task, otherwise you will get an error as &#8220;<strong>Job:</strong> &#8220;&#8221;{\&#8221;status\&#8221;:\&#8221;error\&#8221;,\&#8221;message\&#8221;:\&#8221;Version could not be created from build.\&#8221;}&#8221; http response code: 422&#8243;&#8221; in the pipeline. So to fix this we can add the input <strong>buildVersion:&nbsp;&#8216;$(Build.BuildNumber)&#8217;</strong></p>



<p>And then I set the appFile as the archive file task output.</p>



<p>We usually have many people in out projects, and if the project is a critical ones, the number of people is more. But most of the cases, all of them will not be developers, some might be testers and some may be business people. So isn&#8217;t it a good idea to have a group of people to whom we can send notifications to, whenever we have any new releases, these can be Testers, Developers, Business etc. Luckily App Center has this feature of Groups. I created a Group called Testers and then I used this Group in my pipeline, to make sure that the notifications are sent only to these members. </p>



<p>To create a group, Click on the Groups in the App center and then create one, once it is created assign the members. Now you can click on the settings button of the group and get the Group Distribution Id, which we will use in the pipeline.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="247" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/Get-Group-Distribution-ID-in-App-Center-1024x247.png" alt="" class="wp-image-13946" srcset="/wp-content/uploads/2019/11/Get-Group-Distribution-ID-in-App-Center-1024x247.png 1024w, /wp-content/uploads/2019/11/Get-Group-Distribution-ID-in-App-Center-300x72.png 300w, /wp-content/uploads/2019/11/Get-Group-Distribution-ID-in-App-Center-768x185.png 768w, /wp-content/uploads/2019/11/Get-Group-Distribution-ID-in-App-Center-425x102.png 425w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Group Distribution ID in App Center</figcaption></figure>



<p><em>Please do not forget to update the values of <strong>appSlug </strong>and <strong>distributionGroupId </strong>in the Pipeline Variables</em>. </p>



<p>With this we are done with our configuration. </p>



<h2 class="wp-block-heading">Run the Pipeline</h2>



<p>As we have successfully configured our pipeline, now is the time to run the same. If everything goes well, you should be getting an output as below.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="503" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/Pipeline-Build-Output-1024x503.png" alt="" class="wp-image-13947" srcset="/wp-content/uploads/2019/11/Pipeline-Build-Output-1024x503.png 1024w, /wp-content/uploads/2019/11/Pipeline-Build-Output-300x147.png 300w, /wp-content/uploads/2019/11/Pipeline-Build-Output-768x377.png 768w, /wp-content/uploads/2019/11/Pipeline-Build-Output-425x209.png 425w, /wp-content/uploads/2019/11/Pipeline-Build-Output.png 1634w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Pipeline Build Output</figcaption></figure>



<p>Now let us go to our app center and see the new release.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="365" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/Release-App-Center-Output-1024x365.png" alt="" class="wp-image-13948" srcset="/wp-content/uploads/2019/11/Release-App-Center-Output-1024x365.png 1024w, /wp-content/uploads/2019/11/Release-App-Center-Output-300x107.png 300w, /wp-content/uploads/2019/11/Release-App-Center-Output-768x274.png 768w, /wp-content/uploads/2019/11/Release-App-Center-Output-425x152.png 425w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Release App Center Output</figcaption></figure>



<p>Now you can download the file and install your application. If you extract the files, you should be able to see all the related files inside including the certificate.</p>



<figure class="wp-block-image"><img decoding="async" width="859" height="408" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/App-Center-File-After-Extracted.png" alt="" class="wp-image-13949" srcset="/wp-content/uploads/2019/11/App-Center-File-After-Extracted.png 859w, /wp-content/uploads/2019/11/App-Center-File-After-Extracted-300x142.png 300w, /wp-content/uploads/2019/11/App-Center-File-After-Extracted-768x365.png 768w, /wp-content/uploads/2019/11/App-Center-File-After-Extracted-425x202.png 425w" sizes="(max-width: 859px) 100vw, 859px" /><figcaption>App Center File After Extracted</figcaption></figure>



<p>Now all you have to do is, to double click on the APPXBUNDLE file to install the application.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="651" src="https://sibeeshpassion.com/wp-content/uploads/2019/11/Install-the-App-1024x651.png" alt="" class="wp-image-13950" srcset="/wp-content/uploads/2019/11/Install-the-App-1024x651.png 1024w, /wp-content/uploads/2019/11/Install-the-App-300x191.png 300w, /wp-content/uploads/2019/11/Install-the-App-768x488.png 768w, /wp-content/uploads/2019/11/Install-the-App-425x270.png 425w, /wp-content/uploads/2019/11/Install-the-App.png 1300w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Install the Application</figcaption></figure>



<h2 class="wp-block-heading">References</h2>



<ul class="wp-block-list"><li><a href="https://damienaicheh.github.io/uwp/azure/devops/appcenter/2019/09/24/build-sign-and-deploy-your-uwp-application-using-azure-devops-and-appcenter-en.html">How to build, sign and deploy your UWP application using Azure DevOps and App Center</a></li><li><a href="https://docs.microsoft.com/en-us/windows/msix/package/create-certificate-package-signing/?WT.mc_id=DT-MVP-5001828">Create Certificate</a></li></ul>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Thanks a lot for staying with me for a long time and reading this article. I hope now you have learned</p>



<ul class="wp-block-list"><li>about creating a certificate for your UWP application</li><li>about Azure DevOps Variables</li><li>about Azure DevOps secured files</li><li>about siginin the UWP package in the Azure DevOps pipeline</li><li>about building the UWP application</li><li>about archiving the build artifacts before uploading to the app center</li><li>about configuring the distribute app center task in the Azure DevOps</li><li>about automatically updating the version number of your UWP application release</li></ul>



<p>If you have learned anything else from this article, please let me know in the comment section. </p>



<h2 class="wp-block-heading">Follow me</h2>



<p>If you like this article, consider following me, ha ha!.</p>



<ul class="wp-block-list"><li><a href="https://github.com/SibeeshVenu">GitHub</a></li><li><a href="https://medium.com/@sibeeshvenu">medium</a></li><li><a href="https://twitter.com/sibeeshvenu">Twitter</a></li></ul>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/uwp-application-singin-release-distribute-deploy-with-azure-devops-pipeline/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Asp.Net Core Windows Service Task Quartz.Net With Database</title>
		<link>https://www.sibeeshpassion.com/asp-net-core-windows-service-task-quartz-net-with-database/</link>
					<comments>https://www.sibeeshpassion.com/asp-net-core-windows-service-task-quartz-net-with-database/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 29 Aug 2019 12:46:07 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Asp.Net Core]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Asp Net Core Windows Service]]></category>
		<category><![CDATA[Azure Blob Storage]]></category>
		<category><![CDATA[Azure Storage]]></category>
		<category><![CDATA[NLog]]></category>
		<category><![CDATA[NLog in Windows Service]]></category>
		<category><![CDATA[Quartz Scheduler]]></category>
		<category><![CDATA[Quartz Scheduler with Dependency Injection]]></category>
		<category><![CDATA[Quartz SQL Server]]></category>
		<category><![CDATA[Quartz With Database]]></category>
		<category><![CDATA[Windows Service]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13893</guid>

					<description><![CDATA[[toc] Introduction In our previous article we have already seen that how we can use Quartz.Net scheduler in our Asp.Net core console application and then run it as a windows service. The problem with that approach is that, the scheduler information will be lost once the system restarts or something bad happens. To rectify that problem we can actually save all the scheduler information in a database, luckily the Quartz.Net scheduler supports this and we can easily implement it. I hope the introduction is clear and let&#8217;s jump on to the implementation. Source Code The source code can be found [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>In our previous article we have already seen that how we can <a href="https://medium.com/better-programming/asp-net-core-windows-service-task-scheduler-daily-weekly-monthly-700a569d502a"><strong><em>use Quartz.Net scheduler in our Asp.Net core console application and then run it as a windows service</em></strong></a>. The problem with that approach is that, the scheduler information will be lost once the system restarts or something bad happens. To rectify that problem we can actually save all the scheduler information in a database, luckily the Quartz.Net scheduler supports this and we can easily implement it. I hope the introduction is clear and let&#8217;s jump on to the implementation.</p>



<h2 class="wp-block-heading">Source Code</h2>



<p>The source code can be found <a href="https://github.com/SibeeshVenu/Perfect-Scheduler"><strong><em>in this GitHub repository</em></strong></a>. Please feel free to star, fork or do whatever you wish. You can also consider follow me on GitHub. LOL. </p>



<h2 class="wp-block-heading">Setting Up Database</h2>



<p>Before we start the coding, let us set up our database. You can choose any database as you wish. I am choosing SQL Server Express.</p>



<h3 class="wp-block-heading">Install SQL Server Express</h3>



<figure class="wp-block-image"><img decoding="async" width="1024" height="812" src="https://sibeeshpassion.com/wp-content/uploads/2019/08/Install-SQl-Express-1024x812.png" alt="" class="wp-image-13894" srcset="/wp-content/uploads/2019/08/Install-SQl-Express-1024x812.png 1024w, /wp-content/uploads/2019/08/Install-SQl-Express-300x238.png 300w, /wp-content/uploads/2019/08/Install-SQl-Express-768x609.png 768w, /wp-content/uploads/2019/08/Install-SQl-Express-425x337.png 425w, /wp-content/uploads/2019/08/Install-SQl-Express.png 1690w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>SQL Server Express</figcaption></figure>



<h3 class="wp-block-heading">Enable sa Login</h3>



<p>We should enable the sa login which we will use in our Quartz configuration. If you try to configure the Quartz with windows authentication, you will get an error as below.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>2019-08-29 11:34:02.3570|INFO|Quartz.Core.QuartzScheduler|JobFactory set to: Backup.Service.Helpers.CustomJobFactory<br> 2019-08-29 11:34:12.6801|INFO|Quartz.Impl.AdoJobStore.JobStoreTX|ConnectionAndTransactionHolder passed to RollbackConnection was null, ignoring<br> 2019-08-29 11:34:12.6892|ERROR|Quartz.Impl.AdoJobStore.JobStoreTX|Failure occurred during job recovery: Failed to obtain DB connection from data source &#8216;default&#8217;: System.Data.SqlClient.SqlException (0x80131904): Cannot open database &#8220;BackupClientSchedules&#8221; requested by the login. The login failed.<br> Login failed for user &#8216;WORKGROUP\DESKTOP-3EF5B65$&#8217;.<br>    at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)<br>    at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)<br>    at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)<br>    at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)<br>    at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)<br>    at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal&amp; connection)<br>    at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource<code>1 retry, DbConnectionOptions userOptions, DbConnectionInternal&amp; connection)    at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource</code>1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal&amp; connection)<br>    at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource<code>1 retry, DbConnectionOptions userOptions)    at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource</code>1 retry)<br>    at System.Data.SqlClient.SqlConnection.Open()<br>    at Quartz.Impl.AdoJobStore.JobStoreSupport.GetConnection() in C:\projects\quartznet\src\Quartz\Impl\AdoJobStore\JobStoreSupport.cs:line 323<br> ClientConnectionId:2efd5ab8-71aa-4598-b5ca-63c5aaa6afbe<br> Error Number:4060,State:1,Class:11</p></blockquote>



<p>Yes, that is such a log error, and we don&#8217;t want any errors right. So let us configure sa login first. I have already explained how you can do that , in one of my StackOverflow answer, you can see that <a href="https://stackoverflow.com/questions/3583605/login-failed-for-user-sa-the-user-is-not-associated-with-a-trusted-sql-server/57707682#57707682"><strong><em>here</em></strong></a>. </p>



<h3 class="wp-block-heading">Create Database and Tables Needed</h3>



<p>Now we need to create a database and some tables where we can save the scheduler and trigger information. You can always see the table schema here in <a href="https://github.com/quartznet/quartznet/blob/master/database/tables/tables_sqlServer.sql"><strong><em>this official Quartz GitHub repository</em></strong></a>. You can also find the same file in our source code.</p>



<p>Before you run that query in your SQL Server Management Studio, make sure to create a database first and the use the same.</p>



<pre class="wp-block-code"><code>CREATE database BackupClientSchedules
USE BackupClientSchedules</code></pre>



<p>Now id you see inside the database BackupClientSchedules, you should see some tables with no data inside.</p>



<figure class="wp-block-image"><img decoding="async" width="646" height="1024" src="https://sibeeshpassion.com/wp-content/uploads/2019/08/Quartz-Net-Tables-646x1024.png" alt="" class="wp-image-13895" srcset="/wp-content/uploads/2019/08/Quartz-Net-Tables-646x1024.png 646w, /wp-content/uploads/2019/08/Quartz-Net-Tables-189x300.png 189w, /wp-content/uploads/2019/08/Quartz-Net-Tables-347x550.png 347w, /wp-content/uploads/2019/08/Quartz-Net-Tables.png 650w" sizes="(max-width: 646px) 100vw, 646px" /><figcaption>Quartz Net Tables</figcaption></figure>



<h2 class="wp-block-heading">Configure Quartz.Net to Use Database Instead of RAM</h2>



<p>As we have already set up our database, now we can start configuring the service. If you are new Quartz.Net scheduler, I strongly recommend you to read my previous <a href="https://sibeeshpassion.com/asp-net-core-windows-service-task-scheduler-daily-weekly-monthly/"><strong><em>article</em></strong></a>. </p>



<h3 class="wp-block-heading">Edit App.config</h3>



<p>Let&#8217;s change the App.config file as preceding.</p>



<script src="https://gist.github.com/SibeeshVenu/dd04457e4c476db1b448c610079ee522.js"></script>



<p>Note that we have set  quartz.dataSource.default.provider  as Sqlserver and also given the  quartz.dataSource.default.connectionString. You should change these values with your provider and connection string.</p>



<h3 class="wp-block-heading">Install the Nuget Package</h3>



<p>We should install the Nuget package Quartz.Serialization.Json in our application. </p>



<h3 class="wp-block-heading">Setup the Scheduler</h3>



<p>In our previous article, we have see how we can setup the scheduler and we were using a function called GetScheduler for the same. Now we can edit the code of that function as preceding.</p>



<script src="https://gist.github.com/SibeeshVenu/c1256a4314d393ef839c2368b4a411b3.js"></script>



<p>Please note the comments in the above code block.</p>



<h2 class="wp-block-heading">Install the Service</h2>



<p>Once we finished the above steps, we can run dotnet publish command with release configuration and install the service as preceding.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="568" src="https://sibeeshpassion.com/wp-content/uploads/2019/08/SC-Commands-1024x568.png" alt="" class="wp-image-13896" srcset="/wp-content/uploads/2019/08/SC-Commands-1024x568.png 1024w, /wp-content/uploads/2019/08/SC-Commands-300x166.png 300w, /wp-content/uploads/2019/08/SC-Commands-768x426.png 768w, /wp-content/uploads/2019/08/SC-Commands-425x236.png 425w, /wp-content/uploads/2019/08/SC-Commands.png 1838w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>SC Commands</figcaption></figure>



<p>Again, read my previous article, if you need a detailed explanations about this step.</p>



<h2 class="wp-block-heading">Output</h2>



<p>Once the service started successfully, you should be able to see two log files backupclientlogfile_backupservice.txt and backupclientlogfile_helperservice.txt in our win7-x64 folder. You can see all the logs in this files.</p>



<p>You should also be able to see some scheduling information in our tables in our database. Some of the table&#8217;s screenshots are given below.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="140" src="https://sibeeshpassion.com/wp-content/uploads/2019/08/Quartz-Job-Details-1024x140.png" alt="" class="wp-image-13897" srcset="/wp-content/uploads/2019/08/Quartz-Job-Details-1024x140.png 1024w, /wp-content/uploads/2019/08/Quartz-Job-Details-300x41.png 300w, /wp-content/uploads/2019/08/Quartz-Job-Details-768x105.png 768w, /wp-content/uploads/2019/08/Quartz-Job-Details-425x58.png 425w, /wp-content/uploads/2019/08/Quartz-Job-Details.png 1923w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Quartz Job Details</figcaption></figure>



<figure class="wp-block-image"><img decoding="async" width="652" height="164" src="https://sibeeshpassion.com/wp-content/uploads/2019/08/Quartz-Sample-Triggers.png" alt="" class="wp-image-13898" srcset="/wp-content/uploads/2019/08/Quartz-Sample-Triggers.png 652w, /wp-content/uploads/2019/08/Quartz-Sample-Triggers-300x75.png 300w, /wp-content/uploads/2019/08/Quartz-Sample-Triggers-425x107.png 425w" sizes="(max-width: 652px) 100vw, 652px" /><figcaption>Quartz Sample Triggers</figcaption></figure>



<figure class="wp-block-image"><img decoding="async" width="649" height="67" src="https://sibeeshpassion.com/wp-content/uploads/2019/08/Quartz-Triggers.png" alt="" class="wp-image-13899" srcset="/wp-content/uploads/2019/08/Quartz-Triggers.png 649w, /wp-content/uploads/2019/08/Quartz-Triggers-300x31.png 300w, /wp-content/uploads/2019/08/Quartz-Triggers-425x44.png 425w" sizes="(max-width: 649px) 100vw, 649px" /><figcaption>Quartz Triggers</figcaption></figure>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Wow!. Now we have learned,</p>



<ul class="wp-block-list"><li>about Windows Service and Asp.Net Console Application</li><li>about How to create a Windows Service using Asp.Net Core</li><li>about How to use Quartz scheduler with database</li></ul>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/asp-net-core-windows-service-task-quartz-net-with-database/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Asp.Net Core Windows Service Task Scheduler Daily, Weekly, Monthly</title>
		<link>https://www.sibeeshpassion.com/asp-net-core-windows-service-task-scheduler-daily-weekly-monthly/</link>
					<comments>https://www.sibeeshpassion.com/asp-net-core-windows-service-task-scheduler-daily-weekly-monthly/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 12 Aug 2019 19:15:45 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Asp Net Core Windows Service]]></category>
		<category><![CDATA[Azure Blob Storage]]></category>
		<category><![CDATA[Azure Storage]]></category>
		<category><![CDATA[NLog]]></category>
		<category><![CDATA[NLog in Windows Service]]></category>
		<category><![CDATA[Quartz Scheduler]]></category>
		<category><![CDATA[Quartz Scheduler with Dependency Injection]]></category>
		<category><![CDATA[Windows Service]]></category>
		<category><![CDATA[Windows Service to Upload to Azure]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13876</guid>

					<description><![CDATA[[toc] Introduction Windows services are a good way for reducing some manual jobs that we have to do in our system. In this article, we are going to write a windows service using Asp.Net core, the jobs of this windows service is given below. Zip the folder and save the file to a particular directory Upload the zipped folder to the Azure blob storage The above mentioned tasks will be running daily, weekly, monthly. We are using Quartz scheduler with Dependency Injection to do this amazing tasks. We are using Nlog for logging the details of our tasks. If you [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>Windows services are a good way for reducing some manual jobs that we have to do in our system. In this article, we are going to write a windows service using Asp.Net core, the jobs of this windows service is given below.</p>



<ol class="wp-block-list"><li> Zip the folder and save the file to a particular directory </li><li>Upload the zipped folder to the Azure blob storage</li></ol>



<p>The above mentioned tasks will be running daily, weekly, monthly. We are using Quartz scheduler with Dependency Injection to do this amazing tasks. We are using Nlog for logging the details of our tasks. If you think this is something that you are interested at, then you are at the right place, let us develop our PerfectScheduler. </p>



<h2 class="wp-block-heading">Source Code</h2>



<p>The source code of this project is been uploaded to the GitHub, please feel free to fork, star, create pull requests etc. The repository can be found <a href="https://github.com/SibeeshVenu/Perfect-Scheduler"><strong><em>here</em></strong></a>.</p>



<h2 class="wp-block-heading">Creating Perfect Scheduler</h2>



<p>As I mentioned earlier, we are creating a windows service with Asp.Net core, technically there is no straight way to do this, as the Windows Service with Asp.Net core template is not available in Visual Studio.</p>



<figure class="wp-block-image"><img decoding="async" width="649" height="311" src="https://sibeeshpassion.com/wp-content/uploads/2019/08/No-Windows-Service-Project-Template.png" alt="" class="wp-image-13879" srcset="/wp-content/uploads/2019/08/No-Windows-Service-Project-Template.png 649w, /wp-content/uploads/2019/08/No-Windows-Service-Project-Template-300x144.png 300w, /wp-content/uploads/2019/08/No-Windows-Service-Project-Template-425x204.png 425w" sizes="(max-width: 649px) 100vw, 649px" /><figcaption>No Windows Service Project Template</figcaption></figure>



<p> so we will be creating an Asp.Net console application and then install executable file generated as a windows service. </p>



<figure class="wp-block-image"><img decoding="async" width="649" height="212" src="https://sibeeshpassion.com/wp-content/uploads/2019/08/Net-Core-Console-Application.png" alt="" class="wp-image-13880" srcset="/wp-content/uploads/2019/08/Net-Core-Console-Application.png 649w, /wp-content/uploads/2019/08/Net-Core-Console-Application-300x98.png 300w, /wp-content/uploads/2019/08/Net-Core-Console-Application-425x139.png 425w" sizes="(max-width: 649px) 100vw, 649px" /><figcaption>.Net Core Console Application</figcaption></figure>



<h3 class="wp-block-heading">Creating an Asp.Net Console Application</h3>



<p>Open Visual Studio and search for the project template Console App(.Net Core) and name the solution as per your convenience, I am naming this project as Perfect Scheduler, as I am thinking that we, the community people can make this windows service perfect by creating many pull requests.</p>



<p> Once you had created the application, let us install all of our dependencies at once, so that we don&#8217;t need to worry about them later. </p>



<figure class="wp-block-image"><img decoding="async" width="650" height="640" src="https://sibeeshpassion.com/wp-content/uploads/2019/08/Dependencies.png" alt="" class="wp-image-13881" srcset="/wp-content/uploads/2019/08/Dependencies.png 650w, /wp-content/uploads/2019/08/Dependencies-300x295.png 300w, /wp-content/uploads/2019/08/Dependencies-425x418.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Asp.Net Core Windows Service Dependencies</figcaption></figure>



<h3 class="wp-block-heading">Write the Service</h3>



<p>As we have installed all of our dependencies, let us create our service now. Add a new class with the name BackupService and inherit the same from IHostedService, which is part of Microsoft.Extensions.Hosting namespace.</p>



<p>The IHostedService has two methods in it as follows, so we should implement them in our service class.</p>



<script src="https://gist.github.com/SibeeshVenu/2a9cb76d58645085c3704d533a0a6a73.js"></script>



<h4 class="wp-block-heading">StartAsync</h4>



<p>The StartAsync method can be implemented as preceding.</p>



<script src="https://gist.github.com/SibeeshVenu/1e39b9749d12aac8acc1af98a2da4469.js"></script>



<p>As you can see that in the first line of the above code, we are getting the scheduler of Quartz. Let us create a method and return a scheduler then.</p>



<script src="https://gist.github.com/SibeeshVenu/afd74a512ddb7c8bd6d35868c263bd30.js"></script>



<p>The next step is to build a service provider so that we can inject our dependencies using Constructor Dependency Injection. By default the Quartz is not doing this, so we have to build the configuration our own.</p>



<script src="https://gist.github.com/SibeeshVenu/914f9ee0934d63234f81f16c5ffb2fcc.js"></script>



<p>As you can see that we have configured the services for DailyJob, WeeklyJob, MonthlyJob and HelperService. No worries, we will be creating these Classes and Interfaces very soon. </p>



<p>Once we get the Service Provider, we can pass this to our Custom Job Factory, which we will be implementing soon. Now, we can start the scheduler and schedule our jobs, please make sure that you are using different Identity names for both Triggers and Jobs. The samples are given below.</p>



<script src="https://gist.github.com/SibeeshVenu/2b6fa57cb5edca68431f59133ada6de2.js"></script>



<h4 class="wp-block-heading">StopAsync</h4>



<p>The StopAsync method can be implemented as follows</p>



<script src="https://gist.github.com/SibeeshVenu/36a4edb6866bbd9394a2eeb4a4abba5f.js"></script>



<h3 class="wp-block-heading">Creating the JobBuilders and TriggerBuilders</h3>



<p>Now we can create the Interfaces and Classes for our Jobs, which are Daily, Weekly, Monthly. To do so, let us create a new folder called Helpers and then create a folder called Interfaces inside.  Below are the Interfaces you need to create then.</p>



<h4 class="wp-block-heading">IDailyJob</h4>



<script src="https://gist.github.com/SibeeshVenu/2a06425a40aa642c420616a9dc438ea4.js"></script>



<h4 class="wp-block-heading">IWeeklyJob</h4>



<script src="https://gist.github.com/SibeeshVenu/745be5f74479f91a24d454c4b4ee113d.js"></script>



<h4 class="wp-block-heading">IMonthlyJob</h4>



<script src="https://gist.github.com/SibeeshVenu/43de235532540cd5cd6ff136ad07e9e6.js"></script>



<p>Let us also create an Interface for our HelperService.</p>



<h4 class="wp-block-heading">IHelperService</h4>



<script src="https://gist.github.com/SibeeshVenu/4aa11ef3c39e323a40de2b06abfbccfd.js"></script>



<p>The parameter schedule is for determining which job it is, the value of this parameter can be daily, weekly, monthly.</p>



<script src="https://gist.github.com/SibeeshVenu/308a0cc4b620f6c65f3f47738863db75.js"></script>



<h3 class="wp-block-heading">Create a Custom Job Factory</h3>



<p>To implement the Dependency Injection, we need to create our own custom job factory. Create a class inside the Helper folder as preceding.</p>



<script src="https://gist.github.com/SibeeshVenu/a2e10e1228e65ace98e45397d7c9d849.js"></script>



<h3 class="wp-block-heading">Implement the Job Builder Interfaces</h3>



<p>Now it is time to implement our Daily, Weekly, Monthly job builders. </p>



<h4 class="wp-block-heading">DailyJob</h4>



<script src="https://gist.github.com/SibeeshVenu/d34af66c20232409c4bb15852c88aabf.js"></script>



<h4 class="wp-block-heading">WeeklyJob</h4>



<script src="https://gist.github.com/SibeeshVenu/d021c1dc0be1c03cff9147ac3d4d231c.js"></script>



<h4 class="wp-block-heading">MonthlyJob</h4>



<script src="https://gist.github.com/SibeeshVenu/3b72c9acb9ad0e00887ecbee532d0438.js"></script>



<p>As you can see that we have configured separate classes for our each jobs with the dependency IHelperService injected via constructor. In the future we should be able to write custom logic for each jobs here as it is in separate classes.</p>



<h3 class="wp-block-heading">Implement HelperService</h3>



<p>Before we start implementing this service let us configure the NLog now as we will be writing logs from this class. </p>



<h4 class="wp-block-heading">Configure NLog</h4>



<p>To configure, NLog, create a new configuration file NLog.config and edit the content as preceding.</p>



<script src="https://gist.github.com/SibeeshVenu/7eaab92256f71a5c660a83564635b0dd.js"></script>



<p>Now, create a method SetUpNLog() and add the codes as below.</p>



<script src="https://gist.github.com/SibeeshVenu/82dbe1dd2ea19f5eda4f6fc9342880fc.js"></script>



<p>Please make sure that you have already added a property ILogger _logger. </p>



<p>We can implement the HelperService as preceding with all the necessary private and public methods.</p>



<script src="https://gist.github.com/SibeeshVenu/bc02d3f5621826c2a085970c6e47b004.js"></script>



<p>The method PerformService(string schedule) will be called for every schedule and it will make sure that the below tasks are performed.</p>



<ol class="wp-block-list"><li>Zip the folder and save the file to a particular directory</li><li>Upload the zipped file to the Azure blob storage</li></ol>



<p>Here, the values of the the variable and the blob storage container names are same, that is, daily, weekly, monthly. If you are not sure how you can upload a blob to Azure storage account, I strongly recommend you to read my article <a href="https://sibeeshpassion.com/timertrigger-azure-function-to-upload-to-azure-blob-daily/#azure-function-and-azure-blob"><strong><em>here</em></strong></a>.</p>



<p>Remember to set the values for the FolderToZipLocation(To which location the file should be saved), FolderFromZipLocation (From where the files should be taken), StorageConnectionString in the App.config file.</p>



<script src="https://gist.github.com/SibeeshVenu/1a2a3f26bf5e7a73e3b0af8aa3824172.js"></script>



<h3 class="wp-block-heading">Setting Up The Program</h3>



<p>As you all know that Program class it the start of our console application, not it is time to call our BackupService from the Program class. Let us edit the code of the Program class as below.</p>



<script src="https://gist.github.com/SibeeshVenu/55d3dea19acdf8f3416269f7911c5916.js"></script>



<p>If we are running the application locally/debug, we are calling the extension method RunConsoleAsync() or else we call our own custom extension method RunTheServiceAsync(). The line services.AddHostedService() is very important as this is where we register our IHostedService, which is BackupService. Below is the code for our extension method.</p>



<script src="https://gist.github.com/SibeeshVenu/b4950ef1a36a91800fd9bf9f5a9f02a3.js"></script>



<p>The ServiceLifetime class is where we override the methods from ServiceBase class. You can find the implementation as follows.</p>



<script src="https://gist.github.com/SibeeshVenu/9c1e42e7f697b60375d1a5975c5b0f53.js"></script>



<h2 class="wp-block-heading">Creating the Windows Service</h2>



<p>As we have already created the Asp.Net Core console application, now it is time to create a windows service from it. Make sure that you had set the RuntimeIdentifier to win7-x64 and SelfContained to true in the properties of your project, this will make sure that all of your dependencies are being added to your executable file, so that you don&#8217;t need to worry about handling your dependencies manually. You can read more about it <a href="https://docs.microsoft.com/en-us/dotnet/core/deploying/#self-contained-deployments-scd"><strong><em>here</em></strong></a>. To do so, right click on the project and click on Edit Project File. At the end, your csproj file should be similar as preceding.</p>



<script src="https://gist.github.com/SibeeshVenu/4772a4e34662dc09e7421a12064bcc28.js"></script>



<h3 class="wp-block-heading">Create the Release Configuration</h3>



<p>You should also run the dotnet publish command with the release configuration before you try to install the service, because you need this executable file to install the service.</p>



<p>Open the command prompt with administrator privilege and go to the project root folder using the cd command. Run the command &#8220;dotnet publish &#8211;configuration=release&#8221; .</p>



<p>This will generate everything you wanted. If you run the command correctly, you should see an output as preceding.</p>



<figure class="wp-block-image"><img decoding="async" width="651" height="400" src="https://sibeeshpassion.com/wp-content/uploads/2019/08/Dotnet-Publish-Release.png" alt="" class="wp-image-13883" srcset="/wp-content/uploads/2019/08/Dotnet-Publish-Release.png 651w, /wp-content/uploads/2019/08/Dotnet-Publish-Release-300x184.png 300w, /wp-content/uploads/2019/08/Dotnet-Publish-Release-425x261.png 425w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Dotnet Publish Release</figcaption></figure>



<p>Now go to the bin folder and then release folder, you should see a folder with the name netcoreapp2.1, inside this folder, there will be a folder win7-x64, this is the folder where your exe file, log file and other items are residing. </p>



<h3 class="wp-block-heading">Install the Service</h3>



<p>To install our Asp.Net console application as a windows service, you can use the sc command. Open the command prompt with administrator privilege and run the preceding command.</p>



<script src="https://gist.github.com/SibeeshVenu/cb8761b926f41000658ec14b9dcf1799.js"></script>



<p>And then you can start the service by running the command as &#8220;sc start BackupService&#8221;. This should start your service.</p>



<h3 class="wp-block-heading">Giving Permission to the Folders</h3>



<p>Sometimes you may get some permission issue in your service as it doesn&#8217;t have enough permission to read the files form the C drive. To overcome this, you should give enough permission to the user. You can do this by editing the security properties of those folders.</p>



<figure class="wp-block-image"><img decoding="async" width="649" height="412" src="https://sibeeshpassion.com/wp-content/uploads/2019/08/Setting-Permission-for-the-Users.png" alt="" class="wp-image-13886" srcset="/wp-content/uploads/2019/08/Setting-Permission-for-the-Users.png 649w, /wp-content/uploads/2019/08/Setting-Permission-for-the-Users-300x190.png 300w, /wp-content/uploads/2019/08/Setting-Permission-for-the-Users-425x270.png 425w" sizes="(max-width: 649px) 100vw, 649px" /><figcaption>Setting Permission for the Users</figcaption></figure>



<p>Do the same for the BackupZip folder as well.</p>



<h2 class="wp-block-heading">Output</h2>



<p>If you have run the service correctly, you should see a log file with the name  backupclientlogfile.txt inside your  win7-x64  folder. Once the service is run,  the logs will be written as follows.</p>



<script src="https://gist.github.com/SibeeshVenu/8173f2129e1f79fa4689e7d25d761807.js"></script>



<p>You can also check your Azure Storage account to check whether the files have uploaded correctly or not.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Wow!. Now we have learned,</p>



<ul class="wp-block-list"><li>about Windows Service and Asp.Net Console Application </li><li>about How to create a Windows Service using Asp.Net Core</li><li>about How to use Quartz scheduler</li><li>about How to use NLog in Windows Service</li><li>about How to configure Quartz scheduler to use Dependency Injection</li><li>about How to Zip a folder and save the file</li><li>about How to upload a file to the Azure blob storage</li></ul>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/asp-net-core-windows-service-task-scheduler-daily-weekly-monthly/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to Update Net Core 2.0 Application to 2.1 Version</title>
		<link>https://www.sibeeshpassion.com/how-to-update-net-core-2-0-application-to-2-1-version/</link>
					<comments>https://www.sibeeshpassion.com/how-to-update-net-core-2-0-application-to-2-1-version/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sat, 26 May 2018 09:13:30 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Asp.Net Core]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[.Net Core]]></category>
		<category><![CDATA[Dot Net Core]]></category>
		<category><![CDATA[Dot Net Core 2.0 to 2.1]]></category>
		<category><![CDATA[Dot Net Core 2.0 Vs Dot Net Core 2.1]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=12868</guid>

					<description><![CDATA[[toc] Introduction Many of you might have been developing applications in Net Core 2.0 version, as that was the main release with lots of features. But did you know that the next big release has already happened with some additional features in Net Core journey? Have you already migrated your applications to Dot Net Core 2.1.x version already? If you haven&#8217;t, no worries, here in this post, we are going to cover talk about how we can migrate/update our applications to the new version of Dot Net Core. I hope you will like this article. Background As I said, this [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Introduction</h2>
<p>Many of you might have been developing applications in Net Core 2.0 version, as that was the main release with lots of features. But did you know that the next big release has already happened with some additional features in Net Core journey? Have you already migrated your applications to Dot Net Core 2.1.x version already? If you haven&#8217;t, no worries, here in this post, we are going to cover talk about how we can migrate/update our applications to the new version of Dot Net Core. I hope you will like this article.</p>
<h2>Background</h2>
<p>As I said, this post is only going to cover the steps you may have to take to update your existing Dot Net Core application to 2.1.x. And I will be not be talking about what is Dot net core? And why dot net core is important? etc, if you have those queries in your mind, I strongly recommend you to read the Microsoft document <a href="https://docs.microsoft.com/en-in/dotnet/core/">here</a>.</p>
<p>We will be creating a Dot net Core 2.0 application first, and then we will update the same to 2.1.x version. Sounds good?</p>
<h2>.Net Core 2.0 to 2.1.x</h2>
<h3>Let&#8217;s create a .net core 2.0 application</h3>
<p>As usual open your favorite IDE, Visual Studio 2017, Click on File -&gt; New Project</p>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/05/Net-Core-2.0.jpg"><img decoding="async" class="alignnone wp-image-12869 size-full" src="https://sibeeshpassion.com/wp-content/uploads/2018/05/Net-Core-2.0.jpg" alt="" width="508" height="357" srcset="/wp-content/uploads/2018/05/Net-Core-2.0.jpg 508w, /wp-content/uploads/2018/05/Net-Core-2.0-300x211.jpg 300w, /wp-content/uploads/2018/05/Net-Core-2.0-768x540.jpg 768w, /wp-content/uploads/2018/05/Net-Core-2.0-400x281.jpg 400w, /wp-content/uploads/2018/05/Net-Core-2.0-853x600.jpg 853w" sizes="(max-width: 508px) 100vw, 508px" /></a></p>
<p>As you can see, Asp Net Core version is 2.0.</p>
<p>You can even check the version in your application properties.</p>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/05/Application-Menu.jpg"><img decoding="async" class="alignnone wp-image-12871" src="https://sibeeshpassion.com/wp-content/uploads/2018/05/Application-Menu.jpg" alt="" width="634" height="195" srcset="/wp-content/uploads/2018/05/Application-Menu.jpg 634w, /wp-content/uploads/2018/05/Application-Menu-300x92.jpg 300w, /wp-content/uploads/2018/05/Application-Menu-768x236.jpg 768w, /wp-content/uploads/2018/05/Application-Menu-400x123.jpg 400w" sizes="(max-width: 634px) 100vw, 634px" /></a></p>
<p>Now let&#8217;s run our application and see the output.</p>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/05/Result-From-NetCore2.0.jpg"><img decoding="async" class="alignnone size-full wp-image-12872" src="https://sibeeshpassion.com/wp-content/uploads/2018/05/Result-From-NetCore2.0.jpg" alt="" width="505" height="100" srcset="/wp-content/uploads/2018/05/Result-From-NetCore2.0.jpg 505w, /wp-content/uploads/2018/05/Result-From-NetCore2.0-300x59.jpg 300w, /wp-content/uploads/2018/05/Result-From-NetCore2.0-400x79.jpg 400w" sizes="(max-width: 505px) 100vw, 505px" /></a></p>
<h3>Update Visual Studio 2017 to the latest</h3>
<p>As a first step, to work with Dot net core 2.1 you need to update your IDE. There are a couple of ways you can update your IDE, but the easiest way is to go check the Notifications panel. Let&#8217;s see how to do that.</p>
<p>Go to the View tab and click on Notifications</p>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/05/Notification-Menu.jpg"><img decoding="async" class="alignnone size-full wp-image-12873" src="https://sibeeshpassion.com/wp-content/uploads/2018/05/Notification-Menu.jpg" alt="" width="406" height="433" srcset="/wp-content/uploads/2018/05/Notification-Menu.jpg 335w, /wp-content/uploads/2018/05/Notification-Menu-281x300.jpg 281w, /wp-content/uploads/2018/05/Notification-Menu-400x427.jpg 400w" sizes="(max-width: 406px) 100vw, 406px" /></a></p>
<p>Now you can see all the notifications here as shown in the below image. I always update my Visual Studio whenever there is an update, so you won&#8217;t be able to see that notification here on my panel. If you haven&#8217;t updated, and if you check the Notifications panel, I am sure you will get a link to the update here. You will be able to do further.</p>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/05/Notification-Panel.jpg"><img decoding="async" class="alignnone size-full wp-image-12874" src="https://sibeeshpassion.com/wp-content/uploads/2018/05/Notification-Panel.jpg" alt="" width="373" height="440" srcset="/wp-content/uploads/2018/05/Notification-Panel.jpg 303w, /wp-content/uploads/2018/05/Notification-Panel-254x300.jpg 254w" sizes="(max-width: 373px) 100vw, 373px" /></a></p>
<p>Once you have updated, you can verify your version.</p>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/05/Visual-Studio-15.7.2-1.jpg"><img decoding="async" class="alignnone wp-image-12876" src="https://sibeeshpassion.com/wp-content/uploads/2018/05/Visual-Studio-15.7.2-1.jpg" alt="" width="634" height="381" srcset="/wp-content/uploads/2018/05/Visual-Studio-15.7.2-1.jpg 594w, /wp-content/uploads/2018/05/Visual-Studio-15.7.2-1-300x180.jpg 300w, /wp-content/uploads/2018/05/Visual-Studio-15.7.2-1-768x462.jpg 768w, /wp-content/uploads/2018/05/Visual-Studio-15.7.2-1-400x241.jpg 400w" sizes="(max-width: 634px) 100vw, 634px" /></a></p>
<h3>Install latest Dot Net Core</h3>
<p>Here I am going to download the latest version from <a href="https://www.microsoft.com/net/download/dotnet-core/sdk-2.1.300-preview1">here</a>, however, you can select which version you want from <a href="https://www.microsoft.com/net/download">here</a>.</p>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/05/Dot-Net-Core-2.1-With-Run-Time.jpg"><img decoding="async" class="alignnone wp-image-12879" src="https://sibeeshpassion.com/wp-content/uploads/2018/05/Dot-Net-Core-2.1-With-Run-Time.jpg" alt="" width="634" height="470" srcset="/wp-content/uploads/2018/05/Dot-Net-Core-2.1-With-Run-Time.jpg 482w, /wp-content/uploads/2018/05/Dot-Net-Core-2.1-With-Run-Time-300x222.jpg 300w, /wp-content/uploads/2018/05/Dot-Net-Core-2.1-With-Run-Time-768x569.jpg 768w, /wp-content/uploads/2018/05/Dot-Net-Core-2.1-With-Run-Time-400x296.jpg 400w, /wp-content/uploads/2018/05/Dot-Net-Core-2.1-With-Run-Time-810x600.jpg 810w" sizes="(max-width: 634px) 100vw, 634px" /></a></p>
<p>As you can see that we have installed Dot Net Core SDK, Dot Net Core Runtime, Asp Net Core Runtime, and now you can see that the new version is available for you in Visual Studio 2017.</p>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/05/Select-Dot-Net-Core-2.1.jpg"><img decoding="async" class="alignnone size-full wp-image-12880" src="https://sibeeshpassion.com/wp-content/uploads/2018/05/Select-Dot-Net-Core-2.1.jpg" alt="" width="523" height="290" srcset="/wp-content/uploads/2018/05/Select-Dot-Net-Core-2.1.jpg 523w, /wp-content/uploads/2018/05/Select-Dot-Net-Core-2.1-300x166.jpg 300w, /wp-content/uploads/2018/05/Select-Dot-Net-Core-2.1-400x222.jpg 400w" sizes="(max-width: 523px) 100vw, 523px" /></a></p>
<h3>Changing the Target frameworks</h3>
<p>As the first step, we need to change the Target framework for our application. Here you can select it in the Properties or you can edit the dot(.)csproj file.</p>
<p>Now it is time to change the Microsoft.AspNetCore.All to Microsoft.AspNetCore.App, as with this version Microsoft have reduced the number of dependencies. We always need to install only the needed things right, instead of everything.</p>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/05/Microsoft-NetCore-All-to-NetCore-App.jpg"><img decoding="async" class="alignnone wp-image-12881 size-full" src="https://sibeeshpassion.com/wp-content/uploads/2018/05/Microsoft-NetCore-All-to-NetCore-App-e1527325484490.jpg" alt="" width="634" height="230" /></a></p>
<p>You will always need to change all of your references to the new version. Here I just wanted to show how you can do that. So, look into the packages you have in your application and change it accordingly.</p>
<h2>What is new in Dot(.) Net Core 2.1.x</h2>
<p>The Dot Net Core 2.1.x is a release with some cool new features, I strongly recommend you to read those <a href="https://blogs.msdn.microsoft.com/dotnet/2018/05/07/announcing-net-core-2-1-rc-1/">here.</a></p>
<p>I may write a new post with this features soon.</p>
<h2><span id="conclusion">Conclusion</span></h2>
<p>Thanks a lot for reading. Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h2><span id="your-turn-what-do-you-think">Your turn. What do you think?</span></h2>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/how-to-update-net-core-2-0-application-to-2-1-version/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>LINQ Basic To Advanced &#8211; MVC Demo Application</title>
		<link>https://www.sibeeshpassion.com/linq-basic-to-advanced-mvc-demo-application/</link>
					<comments>https://www.sibeeshpassion.com/linq-basic-to-advanced-mvc-demo-application/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 15 May 2017 16:09:40 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[LINQ Queries]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=12365</guid>

					<description><![CDATA[[toc] Introduction Here, in this post we are going to a see some LINQ queries, which covers both basics and advanced. LINQ queries are introduced few years back to offer a consistent way for working with data across many datasources and formats. In LINQ queries, you will always work with objects, which makes it simple to write. I hope you would have already written lots of LINQ queries already, if you haven&#8217;t, I strongly reccommend you to read this blog where you can find the answer for, why do we need to use LINQ?. Here I am going to create [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h3>Introduction</h3>
<p>Here, in this post we are going to a see some <a href="http://sibeeshpassion.com/tag/LINQ" target="_blank" rel="noopener noreferrer">LINQ</a> queries, which covers both basics and advanced. LINQ queries are introduced few years back to offer a consistent way for working with data across many datasources and formats. In LINQ queries, you will always work with objects, which makes it simple to write. I hope you would have already written lots of LINQ queries already, if you haven&#8217;t, I strongly reccommend you to read this <a href="https://docs.microsoft.com/en-us/dotnet/articles/csharp/programming-guide/concepts/linq/introduction-to-linq-queries" target="_blank" rel="noopener">blog </a> where you can find the answer for, why do we need to use LINQ?. Here I am going to create a <a href="http://sibeeshpassion.com/category/mvc/">MVC</a> demo application. I hope you will like this. Now let&#8217;s begin.</p>
<h3>Download Source Code</h3>
<li><a href="https://code.msdn.microsoft.com/LINQ-Basic-To-Advanced-MVC-cc3b8254" target="_blank" rel="noopener">LINQ_B_To_A</a></li>
<h3>Background</h3>
<p>Whenever I get a chance to write some server side codes in <a href="http://sibeeshpassion.com/category/csharp/" target="_blank" rel="noopener">C#</a>, I always write it using LINQ. And few weeks back, I was assigned to a training programme where my job was to teach LINQ, hence this post covers the the queries I have written for the training programme. Hope you will find it useful.</p>
<h3>Using the code</h3>
<p>A LINQ query can be written in two ways.</p>
<li>Query Syntax</li>
<li>Method Chain or Using dot(.) operator</li>
<p>There are so many articles available in the Internet on the topic LINQ, but most of them dont cover the differences of writing the queries in two possible ways, the motive of this article is to write the queries in both ways, so that you can understand the differnces.</p>
<p>As I mentioned, we are going to create an MVC application, we need to create it first and then configure the entity. Let&#8217;s go and do that.</p>
<h4>Create a database</h4>
<p>To get started with we need to configure our database first. To do so, either you can download the Wild World Importers from <a href="https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v1.0" target="_blank" rel="noopener">here</a> or you can run the script file included in the downlaod link above. </p>
<p>Once after you created the database, you can create your MVC application and Entity Data Model in it. </p>
<h4>Configuring MVC application with Entity Data Model</h4>
<p>By this time, I hope you would have configured your MVC application with Entity Data Model. Now it is time to create a controller and Entity object. </p>
<p>[csharp]<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Data.Entity;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.Mvc;<br />
using System.Windows.Forms;<br />
using LINQ_B_to_A.Models;<br />
namespace LINQ_B_to_A.Controllers<br />
{<br />
    public class HomeController : Controller<br />
    {<br />
        // GET: Home</p>
<p>        public MyDataModel DtContext { get; set; } = new MyDataModel();<br />
    }<br />
}<br />
[/csharp]</p>
<p>Now we can write some LINQ queries as everything is set to get started.</p>
<h4>Setting up the Index view with possible actions</h4>
<p>This is just to call the actions we are going write. Let&#8217;s see the Index page now. </p>
<p>[html]<br />
@{<br />
    ViewBag.Title = &quot;Index&quot;;<br />
    Layout = &quot;~/Views/Shared/_Layout.cshtml&quot;;<br />
}</p>
<p>&lt;h2&gt;Index&lt;/h2&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;LoadAll&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Load All &#8211; Query Expression&quot;/&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;JoinWithWhere&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Join With Where&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;LeftJoin&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Left Join&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;DistinctSample&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Distinct Sample&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;EqualsSamples&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Equals Sample&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;NotEqualsSamples&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Not Equals&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;PagingQueries&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Paging Queries&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;MathQueries&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Math Queries&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;StringQueries&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;String Queries&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;SelectMany&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Select Many&quot; /&gt;<br />
[/html]</p>
<p><div id="attachment_12367" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Index-View-e1494741059608.png"><img decoding="async" aria-describedby="caption-attachment-12367" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Index-View-e1494741059608.png" alt="LINQ Basic to Advanced Index View" width="634" height="197" class="size-full wp-image-12367" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Index-View-e1494741059608.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Index-View-e1494741059608-300x93.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Index-View-e1494741059608-400x124.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12367" class="wp-caption-text">LINQ Basic to Advanced Index View</p></div></p>
<h4>Normal Select Query With StartWith and Take</h4>
<p>Let&#8217;s have a look at the preceding query.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq query with Select<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult LoadAll()<br />
        {<br />
            var loadAllData = (from d in DtContext.Cities where d.CityName.StartsWith(&quot;C&quot;) select d).Take(10);</p>
<p>            //Method Chain Format<br />
            var loadAllData1 = DtContext.Cities.Where(d =&gt; d.CityName.StartsWith(&quot;C&quot;)).Take(10);</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
[/csharp]</p>
<p>As you can see, we are just fetching the data from Cities in both ways. And we are using StartWith as a filter, which actually looks for the city names which starts with the letter C, and finally we are taking 10 elements from it. The first query is the &#8220;Query syntax&#8221; and the second one is &#8220;Method chain&#8221;. Personally I like the second way. How about you?</p>
<p>[html]<br />
@model IQueryable&lt;LINQ_B_to_A.Models.City&gt;<br />
&lt;style&gt;<br />
    dd, dt, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    dd {<br />
        background-color: #a9a9a9<br />
    }<br />
    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;<br />
&lt;dd&gt;City Names&lt;/dd&gt;<br />
@foreach (var ctyObj in Model)<br />
{<br />
    &lt;dt&gt;@ctyObj.CityName&lt;/dt&gt;<br />
}<br />
&lt;pre&gt;<br />
        public ActionResult LoadAll()<br />
        {<br />
            var loadAllData = (from d in DtContext.Cities where d.CityName.StartsWith(&quot;C&quot;) select d).Take(10);</p>
<p>            //Method Chain Format<br />
            var loadAllData1 = DtContext.Cities.Where(d =&gt; d.CityName.StartsWith(&quot;C&quot;)).Take(10);</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>We are ready to see our first query in action now. </p>
<p>Let&#8217;s creat a partial view now to show the data we fetched. <a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Normal-Select-Query-With-StartsWith-and-Take-e1494741383811.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Normal-Select-Query-With-StartsWith-and-Take-e1494741383811.png" alt="LINQ Basic to Advanced Normal Select Query With StartsWith and Take" width="634" height="400" class="alignnone size-full wp-image-12368" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Normal-Select-Query-With-StartsWith-and-Take-e1494741383811.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Normal-Select-Query-With-StartsWith-and-Take-e1494741383811-300x189.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Normal-Select-Query-With-StartsWith-and-Take-e1494741383811-400x252.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a></p>
<h4>JOIN Query</h4>
<p>To write a join, the query would be as preceding.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq query with join and where<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult JoinWithWhere()<br />
        {<br />
            var loadAllData = (from oOrders in DtContext.Orders<br />
                               join oOrderLines in DtContext.OrderLines<br />
                               on oOrders.OrderID equals oOrderLines.OrderID<br />
                               orderby oOrders.OrderID<br />
                               select new OrderAndOrderLines()<br />
                               {<br />
                                   OrderId = oOrders.OrderID,<br />
                                   Description = oOrderLines.Description,<br />
                                   Quantity = oOrderLines.Quantity<br />
                               }).Take(10);<br />
            //Method Chain Format<br />
            var asMethodChain = DtContext.Orders.Join(DtContext.OrderLines, oOrders =&gt; oOrders.OrderID,<br />
                    oOrderLines =&gt; oOrderLines.OrderID,<br />
                    (oOrders, oOrderLines) =&gt; new { oOrders, oOrderLines })<br />
                .OrderBy(@o =&gt; @o.oOrders.OrderID)<br />
                .Select(@s =&gt; new OrderAndOrderLines()<br />
                {<br />
                    OrderId = @s.oOrders.OrderID,<br />
                    Description = @s.oOrderLines.Description,<br />
                    Quantity = @s.oOrderLines.Quantity<br />
                }).Take(10);</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
[/csharp]</p>
<p>In the above query we are just joining the tables Order and OrderLines with OrderID and to select we are using an another custom model OrderAndOrderLines. </p>
<p>[csharp]<br />
namespace LINQ_B_to_A.Models<br />
{<br />
    public partial class OrderAndOrderLines<br />
    {<br />
        public int OrderId { get; set; }<br />
        public string Description { get; set; }<br />
        public int? Quantity { get; set; }<br />
    }<br />
}<br />
[/csharp]</p>
<p>The view can be written as follows.</p>
<p>[html]<br />
@model IEnumerable&lt;LINQ_B_to_A.Models.OrderAndOrderLines&gt;<br />
&lt;style&gt;<br />
    td, th, thead,pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }<br />
    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>&lt;table&gt;<br />
    &lt;caption&gt;Order Details&lt;/caption&gt;<br />
    &lt;tr&gt;<br />
        &lt;th&gt;Order ID&lt;/th&gt;<br />
        &lt;th&gt;Description&lt;/th&gt;<br />
        &lt;th&gt;Quantity&lt;/th&gt;<br />
    &lt;/tr&gt;<br />
    @foreach (var @item in Model)<br />
    {<br />
        &lt;tr&gt;<br />
            &lt;td&gt;@item.OrderId&lt;/td&gt;<br />
            &lt;td&gt;@item.Description&lt;/td&gt;<br />
            &lt;td&gt;@item.Quantity&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    }<br />
&lt;/table&gt;<br />
&lt;pre&gt;<br />
     public ActionResult JoinWithWhere()<br />
        {<br />
            var loadAllData = (from oOrders in DtContext.Orders<br />
                               join oOrderLines in DtContext.OrderLines<br />
                               on oOrders.OrderID equals oOrderLines.OrderID<br />
                               orderby oOrders.OrderID<br />
                               select new OrderAndOrderLines()<br />
                               {<br />
                                   OrderId = oOrders.OrderID,<br />
                                   Description = oOrderLines.Description,<br />
                                   Quantity = oOrderLines.Quantity<br />
                               }).Take(10);<br />
            //Method Chain Format<br />
            var asMethodChain = DtContext.Orders.Join(DtContext.OrderLines, oOrders =&gt; oOrders.OrderID,<br />
                    oOrderLines =&gt; oOrderLines.OrderID,<br />
                    (oOrders, oOrderLines) =&gt; new { oOrders, oOrderLines })<br />
                .OrderBy(o =&gt; o.oOrders.OrderID)<br />
                .Select(s =&gt; new OrderAndOrderLines()<br />
                {<br />
                    OrderId = s.oOrders.OrderID,<br />
                    Description = s.oOrderLines.Description,<br />
                    Quantity = s.oOrderLines.Quantity<br />
                }).Take(10);</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Once you run the action you can see the result as follows. </p>
<p><div id="attachment_12369" style="width: 1654px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Join-With-Where-e1494742473978.png"><img decoding="async" aria-describedby="caption-attachment-12369" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Join-With-Where-e1494742473978.png" alt="LINQ Basic to Advanced Join With Where" width="1644" height="821" class="size-full wp-image-12369" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Join-With-Where-e1494742473978.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Join-With-Where-e1494742473978-300x150.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Join-With-Where-e1494742473978-400x200.png 400w" sizes="(max-width: 1644px) 100vw, 1644px" /></a><p id="caption-attachment-12369" class="wp-caption-text">LINQ Basic to Advanced Join With Where</p></div></p>
<h4>Left JOIN Query</h4>
<p>To write a Left join, the query would be as preceding.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq query with Left Join<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult LeftJoin()<br />
        {<br />
            var loadAllData = (from oOrder in DtContext.Orders<br />
                               join oOrderLine in DtContext.OrderLines<br />
                               on oOrder.OrderID equals oOrderLine.OrderID<br />
                               into lftOrder<br />
                               from afterJoined in lftOrder.DefaultIfEmpty()<br />
                               orderby oOrder.OrderID descending<br />
                               select new OrderAndOrderLines()<br />
                               {<br />
                                   OrderId = oOrder.OrderID,<br />
                                   Description = afterJoined.Description<br />
                               }).Take(10).ToList();<br />
            //Method Chain Format<br />
            var lftJoinMethodChain = (DtContext.Orders.GroupJoin(DtContext.OrderLines,<br />
                    oOrder =&gt; oOrder.OrderID, oOrderLine =&gt; oOrderLine.OrderID,<br />
                    (oOrder, lftJoin) =&gt; new { oOrder, lftJoin })<br />
                .SelectMany(@sm =&gt; @sm.lftJoin.DefaultIfEmpty(), (@sm, afterJoin) =&gt; new { @sm, afterJoin })<br />
                .OrderByDescending(@o =&gt; @o.sm.oOrder.OrderID)<br />
                .Select(@s =&gt; new OrderAndOrderLines()<br />
                {<br />
                    OrderId = @s.sm.oOrder.OrderID,<br />
                    Description = @s.afterJoin.Description<br />
                })).Take(10).ToList();</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
[/csharp]</p>
<p>In the above query we are just joining the tables Order and OrderLines with OrderID and to select we are using an another custom model OrderAndOrderLines as our previous query. The differences you could find here are, using an &#8216;into&#8217; and &#8216;DefaultIfEmpty&#8217; statements. The DefaultIfEmpty is making sure that it returns empty if there is no appropriate rows found in the second table. </p>
<p>The view can be written as follows.</p>
<p>[html]<br />
@model IEnumerable&lt;LINQ_B_to_A.Models.OrderAndOrderLines&gt;<br />
&lt;style&gt;<br />
    td, th, thead, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }<br />
    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>&lt;table&gt;<br />
    &lt;caption&gt;Order Details&lt;/caption&gt;<br />
    &lt;tr&gt;<br />
        &lt;th&gt;Order ID&lt;/th&gt;<br />
        &lt;th&gt;Description&lt;/th&gt;<br />
        &lt;th&gt;Quantity&lt;/th&gt;<br />
    &lt;/tr&gt;<br />
    @foreach (var @item in Model)<br />
    {<br />
        &lt;tr&gt;<br />
            &lt;td&gt;@item.OrderId&lt;/td&gt;<br />
            &lt;td&gt;@item.Description&lt;/td&gt;<br />
            &lt;td&gt;@item.Quantity&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    }<br />
&lt;/table&gt;<br />
&lt;pre&gt;<br />
    public ActionResult LeftJoin()<br />
        {<br />
            var loadAllData = (from oOrder in DtContext.Orders<br />
                               join oOrderLine in DtContext.OrderLines<br />
                               on oOrder.OrderID equals oOrderLine.OrderID<br />
                               into lftOrder<br />
                               from afterJoined in lftOrder.DefaultIfEmpty()<br />
                               orderby oOrder.OrderID descending<br />
                               select new OrderAndOrderLines()<br />
                               {<br />
                                   OrderId = oOrder.OrderID,<br />
                                   Description = afterJoined.Description<br />
                               }).Take(10).ToList();<br />
            //Method Chain Format<br />
            var lftJoinMethodChain = (DtContext.Orders.GroupJoin(DtContext.OrderLines,<br />
                    oOrder =&gt; oOrder.OrderID, oOrderLine =&gt; oOrderLine.OrderID,<br />
                    (oOrder, lftJoin) =&gt; new { oOrder, lftJoin })<br />
                .SelectMany(sm =&gt; sm.lftJoin.DefaultIfEmpty(), (sm, afterJoin) =&gt; new { sm, afterJoin })<br />
                .OrderByDescending(o =&gt; o.sm.oOrder.OrderID)<br />
                .Select(s =&gt; new OrderAndOrderLines()<br />
                {<br />
                    OrderId = s.sm.oOrder.OrderID,<br />
                    Description = s.afterJoin.Description<br />
                })).Take(10).ToList();</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Once you run the action you can see the result as follows. </p>
<p><div id="attachment_12370" style="width: 1658px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Left-Join-e1494742942417.png"><img decoding="async" aria-describedby="caption-attachment-12370" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Left-Join-e1494742942417.png" alt="LINQ Basic to Advanced Left Join" width="1648" height="820" class="size-full wp-image-12370" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Left-Join-e1494742942417.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Left-Join-e1494742942417-300x149.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Left-Join-e1494742942417-400x199.png 400w" sizes="(max-width: 1648px) 100vw, 1648px" /></a><p id="caption-attachment-12370" class="wp-caption-text">LINQ Basic to Advanced Left Join</p></div></p>
<p>As you can see in the image, the order id 200000 doesn&#8217;t has any appropriate rows in the second table, so it shows as empty.</p>
<h4>Distinct Query</h4>
<p>The below query shows how we can write simple distinct query.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq query Distinct sample<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult DistinctSample()<br />
        {<br />
            var distictSample = (from oOrder in DtContext.OrderLines<br />
                                 select oOrder.Description).Distinct().Take(10).ToList();</p>
<p>            //Method Chain Format<br />
            var distictAsMethodChain = (DtContext.OrderLines.Select(oOrder =&gt; oOrder.Description)).Distinct().Take(10).ToList();</p>
<p>            return PartialView(distictSample);<br />
        }<br />
[/csharp]</p>
<p>In the above query we use Distinct to make sure that only distict items are selected from the result. The view can be written as follows.</p>
<p>[html]<br />
@model  List&lt;string&gt;<br />
&lt;style&gt;<br />
    dd, dt, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    dd {<br />
        background-color: #a9a9a9<br />
    }</p>
<p>    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;<br />
&lt;dd&gt;Order Descriptions&lt;/dd&gt;<br />
@foreach (var orderLinesyObj in Model)<br />
{<br />
    &lt;dt&gt;@orderLinesyObj&lt;/dt&gt;<br />
}<br />
&lt;pre&gt;<br />
    public ActionResult DistinctSample()<br />
        {<br />
            var distictSample = (from oOrder in DtContext.OrderLines<br />
                                 select oOrder.Description).Distinct().Take(10).ToList();</p>
<p>            //Method Chain Format<br />
            var distictAsMethodChain = (DtContext.OrderLines.Select(oOrder =&gt; oOrder.Description)).Distinct().Take(10).ToList();</p>
<p>            return PartialView(distictSample);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Once you run the action you can see the result as follows.</p>
<p><div id="attachment_12371" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Distinct-Query-e1494743542508.png"><img decoding="async" aria-describedby="caption-attachment-12371" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Distinct-Query-e1494743542508.png" alt="LINQ Basic to Advanced Distinct Query" width="634" height="372" class="size-full wp-image-12371" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Distinct-Query-e1494743542508.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Distinct-Query-e1494743542508-300x176.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Distinct-Query-e1494743542508-400x235.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12371" class="wp-caption-text">LINQ Basic to Advanced Distinct Query</p></div></p>
<h4>Equals and Not Equals Queries</h4>
<p>We can write the equals and not equals query as preceding.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq query Equals sample<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult EqualsSamples()<br />
        {<br />
            var objEquals = (from objCity in DtContext.Cities<br />
                             where objCity.CityName.Equals(&quot;Troy&quot;)<br />
                             select objCity).Take(2);<br />
            //Method Chain Format<br />
            var objEquals1 = DtContext.Cities.Where(d =&gt; d.CityName.Equals(&quot;Troy&quot;)).Take(2);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objEquals);<br />
        }</p>
<p>        /// &lt;summary&gt;<br />
        /// Linq query Not Equals sample<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult NotEqualsSamples()<br />
        {<br />
            var objNotEquals = (from objCity in DtContext.Cities<br />
                                where objCity.CityName != &quot;Troy&quot;<br />
                                select objCity).Take(5);</p>
<p>            var objNotEquals1 = (from objCity in DtContext.Cities<br />
                                 where !objCity.CityName.Equals(&quot;Troy&quot;)<br />
                                 select objCity).Take(5);</p>
<p>            //Method Chain Format<br />
            var objNotEquals2 = DtContext.Cities.Where(d =&gt; d.CityName != &quot;Troy&quot;).Take(2);</p>
<p>            var objNotEquals3 = DtContext.Cities.Where(d =&gt; !d.CityName.Equals(&quot;Troy&quot;)).Take(2);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objNotEquals);<br />
        }<br />
[/csharp]</p>
<p>The view can be written as follows.</p>
<p>[html]<br />
@model IQueryable&lt;LINQ_B_to_A.Models.City&gt;<br />
&lt;style&gt;<br />
    td, th, thead, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }</p>
<p>    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>    &lt;table&gt;<br />
        &lt;caption&gt;City Details&lt;/caption&gt;<br />
        &lt;tr&gt;<br />
            &lt;th&gt;City ID&lt;/th&gt;<br />
            &lt;th&gt;City Name&lt;/th&gt;<br />
            &lt;th&gt;City Location&lt;/th&gt;<br />
        &lt;/tr&gt;<br />
@foreach (var @item in Model)<br />
{<br />
    &lt;tr&gt;<br />
    &lt;td&gt;@item.CityID&lt;/td&gt;<br />
    &lt;td&gt;@item.CityName&lt;/td&gt;<br />
    &lt;td&gt;@item.Location&lt;/td&gt;<br />
    &lt;/tr&gt;<br />
}<br />
    &lt;/table&gt;<br />
&lt;caption&gt;Equals Oerator&lt;/caption&gt;<br />
&lt;pre&gt;<br />
    public ActionResult EqualsSamples()<br />
        {<br />
            var objEquals = (from objCity in DtContext.Cities<br />
                                       where objCity.CityName.Equals(&quot;Troy&quot;)<br />
                                       select objCity).Take(2);<br />
            //Method Chain Format<br />
            var objEquals1 = DtContext.Cities.Where(d =&gt; d.CityName.Equals(&quot;Troy&quot;)).Take(2);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objEquals);<br />
        }</p>
<p>        public ActionResult NotEqualsSamples()<br />
        {<br />
            var objNotEquals = (from objCity in DtContext.Cities<br />
                where objCity.CityName != &quot;Troy&quot;<br />
                select objCity).Take(5);</p>
<p>            var objNotEquals1 = (from objCity in DtContext.Cities<br />
                where !objCity.CityName.Equals(&quot;Troy&quot;)<br />
                select objCity).Take(5);</p>
<p>            //Method Chain Format<br />
            var objNotEquals2 = DtContext.Cities.Where(d =&gt; d.CityName != &quot;Troy&quot;).Take(2);</p>
<p>            var objNotEquals3 = DtContext.Cities.Where(d =&gt; !d.CityName.Equals(&quot;Troy&quot;)).Take(2);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objNotEquals);<br />
        }</p>
<p>        public ActionResult PagingQueries()<br />
        {<br />
            var objNotEquals = (from objCity in DtContext.Cities<br />
                where objCity.CityName != &quot;Troy&quot;<br />
                orderby objCity.CityName ascending<br />
                select objCity).Skip(5).Take(5);</p>
<p>            //Method Chain Format<br />
            var objNotEquals2 = DtContext.Cities.Where(d =&gt; d.CityName != &quot;Troy&quot;).Skip(5).Take(5);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objNotEquals);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Once you run the action you can see the result as follows.</p>
<p><div id="attachment_12372" style="width: 1622px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Equals-and-Not-Equals-e1494744042305.png"><img decoding="async" aria-describedby="caption-attachment-12372" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Equals-and-Not-Equals-e1494744042305.png" alt="LINQ Basic to Advanced Equals and Not Equals" width="1612" height="560" class="size-full wp-image-12372" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Equals-and-Not-Equals-e1494744042305.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Equals-and-Not-Equals-e1494744042305-300x104.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Equals-and-Not-Equals-e1494744042305-400x139.png 400w" sizes="(max-width: 1612px) 100vw, 1612px" /></a><p id="caption-attachment-12372" class="wp-caption-text">LINQ Basic to Advanced Equals and Not Equals</p></div></p>
<h4>LINQ Paging Queries</h4>
<p>Paging queries are always important as we work in some grid controls, with LINQ those are very easy. Let&#8217;s see one of that query. </p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq Paging Queries<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult PagingQueries()<br />
        {<br />
            var objNotEquals = (from objCity in DtContext.Cities<br />
                                where objCity.CityName != &quot;Troy&quot;<br />
                                orderby objCity.CityName ascending<br />
                                select objCity).Skip(5).Take(5);</p>
<p>            //Method Chain Format<br />
            var objNotEquals2 = DtContext.Cities.Where(d =&gt; d.CityName != &quot;Troy&quot;).Skip(5).Take(5);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objNotEquals);<br />
        }<br />
[/csharp]</p>
<p>Once you run the action you can see the result as follows.</p>
<p><div id="attachment_12373" style="width: 1611px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Paging-Queries-e1494744396637.png"><img decoding="async" aria-describedby="caption-attachment-12373" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Paging-Queries-e1494744396637.png" alt="LINQ Basic to Advanced Paging Queries" width="1601" height="862" class="size-full wp-image-12373" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Paging-Queries-e1494744396637.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Paging-Queries-e1494744396637-300x161.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Paging-Queries-e1494744396637-400x215.png 400w" sizes="(max-width: 1601px) 100vw, 1601px" /></a><p id="caption-attachment-12373" class="wp-caption-text">LINQ Basic to Advanced Paging Queries</p></div></p>
<h4>LINQ Math Queries</h4>
<p>Here we are going to write the possible Math functions in our LINQ query.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Math Queries<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult MathQueries()<br />
        {<br />
            var objMath = (from objInv in DtContext.InvoiceLines<br />
                           where objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15<br />
                           orderby objInv.InvoiceLineID descending<br />
                           select new MathClass()<br />
                           {<br />
                               Actual = objInv.ExtendedPrice,<br />
                               Round = Math.Round(objInv.ExtendedPrice),<br />
                               Floor = Math.Floor(objInv.ExtendedPrice),<br />
                               Ceiling = Math.Ceiling(objInv.ExtendedPrice),<br />
                               Abs = Math.Abs(objInv.ExtendedPrice)<br />
                           }).Take(10);</p>
<p>            //Method Chain Format<br />
            var objMath2 = DtContext.InvoiceLines<br />
                .Where(objInv =&gt; objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15)<br />
                .OrderByDescending(o =&gt; o.InvoiceLineID)<br />
                .Select(objInv =&gt; new MathClass()<br />
                {<br />
                    Actual = objInv.ExtendedPrice,<br />
                    Round = Math.Round(objInv.ExtendedPrice),<br />
                    Floor = Math.Floor(objInv.ExtendedPrice),<br />
                    Ceiling = Math.Ceiling(objInv.ExtendedPrice),<br />
                    Abs = Math.Abs(objInv.ExtendedPrice)<br />
                }).Take(10);</p>
<p>            return PartialView(&quot;MathQueries&quot;, objMath);<br />
        }<br />
[/csharp]</p>
<p>As you can see we have written most of the possible Math functions in our query and selecting with a custome model MathClass.</p>
<p>[csharp]<br />
namespace LINQ_B_to_A.Models<br />
{<br />
    public partial class MathClass<br />
    {<br />
        public decimal Actual { get; set; }<br />
        public decimal Round { get; set; }<br />
        public decimal Floor { get; set; }<br />
        public decimal Ceiling { get; set; }<br />
        public decimal Abs { get; set; }<br />
    }<br />
}<br />
[/csharp]</p>
<p>Let&#8217;s see the view now. </p>
<p>[html]</p>
<p>@model IQueryable&lt;LINQ_B_to_A.Models.MathClass&gt;<br />
&lt;style&gt;<br />
    td, th, thead, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }</p>
<p>    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>&lt;table&gt;<br />
    &lt;caption&gt;Math Operators&lt;/caption&gt;<br />
    &lt;tr&gt;</p>
<p>    &lt;/tr&gt;<br />
    @foreach (var @item in Model)<br />
    {<br />
        &lt;tr&gt;<br />
            &lt;td&gt;Actual: @item.Actual&lt;/td&gt;<br />
            &lt;td&gt;Round: @item.Round&lt;/td&gt;<br />
            &lt;td&gt;Floor: @item.Floor&lt;/td&gt;<br />
            &lt;td&gt;Ceiling: @item.Ceiling&lt;/td&gt;<br />
            &lt;td&gt;Abs: @item.Abs&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    }<br />
&lt;/table&gt;<br />
&lt;pre&gt;<br />
    public ActionResult MathQueries()<br />
        {<br />
            var objMath = (from objInv in DtContext.InvoiceLines<br />
                          where objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15<br />
                          orderby objInv.InvoiceLineID descending<br />
                          select new MathClass()<br />
                          {<br />
                              Actual = objInv.ExtendedPrice,<br />
                              Round = Math.Round(objInv.ExtendedPrice),<br />
                              Floor = Math.Floor(objInv.ExtendedPrice),<br />
                              Ceiling = Math.Ceiling(objInv.ExtendedPrice),<br />
                              Abs = Math.Abs(objInv.ExtendedPrice)<br />
                          }).Take(10);</p>
<p>            //Method Chain Format<br />
            var objMath2 = DtContext.InvoiceLines<br />
                .Where(objInv =&gt; objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15)<br />
                .OrderByDescending(o =&gt; o.InvoiceLineID)<br />
                .Select(objInv =&gt; new MathClass()<br />
                {<br />
                    Actual = objInv.ExtendedPrice,<br />
                    Round = Math.Round(objInv.ExtendedPrice),<br />
                    Floor = Math.Floor(objInv.ExtendedPrice),<br />
                    Ceiling = Math.Ceiling(objInv.ExtendedPrice),<br />
                    Abs = Math.Abs(objInv.ExtendedPrice)<br />
                }).Take(10);</p>
<p>            return PartialView(&quot;MathQueries&quot;, objMath);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>See the result now.</p>
<p><div id="attachment_12374" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496.png"><img decoding="async" aria-describedby="caption-attachment-12374" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496.png" alt="LINQ Basic to Advanced Math Queries" width="634" height="673" class="size-full wp-image-12374" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496.png 336w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496-283x300.png 283w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496-400x425.png 400w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496-565x600.png 565w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12374" class="wp-caption-text">LINQ Basic to Advanced Math Queries</p></div></p>
<h4>LINQ String Queries</h4>
<p>As we saw the Math queries, here we are going to write the possible String functions in our LINQ query.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// String Queries<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult StringQueries()<br />
        {<br />
            var objString = (from objInv in DtContext.InvoiceLines<br />
                             where objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15<br />
                             orderby objInv.InvoiceLineID descending<br />
                             select new StringClass()<br />
                             {<br />
                                 Actual = objInv.Description,<br />
                                 Insert = objInv.Description.Insert(2, &quot;sibeeshpassion&quot;),<br />
                                 Remove = objInv.Description.Remove(1, 1),<br />
                                 Substring = objInv.Description.Substring(2, 3),<br />
                                 ToLower = objInv.Description.ToLower(),<br />
                                 ToUpper = objInv.Description.ToUpper(),<br />
                                 TrimEnd = objInv.Description.TrimEnd(),<br />
                                 TrimStart = objInv.Description.TrimStart()<br />
                             }).Take(2);</p>
<p>            //Method Chain Format<br />
            var objString2 = DtContext.InvoiceLines<br />
                .Where(objInv =&gt; objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15)<br />
                .OrderByDescending(o =&gt; o.InvoiceLineID)<br />
                .Select(objInv =&gt; new StringClass()<br />
                {<br />
                    Actual = objInv.Description,<br />
                    Insert = objInv.Description.Insert(2, &quot;sibeeshpassion&quot;),<br />
                    Remove = objInv.Description.Remove(1, 1),<br />
                    Substring = objInv.Description.Substring(2, 3),<br />
                    ToLower = objInv.Description.ToLower(),<br />
                    ToUpper = objInv.Description.ToUpper(),<br />
                    TrimEnd = objInv.Description.TrimEnd(),<br />
                    TrimStart = objInv.Description.TrimStart()<br />
                }).Take(2);</p>
<p>            return PartialView(&quot;StringQueries&quot;, objString);<br />
        }<br />
[/csharp]</p>
<p>As you can see, here we are using a custom model StringClass.</p>
<p>[csharp]<br />
namespace LINQ_B_to_A.Models<br />
{<br />
    public partial class StringClass<br />
    {<br />
        public string Actual { get; set; }<br />
        public string Insert { get; set; }<br />
        public string Remove { get; set; }<br />
        public string Substring { get; set; }<br />
        public string ToUpper { get; set; }<br />
        public string ToLower { get; set; }<br />
        public string TrimStart { get; set; }<br />
        public string TrimEnd { get; set; }<br />
    }<br />
}<br />
[/csharp]</p>
<p>Let&#8217;s see the view now. </p>
<p>[html]</p>
<p>@model IQueryable&lt;LINQ_B_to_A.Models.StringClass&gt;<br />
&lt;style&gt;<br />
    td, th, thead, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }</p>
<p>    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>&lt;table&gt;<br />
    &lt;caption&gt;String Operators&lt;/caption&gt;<br />
    &lt;tr&gt;</p>
<p>    &lt;/tr&gt;<br />
    @foreach (var @item in Model)<br />
    {<br />
        &lt;tr&gt;<br />
            &lt;td&gt;Actual: @item.Actual&lt;/td&gt;<br />
            &lt;td&gt;Insert: @item.Insert&lt;/td&gt;<br />
            &lt;td&gt;Remove: @item.Remove&lt;/td&gt;<br />
            &lt;td&gt;Substring: @item.Substring&lt;/td&gt;<br />
            &lt;td&gt;ToLower: @item.ToLower&lt;/td&gt;<br />
            &lt;td&gt;ToUpper: @item.ToUpper&lt;/td&gt;<br />
            &lt;td&gt;TrimEnd: @item.TrimEnd&lt;/td&gt;<br />
            &lt;td&gt;TrimStart: @item.TrimStart&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    }<br />
&lt;/table&gt;<br />
&lt;pre&gt;<br />
        public ActionResult StringQueries()<br />
        {<br />
            var objString = (from objInv in DtContext.InvoiceLines<br />
                where objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15<br />
                orderby objInv.InvoiceLineID descending<br />
                select new StringClass()<br />
                {</p>
<p>                    Actual = objInv.Description,<br />
                    Insert = objInv.Description.Insert(2,&quot;sibeeshpassion&quot;),<br />
                    Remove = objInv.Description.Remove(1,1),<br />
                    Substring = objInv.Description.Substring(2,3),<br />
                    ToLower = objInv.Description.ToLower(),<br />
                    ToUpper = objInv.Description.ToUpper(),<br />
                    TrimEnd = objInv.Description.TrimEnd(),<br />
                    TrimStart = objInv.Description.TrimStart()<br />
                }).Take(2);</p>
<p>            //Method Chain Format<br />
            var objString2 = DtContext.InvoiceLines<br />
                .Where(objInv =&gt; objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15)<br />
                .OrderByDescending(o =&gt; o.InvoiceLineID)<br />
                .Select(objInv =&gt; new StringClass()<br />
                {<br />
                    Actual = objInv.Description,<br />
                    Insert = objInv.Description.Insert(2, &quot;sibeeshpassion&quot;),<br />
                    Remove = objInv.Description.Remove(1, 1),<br />
                    Substring = objInv.Description.Substring(2, 3),<br />
                    ToLower = objInv.Description.ToLower(),<br />
                    ToUpper = objInv.Description.ToUpper(),<br />
                    TrimEnd = objInv.Description.TrimEnd(),<br />
                    TrimStart = objInv.Description.TrimStart()<br />
                }).Take(2);</p>
<p>            return PartialView(&quot;StringQueries&quot;, objString);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Now see the result.</p>
<p><div id="attachment_12375" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-String-Queries-e1494745369956.png"><img decoding="async" aria-describedby="caption-attachment-12375" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-String-Queries-e1494745369956.png" alt="LINQ Basic to Advanced String Queries" width="634" height="300" class="size-full wp-image-12375" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-String-Queries-e1494745369956.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-String-Queries-e1494745369956-300x142.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-String-Queries-e1494745369956-400x189.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12375" class="wp-caption-text">LINQ Basic to Advanced String Queries</p></div></p>
<h4>SelectMany Query</h4>
<p>A SelectMany query flattern the result to a single dimentional collection, so to loop through the result we just need only one loop. </p>
<p><div id="attachment_12377" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-Tooltip-e1494746794913.png"><img decoding="async" aria-describedby="caption-attachment-12377" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-Tooltip-e1494746794913.png" alt="LINQ Basic to Advanced SelectMany Tooltip" width="634" height="104" class="size-full wp-image-12377" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-Tooltip-e1494746794913.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-Tooltip-e1494746794913-300x49.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-Tooltip-e1494746794913-400x66.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12377" class="wp-caption-text">LINQ Basic to Advanced SelectMany Tooltip</p></div></p>
<p>If you use the normal Select, you will be getting a list of lists, thus you will have to use two loops to get the datas.</p>
<p><div id="attachment_12378" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Select-Tooltip-e1494746906690.png"><img decoding="async" aria-describedby="caption-attachment-12378" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Select-Tooltip-e1494746906690.png" alt="LINQ Basic to Advanced Select Tooltip" width="634" height="83" class="size-full wp-image-12378" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Select-Tooltip-e1494746906690.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Select-Tooltip-e1494746906690-300x39.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Select-Tooltip-e1494746906690-400x52.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12378" class="wp-caption-text">LINQ Basic to Advanced Select Tooltip</p></div></p>
<p>[csharp]<br />
 /// &lt;summary&gt;<br />
        /// Linq query with SelectMany<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult SelectMany()<br />
        {<br />
            var selectMany = DtContext.Orders.SelectMany(order =&gt; order.Invoices).Take(10);<br />
            var select = DtContext.Orders.Select(order =&gt; order.Invoices).Take(10);<br />
            return PartialView(&quot;SelectMany&quot;, selectMany);<br />
        }<br />
[/csharp]</p>
<p>Let&#8217;s see the view now. </p>
<p>[html]<br />
@model IQueryable&lt;LINQ_B_to_A.Models.Invoice&gt;<br />
&lt;style&gt;<br />
    td, th, thead, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }</p>
<p>    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>&lt;table&gt;<br />
    &lt;caption&gt;Invoice Details&lt;/caption&gt;<br />
    &lt;tr&gt;<br />
        &lt;th&gt;Order ID&lt;/th&gt;<br />
        &lt;th&gt;Invoice ID&lt;/th&gt;<br />
        &lt;th&gt;Invoice Date&lt;/th&gt;<br />
    &lt;/tr&gt;<br />
    @foreach (var @item in Model)<br />
    {<br />
        &lt;tr&gt;<br />
            &lt;td&gt;@item.OrderID&lt;/td&gt;<br />
            &lt;td&gt;@item.InvoiceID&lt;/td&gt;<br />
            &lt;td&gt;@item.InvoiceDate&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    }<br />
&lt;/table&gt;<br />
&lt;caption&gt;Select Many&lt;/caption&gt;<br />
&lt;pre&gt;<br />
     /// &lt;summary&gt;<br />
        /// Linq query with SelectMany<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult SelectMany()<br />
        {<br />
            var selectMany = DtContext.Orders.SelectMany(order =&gt; order.Invoices).Take(10);<br />
            var select = DtContext.Orders.Select(order =&gt; order.Invoices).Take(10);<br />
            return PartialView(&quot;SelectMany&quot;, selectMany);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Now see the result.</p>
<p>That&#8217;s all for today, I will come with another set of LINQ queries in the next part. Till then, bye.</p>
<p><div id="attachment_12379" style="width: 952px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-e1494747140197.png"><img decoding="async" aria-describedby="caption-attachment-12379" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-e1494747140197.png" alt="LINQ Basic to Advanced SelectMany" width="942" height="597" class="size-full wp-image-12379" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-e1494747140197.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-e1494747140197-300x190.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-e1494747140197-400x254.png 400w" sizes="(max-width: 942px) 100vw, 942px" /></a><p id="caption-attachment-12379" class="wp-caption-text">LINQ Basic to Advanced SelectMany</p></div></p>
<h3>Conclusion</h3>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h3>Your turn. What do you think?</h3>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/linq-basic-to-advanced-mvc-demo-application/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Installing Asp.Net Core Docker For Windows</title>
		<link>https://www.sibeeshpassion.com/installing-asp-net-core-docker-for-windows/</link>
					<comments>https://www.sibeeshpassion.com/installing-asp-net-core-docker-for-windows/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sun, 07 May 2017 11:01:29 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Asp.Net Core]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Asp.Net Core Docker]]></category>
		<category><![CDATA[Docker In Windows]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=12284</guid>

					<description><![CDATA[[toc] Introduction Here, in this post we are going to a see how we can install Asp.Net Core Docker in our Windows. Before we start, it would be useful if we say something about the Docker right? Docker is a container software platform where container is everything we need to make our software run. The container is light in weight. You can read more about the Docker here. I hope you will like this. Now let&#8217;s begin. Background Today, I was just trying to create a Asp.Net Docker application in Visual Studio 2017. Unfortunately I was getting an error as preceding. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h3>Introduction</h3>
<p>Here, in this post we are going to a see how we can install Asp.Net Core Docker in our <a href="http://sibeeshpassion.com/category/Windows-10/" target="_blank" rel="noopener noreferrer">Windows</a>. Before we start, it would be useful if we say something about the Docker right? Docker is a container software platform where container is everything we need to make our software run. The container is light in weight. You can read more about the Docker <a href="https://www.docker.com/what-docker">here</a>. I hope you will like this. Now let&#8217;s begin.</p>
<h3>Background</h3>
<p>Today, I was just trying to create a Asp.Net Docker application in <a href="http://sibeeshpassion.com/category/Visual-Studio-2017/">Visual Studio 2017</a>. Unfortunately I was getting an error as preceding.</p>
<blockquote><p>Error MSB4018 The &#8220;PrepareForBuild&#8221; task failed unexpectedly.<br />
Microsoft.DotNet.Docker.CommandLineClientException: Unable to run &#8216;docker-compose&#8217;. Verify that Docker for Windows is installed and running locally. For troubleshooting, please review http://aka.ms/DockerToolsTroubleshooting. &#8212;&gt; System.ComponentModel.Win32Exception: The system cannot find the file specified</p></blockquote>
<p>Then I came to know that I have not installed Docker in my machine yet, so I decided to do that.</p>
<p><div id="attachment_12307" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/Asp-Net-Core-Docker-Error.png"><img decoding="async" aria-describedby="caption-attachment-12307" class="wp-image-12307" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/Asp-Net-Core-Docker-Error-1024x581.png" alt="Asp Net Core Docker Error" width="634" height="360" srcset="/wp-content/uploads/2017/05/Asp-Net-Core-Docker-Error-1024x581.png 1024w, /wp-content/uploads/2017/05/Asp-Net-Core-Docker-Error-300x170.png 300w, /wp-content/uploads/2017/05/Asp-Net-Core-Docker-Error-768x436.png 768w, /wp-content/uploads/2017/05/Asp-Net-Core-Docker-Error-400x227.png 400w, /wp-content/uploads/2017/05/Asp-Net-Core-Docker-Error-1057x600.png 1057w, /wp-content/uploads/2017/05/Asp-Net-Core-Docker-Error.png 1379w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12307" class="wp-caption-text">Asp Net Core Docker Error</p></div></p>
<h3>Installing Docker For Windows</h3>
<p>You can install the Docker from <a href="https://docs.docker.com/docker-for-windows/install/#download-docker-for-windows">here</a>. Once you downloaded the set up file, please run the file.</p>
<p><div id="attachment_12308" style="width: 628px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-For-Windows.png"><img decoding="async" aria-describedby="caption-attachment-12308" class="size-full wp-image-12308" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-For-Windows.png" alt="Docker For Windows" width="618" height="483" srcset="/wp-content/uploads/2017/05/Docker-For-Windows.png 618w, /wp-content/uploads/2017/05/Docker-For-Windows-300x234.png 300w, /wp-content/uploads/2017/05/Docker-For-Windows-400x313.png 400w" sizes="(max-width: 618px) 100vw, 618px" /></a><p id="caption-attachment-12308" class="wp-caption-text">Docker For Windows</p></div></p>
<h3>Start and test the Docker</h3>
<p>Once you installed the Docker, now it is time to test whether everything is installed correctly or not. Before that make sure that the Docker is starting.</p>
<p><div id="attachment_12309" style="width: 281px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-is-Starting.png"><img decoding="async" aria-describedby="caption-attachment-12309" class="size-full wp-image-12309" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-is-Starting.png" alt="Docker is Starting" width="271" height="152" /></a><p id="caption-attachment-12309" class="wp-caption-text">Docker is Starting</p></div></p>
<p>There is a hight possibility that to get an error &#8220;Hardware assisted virtulization and data execution protection must be enabled in the BIOS&#8221; as preceding image.</p>
<p><div id="attachment_12310" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-Error.png"><img decoding="async" aria-describedby="caption-attachment-12310" class="wp-image-12310" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-Error.png" alt="Docker Error" width="634" height="233" srcset="/wp-content/uploads/2017/05/Docker-Error.png 863w, /wp-content/uploads/2017/05/Docker-Error-300x110.png 300w, /wp-content/uploads/2017/05/Docker-Error-768x282.png 768w, /wp-content/uploads/2017/05/Docker-Error-400x147.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12310" class="wp-caption-text">Docker Error</p></div></p>
<p>Before you go and change the settings in BIOS, check in Task Manager window as well.</p>
<p><div id="attachment_12311" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/Hyper-V-support-and-Virtulization.png"><img decoding="async" aria-describedby="caption-attachment-12311" class="wp-image-12311" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/Hyper-V-support-and-Virtulization.png" alt="Hyper V support and Virtulization" width="634" height="564" srcset="/wp-content/uploads/2017/05/Hyper-V-support-and-Virtulization.png 834w, /wp-content/uploads/2017/05/Hyper-V-support-and-Virtulization-300x267.png 300w, /wp-content/uploads/2017/05/Hyper-V-support-and-Virtulization-768x683.png 768w, /wp-content/uploads/2017/05/Hyper-V-support-and-Virtulization-400x356.png 400w, /wp-content/uploads/2017/05/Hyper-V-support-and-Virtulization-674x600.png 674w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12311" class="wp-caption-text">Hyper V support and Virtulization</p></div></p>
<h3>Enabling Virtulization in BIOS</h3>
<p>To Enable the Virtulization in BIOS, go to System Configuration -&gt; Click on Virtulization Technology and Enable it.</p>
<p><div id="attachment_12313" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/BIOS-Settings.jpeg"><img decoding="async" aria-describedby="caption-attachment-12313" class="wp-image-12313" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/BIOS-Settings-1024x574.jpeg" alt="BIOS Settings" width="634" height="355" srcset="/wp-content/uploads/2017/05/BIOS-Settings-1024x574.jpeg 1024w, /wp-content/uploads/2017/05/BIOS-Settings-300x168.jpeg 300w, /wp-content/uploads/2017/05/BIOS-Settings-768x430.jpeg 768w, /wp-content/uploads/2017/05/BIOS-Settings-400x224.jpeg 400w, /wp-content/uploads/2017/05/BIOS-Settings-1071x600.jpeg 1071w, /wp-content/uploads/2017/05/BIOS-Settings.jpeg 634w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12313" class="wp-caption-text">BIOS Settings</p></div></p>
<p>After the restart, the Docker will ask you to start the service. Go ahead and do that.</p>
<h3>Setting up Docker</h3>
<p><div id="attachment_12314" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-Service-Is-Not-Runnig-Window.png"><img decoding="async" aria-describedby="caption-attachment-12314" class="wp-image-12314" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-Service-Is-Not-Runnig-Window.png" alt="Docker Service Is Not Runnig Window" width="634" height="233" srcset="/wp-content/uploads/2017/05/Docker-Service-Is-Not-Runnig-Window.png 863w, /wp-content/uploads/2017/05/Docker-Service-Is-Not-Runnig-Window-300x110.png 300w, /wp-content/uploads/2017/05/Docker-Service-Is-Not-Runnig-Window-768x282.png 768w, /wp-content/uploads/2017/05/Docker-Service-Is-Not-Runnig-Window-400x147.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12314" class="wp-caption-text">Docker Service Is Not Runnig Window</p></div></p>
<p>Now again, if you are getting an error as &#8220;Error MSB4018 The &#8220;PrepareForLaunch&#8221; task failed unexpectedly.<br />
Microsoft.DotNet.Docker.CommandLineClientException: Creating network &#8220;dockercompose3875147227_default&#8221; with the default driver<br />
Building linq_basic_to_advanced Service  &#8216;linq_basic_to_advanced&#8217; failed to build: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).&#8221;, you need to change your shared drive settings in Docker.</p>
<p>Right click and click on the settings.</p>
<p><div id="attachment_12315" style="width: 397px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-Settings.png"><img decoding="async" aria-describedby="caption-attachment-12315" class="size-full wp-image-12315" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-Settings.png" alt="Docker Settings" width="387" height="291" srcset="/wp-content/uploads/2017/05/Docker-Settings.png 387w, /wp-content/uploads/2017/05/Docker-Settings-300x226.png 300w" sizes="(max-width: 387px) 100vw, 387px" /></a><p id="caption-attachment-12315" class="wp-caption-text">Docker Settings</p></div></p>
<p>Click on the Shared Drives and  select the drive that hosts your project and the drive where %USERPROFILE% resides.</p>
<p><div id="attachment_12316" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/Shared-Drive-in-Docker.png"><img decoding="async" aria-describedby="caption-attachment-12316" class="wp-image-12316" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/Shared-Drive-in-Docker-1024x666.png" alt="Shared Drive in Docker" width="634" height="413" srcset="/wp-content/uploads/2017/05/Shared-Drive-in-Docker-1024x666.png 1024w, /wp-content/uploads/2017/05/Shared-Drive-in-Docker-300x195.png 300w, /wp-content/uploads/2017/05/Shared-Drive-in-Docker-768x500.png 768w, /wp-content/uploads/2017/05/Shared-Drive-in-Docker-400x260.png 400w, /wp-content/uploads/2017/05/Shared-Drive-in-Docker-922x600.png 922w, /wp-content/uploads/2017/05/Shared-Drive-in-Docker.png 549w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12316" class="wp-caption-text">Shared Drive in Docker</p></div></p>
<p>Click on Apply and type your filesystem passwor in the following pop up. Now if you are running the Edge version of Docker Community Edition for Windows, after the install you may be able to login with your Docker ID and password.</p>
<p><div id="attachment_12320" style="width: 619px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-SignIn-page.png"><img decoding="async" aria-describedby="caption-attachment-12320" class="size-full wp-image-12320" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-SignIn-page.png" alt="Docker SignIn page" width="609" height="367" srcset="/wp-content/uploads/2017/05/Docker-SignIn-page.png 609w, /wp-content/uploads/2017/05/Docker-SignIn-page-300x181.png 300w, /wp-content/uploads/2017/05/Docker-SignIn-page-400x241.png 400w" sizes="(max-width: 609px) 100vw, 609px" /></a><p id="caption-attachment-12320" class="wp-caption-text">Docker SignIn page</p></div></p>
<p>We have enough settings for now, shall we just check whether the installation is done perfectly or not? To check, go to the command window and type the command as  docker run hello-world.</p>
<p><div id="attachment_12322" style="width: 593px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-Check-From-Command-Window.png"><img decoding="async" aria-describedby="caption-attachment-12322" class="size-full wp-image-12322" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/Docker-Check-From-Command-Window.png" alt="Docker Check From Command Window" width="583" height="414" srcset="/wp-content/uploads/2017/05/Docker-Check-From-Command-Window.png 583w, /wp-content/uploads/2017/05/Docker-Check-From-Command-Window-300x213.png 300w, /wp-content/uploads/2017/05/Docker-Check-From-Command-Window-400x284.png 400w" sizes="(max-width: 583px) 100vw, 583px" /></a><p id="caption-attachment-12322" class="wp-caption-text">Docker Check From Command Window</p></div></p>
<p>You can also check the Docker version with the command docker &#8211;version</p>
<h3>Conclusion</h3>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h3>Your turn. What do you think?</h3>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/installing-asp-net-core-docker-for-windows/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Webinar: Why Visual Studio 2017? Few Features of VS2017 You May Love</title>
		<link>https://www.sibeeshpassion.com/webinar-why-visual-studio-2017-few-features-of-vs2017-you-may-love/</link>
					<comments>https://www.sibeeshpassion.com/webinar-why-visual-studio-2017-few-features-of-vs2017-you-may-love/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 10 Apr 2017 09:29:29 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2017]]></category>
		<category><![CDATA[Webinars]]></category>
		<category><![CDATA[Features of VS2017]]></category>
		<category><![CDATA[VS2017]]></category>
		<category><![CDATA[VS2017 IDE features]]></category>
		<category><![CDATA[Webinar]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=12175</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/webinar-why-visual-studio-2017-few-features-of-vs2017-you-may-love/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
