{"id":36915,"date":"2018-02-08T16:01:48","date_gmt":"2018-02-09T00:01:48","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/?p=11695"},"modified":"2018-02-08T16:01:48","modified_gmt":"2018-02-09T00:01:48","slug":"two-lesser-known-tools-for-local-azure-development","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/two-lesser-known-tools-for-local-azure-development\/","title":{"rendered":"Two Lesser Known Tools for Local Azure Development"},"content":{"rendered":"<p>If you\u2019re developing applications that target Azure services (e.g. Web Apps, Functions, Storage), you\u2019ll want to know about two powerful tools that come with Visual Studio 2017 and the Azure development workload: * <strong>Cloud Explorer<\/strong> is a tool window inside Visual Studio that lets you browse your Azure resources and perform specific tasks \u2013 like stop and start app service, view streaming logs, create storage items. * <strong>Storage Emulator<\/strong> is a separate application to Visual Studio that provides a local simulation of the Azure storage services. It\u2019s really handy for testing Functions that trigger from queues, blobs or tables. In this blog I\u2019ll show you how you can develop Azure applications entirely locally \u2013 including the ability to interact with Azure storage \u2013 without ever needing an Azure subscription.<\/p>\n<h3>Prerequisites<\/h3>\n<ul>\n<li>If you want to follow along, you\u2019ll need <a href=\"https:\/\/www.visualstudio.com\/downloads\/\" rel=\"noopener\" target=\"_blank\">Visual Studio 2017<\/a> with <a href=\"https:\/\/www.visualstudio.com\/vs\/support\/selecting-workloads-visual-studio-2017\/\" rel=\"noopener\" target=\"_blank\">Azure development workload<\/a> installed.<\/li>\n<li>For the purposes of this blog, we&#8217;ve developed a <a href=\"https:\/\/github.com\/justcla\/ListBlobFiles\">simple one-page web app<\/a>. Note: You will NOT need an Azure subscription to follow this blog. In fact, that&#8217;s the whole point of this blog. \ud83d\ude09 <\/li>\n<\/ul>\n<h3>Cloud Explorer<\/h3>\n<p>The Cloud Explorer is your window into Azure from within Visual Studio. You can browse the common resources in your Azure subscriptions in one convenient tool window. Each of the various Azure services have different properties and actions.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/CloudExplorerExpanded-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/CloudExplorerExpanded-1-1.png\" alt=\"Cloud Explorer - Expanded\" width=\"450\" class=\"alignnone size-full wp-image-11725\" \/><\/a><\/p>\n<p>In the picture above, you can see it has listed a variety of resources from my Azure subscription including my App Services, SQL Databases and Virtual Machines, as well as my App Service Plans, Storage Accounts and other network infrastructure assets. I have published the sample app to an App Service called <strong>ListBlobFilesSample<\/strong>. You can see it listed under the App Services node.<\/p>\n<p>Each resource has a collection of properties and actions. You can trigger actions by right-clicking on the item of interest. For instance, I can <strong>View Streaming Logs<\/strong> to see a running output of my application in the cloud, or I can <strong>Attach Debugger<\/strong> to step through the code to diagnose errors. (Note: For more information about diagnosing errors, see <a href=\"https:\/\/blogs.msdn.microsoft.com\/webdev\/2018\/02\/07\/diagnosing-errors-on-your-cloud-apps\/\">Diagnosing Errors on your Cloud Apps<\/a>.)<\/p>\n<p>In this blog, we\u2019ll be using Cloud Explorer to interact with our Storage Accounts \u2013 specifically, with the local (Development) storage account using the Microsoft Azure Storage Emulator.<\/p>\n<h3>Sample Code<\/h3>\n<p>For this post, we\u2019ll be working with a sample Web App with a single Razor Page file that displays a list of items in a Blob storage container (i.e. list of files in a folder in a storage account). Clone the source from<\/p>\n<p><a href=\"https:\/\/github.com\/justcla\/ListBlobFiles\">here<\/a> and open the ListBlobFiles solution in Visual Studio. The web app consists of: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211; a single Razor Page file (Index.cshtml), \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211; its code behind file (Index.cshtml.cs), \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211; a utility class for reading items from storage (StorageHelper.cs), \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211; the application\u2019s settings file (appsettings.json), \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211; standard web app startup files (Program.cs and Startup.cs)<\/p>\n<p>Here\u2019s a snippet of the most interesting part \u2013 the helper class that returns a list of files stored in a blob storage container. <\/p>\n<h3>Using Storage Completely Offline with Storage Emulator<\/h3>\n<p>Using the Storage Emulator, you can develop, run, debug and test your applications that use Azure Storage locally without an Azure subscription. The other great thing is, the Storage Emulator is part of the Azure development workload in Visual Studio, so there is no extra installation required.<\/p>\n<p><strong>Start the Storage Emulator<\/strong> * Press the Windows key and type \u201cStorage Emulator\u201d, then select <strong>Microsoft Azure Storage Emulator<\/strong>. When the Storage Emulator is running, an icon will appear in the Windows system tray. <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/StorageEmulatorIcon-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/StorageEmulatorIcon-1-1.png\" alt=\"Storage Emulator icon in task bar\" width=\"200\" class=\"alignnone size-full wp-image-11745\" \/><\/a><\/p>\n<p><strong>Launch the web app from Visual Studio<\/strong> * Press <strong>Ctrl+F5<\/strong> to build and run the web app locally. A web browser will launch an open the Index page of the app. The page renders and shows there are no files in the Blob container. <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/WebPageDisplaysError.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/WebPageDisplaysError-2.png\" alt=\"Web page displays errors\" width=\"450\" class=\"alignnone size-full wp-image-11755\" \/><\/a><br \/>\nLet\u2019s add some files to a local storage container and see if they show up when we refresh the page.<\/p>\n<p><strong>Create local Blob Storage (using Storage Emulator and Cloud Explorer)<\/strong> * Open Cloud Explorer * Expand to <strong>Blob Containers<\/strong> under (Local)-&gt;Storage Accounts-&gt;(Development) * Click <strong>Create Blob Container<\/strong> in the Actions panel <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/CloudExplorerCreateBlobContainer.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/CloudExplorerCreateBlobContainer-2.png\" alt=\"Cloud Explorer - Create Blob Container\" width=\"319\" class=\"alignnone size-full wp-image-11765\" \/><\/a> * Enter a name for the local blob storage container (ie. &#8220;myfiles&#8221;) &#8211; Note: must contain only lowercase\/numbers\/hyphens<\/p>\n<p><strong>Add files to your Blob container<\/strong> * Right-click the new container (myfiles) and select Open. * In the toolbar, click the Upload button. * Browse for a file, then press OK. * Do this repeatedly to add several files to your blob container (storage folder).<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/AddFilesToBlobContainer.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/AddFilesToBlobContainer-2.png\" alt=\"Cloud Explorer - Add files to blob container\" width=\"750\" class=\"alignnone size-full wp-image-11775\" \/><\/a><\/p>\n<p>You&#8217;ll see the files appear in the container window, along with the URL for each item. The Microsoft Azure Activity Log window shows the status of the uploads. <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/FilesAddedToBlobContainer.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/FilesAddedToBlobContainer-1.png\" alt=\"Files appear in container view\" width=\"700\" class=\"alignnone size-full wp-image-11785\" \/><\/a><\/p>\n<p>Return to the web browser that is running our local web app and refresh the page. Notice that the page now outputs the URLs of all the files in the container. <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/WebPageDisplaysFilenames.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/WebPageDisplaysFilenames-2.png\" alt=\"Web page renders correctly, showing files in blob container\" width=\"450\" class=\"alignnone size-full wp-image-11786\" \/><\/a><\/p>\n<p>Success! You&#8217;re now doing local development of an app that uses Azure storage &#8211; without needing any resources on Azure.<\/p>\n<h3>Next Steps<\/h3>\n<p>Try it on the cloud! When you&#8217;re ready, publish your app to Azure App Services and configure it to run with Azure Storage on the cloud. You can continue to use Cloud Explorer within Visual Studio to interact with your storage account on Azure in just the same way you did with local development.<\/p>\n<h3>Related Links<\/h3>\n<ul>\n<li>Get started with Azure Blob storage using .NET <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/blobs\/storage-dotnet-how-to-use-blobs\">https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/blobs\/storage-dotnet-how-to-use-blobs<\/a><\/li>\n<li>Use the Azure Storage Emulator for development and testing <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/common\/storage-use-emulator\">https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/common\/storage-use-emulator<\/a><\/li>\n<li>Introduction to Razor Pages in ASP.NET Core <a href=\"https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/mvc\/razor-pages\/?tabs=visual-studio\">https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/mvc\/razor-pages\/?tabs=visual-studio<\/a><\/li>\n<li>ASP.NET Core &#8211; Simpler ASP.NET MVC Apps with Razor Pages <a href=\"https:\/\/msdn.microsoft.com\/en-us\/magazine\/mt842512.aspx\">https:\/\/msdn.microsoft.com\/en-us\/magazine\/mt842512.aspx<\/a> <\/li>\n<li>Azure\nArticle : Azure Blob Storage Photo Gallery Web Application <a href=\"https:\/\/azure.microsoft.com\/en-us\/resources\/samples\/storage-blobs-dotnet-webapp\/\">https:\/\/azure.microsoft.com\/en-us\/resources\/samples\/storage-blobs-dotnet-webapp\/<\/a><\/li>\n<li>Related sample on GitHub: Image Resizer Web App <a href=\"https:\/\/github.com\/Azure-Samples\/storage-blob-upload-from-webapp\">https:\/\/github.com\/Azure-Samples\/storage-blob-upload-from-webapp<\/a><\/li>\n<li>Upload image data in the cloud with Azure Storage <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/blobs\/storage-upload-process-images\">https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/blobs\/storage-upload-process-images<\/a><\/li>\n<li>Azure Blob Storage Samples for .NET <a href=\"https:\/\/github.com\/Azure-Samples\/storage-blob-dotnet-getting-started\">https:\/\/github.com\/Azure-Samples\/storage-blob-dotnet-getting-started<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>If you\u2019re developing applications that target Azure services (e.g. Web Apps, Functions, Storage), you\u2019ll want to know about two powerful tools that come with Visual Studio 2017 and the Azure development workload: * Cloud Explorer is a tool window inside Visual Studio that lets you browse your Azure resources and perform specific tasks \u2013 like [&hellip;]<\/p>\n","protected":false},"author":467,"featured_media":21414,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197,327],"tags":[7541],"class_list":["post-36915","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","category-azure","tag-azure-development"],"acf":[],"blog_post_summary":"<p>If you\u2019re developing applications that target Azure services (e.g. Web Apps, Functions, Storage), you\u2019ll want to know about two powerful tools that come with Visual Studio 2017 and the Azure development workload: * Cloud Explorer is a tool window inside Visual Studio that lets you browse your Azure resources and perform specific tasks \u2013 like [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/36915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/467"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=36915"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/36915\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/21414"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=36915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=36915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=36915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}