Feb
27
2015

Context Aware Access to Command Prompt or PowerShell in Windows

I have been ramping up on ASP.NET 5 which has had me in PowerShell or the command prompt quite a bit (this is to support upcoming x-plat features).  In many cases, I have needed to run commands in the context of a folder.  Here is an easy way to do this in Windows Explorer…  

From the Windows File menu

Suppose I am in a folder and I want to immediately go to the command prompt or PowerShell and already be in the context of that directory?  I simply go to the File menu option in Windows Explorer ([Alt] F keyboard shortcut) and select either the command prompt or PowerShell as seen below:

File menu in windows explorer
Letters appear when [Alt] key is used

If I choose the command prompt, it will put me in the same directory as the current open window as seen here:

path in windows and command prompt

    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Feb
19
2015

Creating an ASP.NET 5 Starter Application

This blog post is part of a series covering ASP.NET 5  To follow along, this post requires installing Visual Studio 2015 CTP.

This post will cover:

  • Creating the project
  • Examining the project
  • Comparing to "Empty project"

The goal of these topics is not only to show “how-to”, but to answer the “what is that…” and “why is that” as well.  It is written as if you are following along in Visual Studio 2015 (tutorial style), yet with enough supplemental detail to simply read (article style). Although not an exhaustive dive into each area, it should provide enough context to quickly get started with ASP.NET 5.

Creating the project

To create a new ASP.NET 5 application, it is necessary to think in terms of projects, not web sites.  The Web Site… option as seen below is still supported in Visual Studio 2015 to support legacy site development.  The specific “ASP.NET vNext” features require the Project… option. With this in mind, in Visual Studio 2015 select from the top menu bar: File --> New --> Project...

visual studio 2015 new project

After selecting Project…, a new project dialogue box appears.  On the left side of the box, select the Web option under the language of preference (Visual C# used below).  From there, select ASP.NET Web Application and choose the solution/project name and file location.  This post will use ASPNET5 as the solution name, and StarterSite as the project name.

asp.net web application project
ASP.NET 5 Class Library and Console Application project templates will be covered in an upcoming blog post

Another dialogue box will appear to fine tune the type of web project desired. In this post, we will look at the ASP.NET 5 Starter Web template.

image

 

Examining the project

The following is the default structure for the ASP.NET 5 Starter Web project:

image

A closer look at the wwwroot folder reveals helpful static (non-compiling) content:

image

The bin folder contains the AspNet.Loader.dll file, which is needed in deployment to IIS.

The css folder contains the site.css file, with minimal style declarations.

The lib folder contains multiple references for support of Bootstrap and jQuery, and contains the _references.js file, which is used to support IntelliSense in Visual Studio.

Back at the project level items, folders such as Controllers, Models, and Views contain what is needed to support MVC.

The Migrations folder contains code to support Entity Framework database migrations.

For an understanding of gruntfile.js and bower.json, take a look at this post by Mike Wasson.

 

Comparing to “Empty project”

In a previous post discussing how to create an ASP.NET 5 site with the “empty” template, there was significantly less folders and files.  This does however help us to appreciate what is truly required for ASP.NET 5 to run.  The folder and files below represent the true minimum:

wwwroot Folder of static files served to client. No code or ‘razor’ goes here
project.json File for managing project settings
Startup.cs File for startup and configuration code

The wwwroot folder in the “empty project” only contains the bin with the AspNet.Loader.dll file – much less than what was shown earlier in this post.

The content of the project.json file and the Startup.cs file also differ from the ‘empty’ with more code to support features commonly used.  The point here is that much has been added to the ‘starter’ template to provide a basis for common tasks associated with web site development.

Summary

In conclusion, there is a solid basis for quick web development when using the ASP.NET 5 Starter Web project template.

    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Feb
11
2015

WebCamp 2015

imageLearn how to develop beautiful, fast and interactive websites! Join us for a FREE WebCamp in your local area to get hands-on with the new release of ASP.NET and Web Tools for Visual Studio 2013. We’ll discuss the Microsoft tools and resources that can help you build cutting-edge websites, and then show you how to deploy them with Microsoft Azure. WebCamps are no-fluff, hands-on learning events for developers, by developers. Don’t miss this exciting chance to sharpen your coding skills and create something amazing. Register now for a Web Camp near you. http://aka.ms/msftwebcamps

For the Web Camps that I am presenting at, here are some resources I would like to share:

    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Jan
30
2015

Install Visual Studio 2015 CTP

This blog post is part of a series covering ASP.NET 5

The following is a step-by-step guide to installing Visual Studio 2015 (currently in CTP).  The process for installing has been simplified compared to the preview edition.

  1. Download Visual Studio 2015
  2. Execute the file when the download is complete.  You will be prompted with the following screen capture.  You can keep the default options selected and click Install.
    Features not installed by default are C++ Cross Platform Mobile, Apache Cordova, and support for Windows 8.1 and Windows Phone 8.1 development. If you want any of these, choose the Custom option instead of Typical and select desired features.
    image_thumb2
    The application will start to acquire files and perform the install.
    This process may take awhile.
    image_thumb5
  3. When the previous step completes, you will be prompted to restart:
    image
  4. After restarting your PC, the setup continues and then prompts to launch:
    image

  5. Once launched, you will need to sign in with your Microsoft account:image

Visual Studio 2015 CTP is now installed and ready!

    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Jan
8
2015

Creating an ASP.NET 5 Empty Application

This blog post is part of a series covering ASP.NET 5  To follow along, this post requires installing Visual Studio 2015 CTP.

To accelerate the learning process for ASP.NET 5 (aka ASP.NET vNext), this post will cover:

  • Creating the project
  • Examining the project
  • Modifying the project
  • Running the project

The goal of these topics is not only to show “how-to”, but to answer the “what is that…” and “why is that” as well.  It is written as if you are following along in Visual Studio 2015 (tutorial style), yet with enough supplemental detail to simply read (article style). Although not an exhaustive dive into each area, it should provide enough context to quickly get started with ASP.NET 5.

Creating the project

To create a new ASP.NET 5 application, it is necessary to think in terms of projects, not web sites.  The Web Site… option as seen below is still supported in Visual Studio 2015 to support legacy site development.  The specific “ASP.NET vNext” features require the Project… option. With this in mind, in Visual Studio 2015 select from the top menu bar: File --> New --> Project...

visual studio 2015 new project

After selecting Project…, a new project dialogue box appears.  On the left side of the box, select the Web option under the language of preference (Visual C# used below).  From there, select ASP.NET Web Application and choose the solution/project name and file location.  This post will use ASPNET5 as the solution name, and ASPNET5Blank as the project name.

asp.net web application project
ASP.NET 5 Class Library and Console Application project templates will be covered in an upcoming blog post

Another dialogue box will appear to fine tune the type of web project desired.  Choose the ASP.NET 5 Empty template as seen below.  Although you may see other options, notice each is disabled.

asp.net 5 empty project template

Examining the project

Once the project has loaded in Visual Studio, Solution Explorer will reveal the following:

asp.net 5 empty web site in solution explorer

The project corresponds to the following file/folder structure:
folder structure of asp.net 5 empty web site

The following is a brief explanation of the projects file/folder contents:

Project_Readme.html HTML help file (not required to be in project, can be discarded)
*.kproj File for managing ASP.NET 5 projects in Visual Studio
*.kproj.user File for managing project user options in Visual Studio
debugSettings.json File used by Visual Studio for debug setting
   
wwwroot Folder of static files served to client. No code or ‘razor’ goes here
project.json File for managing project settings
Startup.cs File for startup and configuration code

The first four items above are there for the benefit of the developer using Visual Studio.  The latter three are needed for development.

Let’s take a look at the initial contents of the project.json file:

{
    "webroot": "wwwroot",
    "version": "1.0.0-*",
    "exclude": [
        "wwwroot"
    ],
    "packExclude": [
        "node_modules",
        "bower_components",
        "**.kproj",
        "**.user",
        "**.vspscc"
    ],
    "dependencies": {
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta2"
    },
    "frameworks" : {
        "aspnet50" : { },
        "aspnetcore50" : { }
    }
}

As can be seen above, the file contains name/value pairs (see schema at GitHub).  This new approach to managing web configurations (notice no web.config) enables simplified dependency management.  Instead of adding assembly references, you now add NuGet packages as dependencies.  How is this better?  Instead of hard-coupling a reference to an assembly, you can now simply add the dependency by just typing it into the file above.

The contents of the Startup.cs file are as follows:

using System;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;

namespace EmptySite
{
    public class Startup
    {
        public void Configure(IApplicationBuilder app)
        {
            // In empty template, no code is here...
        }
    }
}

The Configure method of the Startup class is automatically called at runtime. The IApplicationBuilder instance (with parameter name app highlighted above) provides methods to configure the app and to access the HTTP request.  An example of the UseWelcomePage method is used in the article Create a Web API in MVC 6.  However, when I attempt to access this method in my project, I do not see it:

use method

The only methods displayed are just named Use. In the next topic, the project will be modified to enable the use of other methods off of the IApplicationBuilder instance passed in. 

Modifying the Project

In Visual Studio, open the project.json file. We are going to add a dependency to the Microsoft.AspNet.Diagnostics package which is needed to get access to the UseWelcomePage method. Under dependencies, the name of the package is provided paired with the version.  It must be typed accurately.  However, when doing so in Visual Studio, we get discovery and auto-completion via IntelliSense!

adding dependency to project.json file

In the above screen capture, I started adding the Microsoft.AspNet.Diagnostics package.  When ready to add the corresponding value for version, IntelliSense came to the rescue again!

intellisense support for project.json file

After saving the project.json file, the output window in Visual Studio reveals what happened:

output of dependencies added

The Microsoft.AspNet.Diagnostics package was installed along with its dependencies.  Did this modify the project.json file to show the two new packages?  No.  And that is good news.  Why?  There is no need to clutter the file with hierarchies of dependencies.  When a new package is referenced, the dependencies (and their dependencies) are automatically added.  When removed, all dependencies are removed too!

Returning to the Startup.cs file, when I now attempt to access the UseWelcomePage method, it exists!

usewelcomepage method

The Configure method is now updated to look as follows:

public void Configure(IApplicationBuilder app)
{
    app.UseWelcomePage();
}

What will this do?  Let’s find out!

Running the Project

By default, the project will be deployed to IIS Express for testing.  The classic Debug menu options still work here:

debug options in visual studio

When selecting either Start Debugging [F5] or Start Without Debugging [Ctrl+F5], the app will run showing the welcome screen as seen here:

usewelcomepage screen

Summary

This post examined the very essentials of an ASP.NET 5 application. In addition to learning how to create, modify, and run an app, we poked around with the initial files and learned how cool dependencies are managed in the project.json file. 

Be sure to check the series covering ASP.NET 5 for new and updated topics!

    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Jan
3
2015

Install Visual Studio 2015

This blog post is part of a series covering ASP.NET 5

The following is a step-by-step guide to installing Visual Studio 2015 (currently in Preview).

  1. Download Visual Studio 2015 Preview
  2. Execute the file when the download is complete.  You will be prompted with a screen similar to what is shown next:image
  3. Select the options relevant to your development needs.  Although all options are checked in the screen capture below, the highlighted items below are essential for web development:image
  4. After clicking the Install button, the application will start to acquire files and perform the install:
    image
  5. If you previously selected Visual C++ Cross Platform Mobile Development or Tools for Apache Cordova, you will see the following:
    image
    This enables features as seen below:
    image
    After clicking Install, you will see a secondary installer to enable the desirable third-party features:
    image
    The secondary installer will confirm selected features:
    image
    The installation will continue with acquiring needed files and applying:
    image
  6. Once Visual Studio 2015 is installed, you will need to sign in with your Microsoft account:image

Visual Studio 2015 is now installed and ready!

    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Jan
2
2015

ASP.NET 5

aspnetA hand-picked collection of posts, articles, videos, and resources related to ASP.NET 5. All posts featured on Palermo4.com will be "living content" - that is it will be updated to be in sync with current releases. If you happen to know of any resource that should be here, please leave a comment below!

Overview, Concepts, & Resources

ASP.NET 5 on Palermo4.com

Videos

scott hunter asp.net 5
Scott Hunter on ASP.NET 5
mva asp.net 5 scott hanselman scott hunter
MVA ASP.NET 5
asp.net 5 community standup
Community Standup
    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Oct
27
2014

Sharing a TouchDevelop App

Making an app has never been easier.  Just visit TouchDevelop and try yourself!  After creating an app, you will likely want to get feedback and share it with others.  Although the publishing process offers a way to share the app, here is what to do if you want to share it later.

1) Sign in to TouchDevelop

2) Locate the app you created under “my scripts” and select it

image

3) Select the “share” option

image

4) Use the URL provided however you wish Smile

image

    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Oct
12
2014

Universal Windows Apps with Angular

Starting with Visual Studio 2013 (with update 2), developers can create an app with a single solution to target multiple devices such as PCs, tablets, or phones.  This type of solution can generate universal Windows apps.  These can be written with C#, C++, or JavaScript. For video training on the topic, please check out the free course at the Microsoft Virtual Academy.

If written with JavaScript, web developers who use Angular will be happy to know you can continue to do so while making apps.

For a jumpstart on the development process, I have created a starter solution with a bare-bones shell that properly sets up Angular for use in the project.  The starter solution is named AngularVS (Angular for Visual Studio) and is available publicly at github.

A key factor for Angular to work properly in these types of apps is the use of the the ng-csp directive as seen below.  Not only will this enable Angular to work smoothly, if declared before other popular libraries|frameworks such as jQuery, it helps enable them safely too!

ngcsp

    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).

Resources

Archives