Quantcast
Channel: Scott Hanselman's Blog
Viewing all 1148 articles
Browse latest View live

Azure App Service Secrets and Web Site Hidden Gems

$
0
0

I just discovered that you can see a preview (almost like a daily build) of the Azure Portal if you go to https://preview.portal.azure.com instead of https://portal.azure.com. Sometimes the changes are big, sometimes they are subtle. It feels faster to me.

Azure Preview Portal

A few days ago I blogged that I had found a number of things in Azure that I wasn't previously aware of like "Metrics per instance (App Service)" which is DEEPLY useful if you run more than one Web App inside an App Service Plan. Remember, an App Service Plan is basically a VM and you can run as many Websites, docker containers, Azure Functions, Mobile Apps, Api Apps, Logic apps, and whatever you can fit in there. Density is the word of the day.

Azure App Service Secrets and Hidden Gems

A bunch of folks agreed that there were some real hidden gems worth exploring so I thought I'd take a moment and do just that. Here's a few of the things that I'm continuously amazed are included for free with App Service.

Console

The Console option under Development Tools

There's a web-based console that you can access from the Azure Portal to explore your apps!

Live HTML5 Console within the Azure Portal

This is basically an HTML 5 bash prompt. I find it useful to double check the contents of certain files in Production, and confirm environment variables are set. I also, for some reason, find it comforting to see that my "cloud web site" actually lives on Drive D:. It calms me to know the Cloud has a D Drive.

App Service Editor

App Service Editor

App Service Editor is the editor that's codenamed "Monaco" that powers Visual Studio Code. It's amazing and few people know about it. I use it to make quick updates to production, although you do need to be aware if you have Continuous Deployment enabled that your changes will get eventually overwritten.

It's like a whole "IDE in the Cloud"

Testing in Production - (A/B Testing)

This is an amazing feature that not enough people know about. So, I'm assuming you are aware of Staging Slots? These are things like dev-, test-, or staging- that you can pull from a different branch during CI/CD, or just a separate but near-identical website that runs on the same hardware. The REAL magic is the Testing in Production feature.

Once you have a slot - I have one here for the Staging Site for BabySmash - you have the option to just "swap" between staging and production...OR...you can set a percentage of traffic you want to go to each slot!

Note that traffic is pinned to a slot for the life of a client session, so you don't have to worry about folks bouncing around if you change the UI or something.

Why is this insanely powerful? You can even make - for example - a "beta" slot and have your customers opt-in to a beta! And you don't have to write any code to enable this! MyApp.com/?x-ms-routing-name=beta would get them there and MyApp.com?x-ms-routing-name=self always points to Production.

Testing in Production 

You could also write a PowerShell script that would slowly move traffic in increments. That way you could ramp up traffic to staging from 5% to 100% - assuming you see no errors or issues.

$siteName = "yourProductionSiteName"

$rule1 = New-Object Microsoft.WindowsAzure.Commands.Utilities.Websites.Services.WebEntities.RampUpRule
$rule1.ActionHostName = "yourSlotSiteName"
$rule1.ReroutePercentage = 10;
$rule1.Name = "stage"

$rule1.ChangeIntervalInMinutes = 10;
$rule1.ChangeStep = 5;
$rule1.MinReroutePercentage = 5;
$rule1.MaxReroutePercentage = 50;
$rule1.ChangeDecisionCallbackUrl = "callBackUrlOfyourChoice-OptionalThatDecidesIfYouShoudlKeepGoing"

Set-AzureWebsite $siteName -Slot Production -RoutingRules $rule1

All this stuff is built-in to the Standard Azure AppServicePlan.

Easy and Cheap Databases

A number of folks in the comments of my last post asked about the 20 websites I have running on my single App Service Plan. Some felt I may have been disingenuous about the pricing and assumed I have a bunch of SQL Server databases behind my sites, or that a site can't be useful without a SQL Server.

There's a few things there to answer. My sites are many different techs, Node.js, Ruby, C# and ASP.NET MVC, and static sites. For example:

  • Running the Ruby Middleman Static Site Generator on Microsoft Azure runs in the cloud when I check code into GitHub but deploys a static site.
  • The Hanselminutes Podcast uses WebMatrix and ASP.NET WebPage's "SQL Compact Edition." This database runs out of a single file that's stored locally.
  • One of my node.js sites uses SQL Lite for its data.
  • One ASP.NET application uses "Azure MySQL in-app" that is also included in Azure App Service. You get a single modest MySQL database that runs in the context of your App Service. It's not super fast and meant for development, but with a little caching it's very workable.
  • One node.js app thinks it is talking MongoDB but actually it's talking via MongoDB protocol support in Azure DocumentDB. You can create an Azure noSQL DocumentDB and point any app that speaks Mongo to it and it Just Works.

There's a number of options, including Easy Tables for your Mobile Apps. Check out http://mobile.azure.com to learn more about how you can get a VERY quick and easy backend for mobile (or web) apps.

Azure App Service Extensions

If you have used Git deploy to an Azure App Service, you likely noticed a "Sidecar" website that your app has. I have babysmash.com which is actually babysmash.azurewebsites.net, right? There's also babysmash.scm.azurewebsites.net that you can't access. That sidecar site (when I'm authenticated) has a ton of easy REST GET APIs I can call to get my process list, files, deployments, and lots more. This is all powered by Kudu, which is open source by the way.

The Azure Kudu sidecar site

Kudu's sidecar site is a "site extension." You can not only write your own Azure Site Extension (they are just NuGet packages!) but it turns out there are a TON of useful already vetted and published extensions you can add to your site today. Those extensions live at http://www.siteextensions.net but you add them directly from the Azure Portal. There's 84 at the time of this blog post.

Azure Site Extensions include:

  • phpMyAdmin - for Admin of MySQL over the web
  • Azure Let's Encrypt - Easy install of Let's Encrypt SSL certs!
  • Image Optimizer - Automatic squishing of your site's JPGs and PNGs because you know you forgot!
  • GoLang Support - Azure doesn't officially support Go in Azure Web Apps...but with this extension it works fine!
  • Jekyll - Easy static site generation in Azure
  • Brotli HTTP Compression

You get the idea.

Diagnostics

I just discovered this "uptime" blade within my Web Apps in the Azure Portal. It tells me my app's uptime and if it's not 100%, it tells my why not and when!

Azure Diagnostics and Uptime

Again, none of this stuff costs extra. You can add Site Extensions or explore your apps to the limit of the underlying App Service Plan. I'm doing all this on a single Standard 1 (S1) App Service Plan.


Sponsor: Excited about the future in ASP.NET? The folks at Progress held an awesome webinar which gives a 360⁰ view of the new ASP.NET Core and how it compares to WebForms and MVC. Watch it now on demand!


© 2016 Scott Hanselman. All rights reserved.
     

Xamarin .NET Workbooks - Interactive Computing is a stellar learning tool

$
0
0

I've been thinking a lot about how to best teach .NET and C#/F# to folks who are new to the space. We've added an in-browser no-install C# tutorial at http://dot.net. You can run through almost a few days lessons in C# without installing anything. Heck, it's useful even if you just want to brush up on your skills.

When I spoke with Safia Abdalla a few months ago she re-introduced me to the ideas behind Interactive Computing and the whole ecosystem around Jupyter Notebooks, and the Nteract project Safia works on. It's pretty amazing.

Pythonistas are familiar with Jupyter and the idea of a notebook that cleanly mixes prose and code. This ecosystem is very friendly to data scientists that are (perhaps) more scientist and less developer. People for whom an IDE is not as interesting as "electric paper."

In fact, many people don't realize that the Microsoft Azure Cloud supports hosting of Jupyter Notebooks using Python, R, and F#.

Azure Notebooks

Notebooks are a great learning resource that go beyond a REPL (an simple interactive console) in that they are effectively textbooks with islands of interactive code. It's even more powerful when you consider graphics, charts, and other interactive models.

Xamarin has a thing called Xamarin Workbooks (I'm calling them .NET Workbooks in my head) that you should download and check out RIGHT NOW. Go get Xamarin Workbooks & Inspector for Windows (or download for Mac). Start playing around with workbooks or try out the samples.

I'm going to try teaching my C# and .NET courses for at least the first day or two using Xamarin .NET Workbooks. I think they have huge potential and I'm thrilled that Miguel and friends are investing so much in them. The potential for these as a learning tool that sits between a REPL and an IDE is huge.

The page at https://developer.xamarin.com/workbooks/ is FILLED with amazing example workbooks and lessons, and it's growing. It has section not only on C# but Android, Games, Graphics as a concept, iOS, WPF, and so much more.

I run it and start here:

Xamarin Workbooks

Then I start typing...prose first! Just real sentences. Then I add some code. Notice that I'm not doing Console.WriteLine, I'm just assigning a variable. Xamarin Workbooks makes a nice visualization of my variable.

var scott = "Hanselman"

The prose is ignored (by the compiler) but the code cells and built upon each other and when you execute one you're executing up to that point. Great for building up concepts.

You can print in other libraries and built upon them like in this chart example using the Urho library.

Charts in Xamarin Workbooks

Not to put to fine a point on it, but you can write really fully featured examples or games in Xamarin Workbooks. Here's a fully 3D realized planet earth WITH SATELLITES. Again, with not just sample code but explanatory prose. It's a textbook come to life.

THIS is how I wish I learned programming 25 years ago. I'd loved to have turned (or demo'ed) a .workbook file. I'm thrilled to see C# folks be able to do simple things that Jupyter users have enjoyed for so long.

3D Earth in Xamarin Workbooks

What do you think? Would this be a good way to deliver a course on learning .NET and C#?


Sponsor: Big thanks to Progress! They recently published a comprehensive whitepaper on The State of C#, discussing the history of C#, what’s new in C# 7 and whether C# is still a viable language. Check it out!



© 2016 Scott Hanselman. All rights reserved.
     

Temporary Fix: Logitech BRIO Camera broken on Windows 10 Insiders 15042

$
0
0

I just updated my Windows 10 to Insiders Fast Build 15042, and suddenly my glorious new Logitech BRIO 4k webcam doesn't work! Well, it's all beta software, but it turns out the issue is with something in the Logitech INF files for their drivers. I'm assuming they'll figure it out, but the nutshell is that the first install works, but the driver gets messed up on the upgrade. You can't just pull out the camera and put it in again, you need to DELETE the drivers and have them redownloaded by Windows Update/Device Manager.

Here's a temporary fix (either until Logitech fixes it and it shows up in Windows Update or you take another Windows 10 upgrade):

Logitech BRIO stops working on Windows 10 Insiders UPGRADE

Go to device manager and right click the device and Uninstall Driver. If it has the checkbox "Delete this driver" then check it. That's required. IF (like me) you don't have that checkbox (I'm not sure why I don't) then you'll need to delete the Logitech driver from the DriverStore. You can do it manually but it's tricky and messy and hard.

We need to delete this driver so it gets reinstalled cleanly.

Driver 2/31/2017

Unplug your webcam. Then, go get the latest copy of DriverStoreExplorer from here https://github.com/lostindark/DriverStoreExplorer/releases and delete JUST this one driver.

Using the Driver Store Explorer

Now, go back to Device Manager and plug in your Logitech BRIO webcam. Note you'll get some super old 2006 driver. Right click the BRIO in Imaging Devices and Update Driver. This will get you BACK to your original state. You still have a driver that will break when you next take a "major" Windows update or Insiders Build, but at least you have a solution until it magically gets fixed.

Yay!


Sponsor: Big thanks to Progress! They recently published a comprehensive whitepaper on The State of C#, discussing the history of C#, what’s new in C# 7 and whether C# is still a viable language. Check it out!


© 2016 Scott Hanselman. All rights reserved.
     

Exploring the new DevOps - Azure Command Line Interface 2.0 (CLI)

$
0
0

Azure CLI 2.0I'm a huge fan of the command line, and sometimes I feel like Windows people are missing out on the power of text mode. Fortunately, today Windows 10 has bash (via Ubuntu on Windows 10), PowerShell, and "classic" CMD. I use all three, myself.

Five years ago I started managing my Azure cloud web apps using the Azure CLI. I've been a huge fan of it ever since. It was written in node.js, it worked the same everywhere, and it got the job done.

Fast forward to today and the Azure team just announced a complete Azure CLI re-write, and now 2.0 is out, today. Initially I was concerned it had been re-written and didn't understand the philosophy behind it. But I understand it now. While it works on Windows (my daily driver) it's architecturally aligned with Mac and (mostly, IMHO) Linux users. It also supports new thinking around a modern command line with support for things like JMESPath, a query language for JSON. It works well and clearly with the usual suspects of course, like grep, jq, cut, etc. It's easily installed with pip, or you just get Python 3.5.x and then just "pip install --user azure-cli."

Linux people (feel free to check the script) can just do this curl, but it's also in apt-get, of course.

curl -L https://aka.ms/InstallAzureCli | bash

NOTE: Since I already have the older Azure CLI 1.0 on my machine, it's useful to note that these two CLIs can live on the same machine. The new one is "az" and the older is "azure," so no problems there.

Or, for those of you who run individual Docker containers for your tools (or if you're just wanting to explore) you can

docker run -v ${HOME}:/root -it azuresdk/azure-cli-python:<version>

Then I just "az login" and I'm off! Here I'll query my subscriptions:

C:\Users\scott\Desktop>  az account list --output table

Name CloudName Sub State IsDefault
------------------------------------------- ----------- --- ------- -----------
3-Month Free Trial AzureCloud 0f3 Enabled
Pay-As-You-Go AzureCloud 34c Enabled
Windows Azure MSDN AzureCloud ffb Enabled True

At this point, it's already feeling familiar. It's "az noun verb" and there's an optional --output parameter. If I don't include --output by default I'll get JSON...which I can then query with JMESPath if I'd like. (Those of us who are older may be having a little XML/XPath/XQuery déjà vu)

I can use JSON, TSV, tables, and even "colorized json" or JSONC.

C:\Users\scott\Desktop> az appservice plan list --output table   

AppServicePlanName GeoRegion Kind Location Status
-------------------- ---------------- ------ ---------------- --------
Default1 North Central US app North Central US Ready
Default1 Southeast Asia app Southeast Asia Ready
Default1 West Europe app West Europe Ready
DefaultServerFarm West US app West US Ready
myEchoHostingPlan North Central US app North Central US Ready

I can make and manage basically anything. Here I'll make a new App Service Plan and put two web apps in it, all managed in a group:

az group create -n MyResourceGroup
# Create an Azure AppService that we can use to host multiple web apps 

az appservice plan create -n MyAppServicePlan -g MyResourceGroup

# Create two web apps within the appservice (note: name param must be a unique DNS entry)
az appservice web create -n MyWebApp43432 -g MyResourceGroup --plan MyAppServicePlan
az appservice web create -n MyWEbApp43433 -g MyResourceGroup --plan MyAppServicePlan

You might be thinking this looks like PowerShell. Why not use PowerShell? Remember this isn't for Windows primarily. There's a ton of DevOps happening in Python on Linux/Mac and this fits very nicely into that. For those of us (myself included) who are PowerShell fans, PowerShell has massive and complete Azure Support. Of course, while the bash folks will need to use JMESPath to simulate passing objects around, PowerShell can keep on keeping on. There's a command line for everyone.

It’s easy to get started with the CLI at http://aka.ms/CLI and learn about the command line with docs and samples. Check out topics like installing and updating the CLI, working with Virtual Machines, creating a complete Linux environment including VMs, Scale Sets, Storage, and network, and deploying Azure Web Apps – and let them know what you think at azfeedback@microsoft.com. Also, as always, the Azure CLI 2.0 is open source and on GitHub.


Sponsor: Check out JetBrains Rider: a new cross-platform .NET IDE. Edit, refactor, test, build and debug ASP.NET, .NET Framework, .NET Core, or Unity applications. Learn more and get access to early builds!



© 2016 Scott Hanselman. All rights reserved.
     

Relationship Hacks: An Allowance System for Adults

$
0
0

Nintendo Switch - YOU DESERVE ONEI'm setting a goal for myself to finish my half-finished book relationshiphacks.com this year. In an attempt to make that happen (and because the recent podcast with my wife was wildly popular) I'm going to try to blog some guiding principles. Then I'll attempt to collect the feedback and comments, improve the posts, then move them into the book.

I got a Nintendo Switch yesterday. Bought it with cash, brought it home, set it up, and - with neither shame nor regret - showed my non-gamer spouse.

"That's cool," she said. "Is that the new Nintendo 64 they were talking about on the radio?"

No judgment. Not a comment about the $300 price tag. Nothing was sad like "do we really need another game?" or "what credit card did you buy that with?"

How is this possible? No fight (not even a lowercase F fight) and no tension.

My wife and I give each other an allowance. In cash.

Every two weeks when our paychecks are deposited, we each get an allowance. It's a $100 a week (yes, for some that's a lot, for others, it's not. It works for us.) and it's the same for each of us. We put all our money in one account, give ourselves the allowance, pay the bills, then if there is anything left over it goes it savings.

Let me back up. We used to a bicker and judge each other for our purchases. If you'd log into our bank you'd see something like:

  • Paycheck
  • Mortgage
  • Car Note
  • $5 Starbucks
  • $3 Subway
  • $8 Chipotle
  • $60 GameStop
  • $70 Nordstrom

HOLD UP. What is that GameStop? Well, what's this Nordstrom? Did you need to be getting that [widget?]

You get the idea. We needed to remove all that noise at the bottom of the ledger as it was distracting us from the larger goals.

Then my wife had the idea that we just needed to pay ourselves first. We can spend that money however we like - with promised zero judgment from the other spouse. That's crucial, otherwise the system doesn't work.

The allowance for anything that isn't "necessarily living stuff." So it's not for toothpaste, but it IS for eating out when we don't need to eat out.

I could have eaten at Chipotle each day this week, but that would come out of my allowance. Instead, I chose to eat at home all month and save my allowance for a Nintendo Switch.

This works - of course - both ways. My wife has hobbies and social stuff that she does, and she uses her allowance for that.

If you made it this far, perhaps you're thinking, "wow, you're a wimp" or "gee, he/she has you in their pocket." Wait.

Step back and absorb. We are grown-ass people. This system works because we designed it for us. All arguments around "frivolous" spending are gone.

This allows us the best of all worlds.

  • It keeps credit card spending to an absolute minimum. 
  • We are empowered and we empower each other with this system.
  • There's a certain sense of power in carrying cash. You know exactly how much you have and exactly when you have to stop spending.
  • We can decide if we want $200 shoes or a $100 meal or a $50 game. One spouse comes home excited about their purchase while the other greets them without resentment. The fixed allowance amount handles that.
    • Additional spending is discussed on a case-by-case basis. But we've picked an amount that is large enough that I could buy something crazy like a Vive - if I am willing to forgo movies, excessive eating out, etc.
  • It sets a good example for the kids as they watch us weigh the pros and cons of a purchase. Money is spent when it's in-hand and not on credit.

My wife and I are in a mixed marriage. It's not that I'm White and she's Black, is that I'm a techie/geek/nerd and she's fairly normal. ;) Of course, this kind of mix isn't gender or race specific. I know lots of couples of varying combos and flavors that bump up against issues in their relationships because of budding resentment, missed or poorly set expectations, divergent points of view around problem solving, and more.

I'd love to hear YOUR story of your partner and your "mix" and how you (mostly) solved it with a simple Relationship Hack like this. Sound off in the comments.


Sponsor: Check out JetBrains Rider: a new cross-platform .NET IDE. Edit, refactor, test, build and debug ASP.NET, .NET Framework, .NET Core, or Unity applications. Learn more and get access to early builds!


© 2017 Scott Hanselman. All rights reserved.
     

Relationship Hacks - Mindfulness - Don't live your life by default

$
0
0

Setting the DefaultsI'm setting a goal for myself to finish my half-finished book relationshiphacks.com this year. In an attempt to make that happen (and because the recent podcast with my wife was wildly popular) I'm going to try to blog some guiding principles. Then I'll attempt to collect the feedback and comments, improve the posts, then move them into the book. Yesterday I posted about "An allowance system for adults."

In this post on I want to touch briefly on the concept of "mindfulness." When I was younger I didn't know this term so I said "don't live your life by default." Phrased alternatively, "don't let your life happen by default."

I mentioned it years ago on a podcast and Paul Apostolos did a very nice blog post where he paraphrased:

Teach your children to make life choices rather than just let life happen to them.

Now, to be clear, stuff happens and this isn't always possible. There's luck, there's planning, there's inherent privilege, but the root idea of mindfulness and awareness is crucial. As they say, "Luck Is what happens when preparation meets opportunity"

I met with a young mentee today who is considering not just leaving her job but also moving to a totally different career. What I appreciated about her perspective and questions was that she clearly was going into the future fully aware of the possibilities. She embraced both the potential good and bad possibilities with a conscious and mindful awareness that was inspiring.

She wasn't going to just "let whatever happen, happen." She wasn't going to just start the game and accept the defaults. She is opening up the options menu of life and trying to change the settings consciously.

I'm doing my best to teach my kids this, hopefully by example. Yes there are things they can't change about themselves, but the one thing they can change (or try) is how they think and how they act. I catch them saying things like "I'm not good at math." They have tapes that are already starting to run in their little heads that feed them negativity and inaction. The defaults are just doing nothing. Humans (myself included) can be very lazy. I want them to build up their reservoirs of self-esteem and "I can do it" so they don't accept the defaults.

Do you have any stories of where you "woke up" and realized you were coasting (perhaps for a week, perhaps for years) and were just accepting the defaults in your life? How did you break out of that thinking?


Sponsor: Get next level application monitoring with Raygun - The revolutionary software intelligence platform for your web and mobile apps. Take a free trial today!



© 2017 Scott Hanselman. All rights reserved.
     

Nintendo Switch and The Legend of Zelda: Breath of the Wild are an ABSOLUTE JOY

$
0
0

I bought a Nintendo Switch last week with my allowance and I'm utterly smitten. It's brilliant. It's absolutely brilliant.

The Nintendo Switch is FAB

Now, to be clear, I'm neither a hardcore gamer nor a journalist. However, I am someone who grew up on Mario, enjoys Retrogaming and my Xbox One, and most of all, I know genius when I see it.

The Legend of Zelda: Breath of the Wild is a wonderful example of the very best that video games can offer as an art form in 2017. - Me

It may be the best video game ever. And it is because it borrows so much from the decades of refinement whose shoulders it stands upon.

Let's break this down into two halves. First, Zelda (which is available on WiiU and Switch), and later, the Switch itself.

If you don't feel like reading this, just trust me and buy a Switch and Zelda and bask in the hundreds of hours of joy and wonder it will bring you. It's the most fun I've had with a video game in recent memory. I also profoundly recommend the gorgeous hardcover The Legend of Zelda: Breath of the Wild: The Complete Official Guide Collector's Edition. The maps, the art, and the gentle walkthroughs are more fun than googling. The kids and I have enjoyed exploring the wilderness with the giant map unfurled in front of us.

Legend of Zelda: Breath of the Wild

It's HUGE. It's estimated at 360 square kilometers. They are saying it's 1.5x the Skyrim map and may be larger than Witcher 3. A cynic could call Breath of the Wild derivative, but an optimist like me says, well, they stole every game mechanic that was awesome over the last few decades, and made the near-perfect game. I love that this is a console launch game that is polished and has at LEAST 100 hours or more for the completist.

Zelda is gorgeousWhat is Zelda like?

  • Just Cause - Fly off a cliff with a paraglider, fly over a raging river and land on an elk, tame it and ride it. Because you're awesome and you can.
  • Witcher 3 - Massive map, armor sets, crafting and more.
  • Assassin's Creed - Climbing because...it's fun. Getting maps by unlocking towers and jumping off.
  • Grand Theft Auto - The first massive sandbox without loading. You enter a new area and get a brief subtitle announcing you're in a new "neighborhood" and then you wander.
  • Skyrim - The Elder Scrolls was the first video game I played where I climbed mountains "because they were there" and really had a sense of wonder when I got to the top. Draw distance!
  • Shadow of the Colossus - There's amazing HUGE boss fights that involve climbing the enemy, racing after monsters with horses, and sometimes going inside them.
  • Bard's Tale - Because I'm old.

Complaints? Honestly, if I had to truly nit. And I mean really nit I'd say the durability of weapons, particularly swords, is annoying. I would make them last maybe 50% longer. Also, moving in and out of Shrines has a load screen that takes 10-15 seconds. But really, that's like saying "I wish Beyoncé was 5'8", not 5'7". I mean, REALLY. Beyoncé. Shush.

The Nintendo Switch

It's portable. Just like in the ad, you can pull the Switch out and leave. In my video below I also switch to portable AND have to re-sync the controllers, so there is one additional ceremony, but it's easy.

It feels like a console when it's plugged in. I've got it plugged into my TV and from my couch it looks as nice as any of my devices. Sure, it's not an Xbox One playing Tom Clancy: The Division. But it's a brilliant tradeoff for a device I can simply pick up and go outside with (which I've done, with considerable appreciation.)

I'm surprised that folks are complaining about the gaming resolution, frame rates, battery life, older processor, or said "it's just like an iPad with an HDMI cable." Here's why:

  • Resolution - Zelda runs at 720p (the native res of the touchscreen) at 30fps. It's just 6.5" and 720p is just fine when it's a foot or more from your face.
  • Battery - I got an easy 3 hours out of it. If you're on a plane, carry a cable and extra battery. If you need to portably game more than 3 hours, take a break. ;) Seriously, though, given my appreciation of it's portability and power and experience this is reasonable. One can always complain about battery life.
  • Frame Rate - When you dock the Switch and run Zelda over your TV the resolution is 900p and sometimes it lags. If you're in the forest, and it's raining, and there's a bunch of enemies around there will totally be moments of 20 fps. But it passes. And it's still gorgeous. A small price to pay, and we don't know if it's fixable with a software patch. Given that launch titles rarely use the new hardware in an optimized fashion, it's more than reasonable to give them a break on this.
  • Older Processor - The Switch is using the older Nvidia Tegra X1 processor. As a business person this makes sense. It's a $300 device. It's not reasonable to expect all day battery life and 4k gaming on a device that weights two-thirds of a pound.
  • Innovation - Yes, you can plug your iPad into your TV. But most folks don't. And the iPad and iOS clearly haven't tried to optimize for this scenario. Apple has scandalously under-supported their MFi Controller Spec, even though the SteelSeries is brilliant. Frankly, Apple handed Nintendo a huge opportunity by not making a proper controller and supporting MFi better with Game Devs. The Switch might not exist if I could BlueTooth Pair any controller to my iPad and play Skyrim on an iPad. Oh ya, I'd have to have an iPad with expandable memory or a cartridge slot. ;) The Switch is a new category of device. It's not an iPad.

It's a fantastic device for the price and the promises, for the most part, were kept. That said, a few gentle warnings if you do get a Switch.

  • If you put the joy-cons on backwards they might get stuck and you could perhaps damage the system.
  • The joy-cons have these little wrist straps as well, and to be clear if you put these on backwards you're in trouble. Make sure you line up the plus + signs. There's a + on the right joy-con and a - on the left one. Use the correct strap for the correct joy-con.
  • If you slam the Switch into the dock it's possible you could scratch the screen. I always treat $300 equipment like it cost $300. Be somewhat careful.

My Recommended Nintendo Switch accessories (I own each of these)

These accessories are by no means required (the Switch has everything you need out of the box) but these are all 4+ star rated and I've purchased them myself and appreciate them. Yes, I've gone overboard and my $300 Switch is now a $500 Switch BUT I HAVE NO REGERTS. ;)

  • Some kind of Carrying Case. I have the Zelda Special Edition case, but all the cases that are official Nintendo are excellent.
  • The Nintendo Switch Pro Controller. If you're going to hook your Switch up to the TV you might consider the pro controller. The Switch does come with a quasi-controller that has you pop the two joy-cons into a harness to simulate a typical Xbox/PS Controller but the ergonomics are exact by any stretch. The Pro Controller is fantastic. It's 99% the same as an Xbox Controller and includes (quietly) the full 360 degree gyro support that (I believe) Switch Games will be known for (see the second above on gyro in Zelda.)
  • Joy-con Grips. This was a frivolous purchase but a good one. I've got big hands and the Joy-Cons are NOT comfortable when turned horizontally and used for any period of time. These little holsters turn them into tiny Pro Controllers and make two player a LOT easier.
  • Compact Playstand. The Switch has one major hardware design "flaw" in that it can't be charged while it's using its kickstand. This little folding playstand is nice because it's 3-in-1 and can also perfectly fit a 3DSXL.
  • Large 128g EXTRA-FAST microSDXC SD Card. The Switch has only 32gigs of internal space and if you (theoretically) downloaded Zelda you'll use 13gigs. I can see myself using up a LOT of space in the next year so I got this 128G SD Card. And it's FAST.
  • 6 pack of Microfiber Cleaning Cloths  - I can't stand a dirty touchscreen. Can't. I have two dozen of these spread around the house, my car, my backpack. Can't have too many given laptops, TVs, and iPads.
  • USB C cables - Both the Switch and Pro Controller use USB C (finally!) so pick up a few USB C cables that you can use to charge in a pinch from your laptop, existing car charger, or portable battery. I only buy Anker Batteries.
  • A Zelda Amiibo - Amiibos are these little figurines with an RFID/NFC dealie inside. They are registered to you and they can "light up" features in all kinds of games. In Zelda specifically you can (a little later in the game) use them to get daily food and other bonuses. Plus they look nice on your desk.

My Predictions for the Nintendo Switch in 2017

I'm looking forward to seeing what the Nintendo Switch can become. I think/predict we'll see this on the Switch in 2017.

  • A thrilling Indie Game Community. Yes, the launch titles are weak. There aren't a ton of launch games. Call it a soft launch. But give it a few months.
  • Virtual Console - The ability to play SNES/NES and other games via some kind of emulation from Nintendo. We have already seen NEO-GEO games show up in the last few days! I can imagine we'll see a Mario Collection going back 30+ years.
  • Video Apps - If they add Hulu, Netflix, and Amazon, then I'll be taking my Switch with me to
  • A USB-C to HDMI cable - I don't want to take the dock with me on trips, so I'd love a USB-C to HDMI cable from Nintendo (It'll need their magic box/chip) to free up my bag.
  • A great balance between AAA Games and "classic" games. If Zelda and Shovel Knight are any indication, the future is bright.
  • Continued updates to the online experience. I suspect we'll get firmware and store updates quarterly.

But at the same time, what's the nightmare scenario? Nothing happens. No games come out and I have a $500 Zelda-specific device. I'm totally OK with that give the joy of the last week. So between the worst-case scenario and the best case, no matter what happens it's awesome and I'm a satisfied customer.

* I've used Amazon referral links here. Please use them and you'll support this blog and my Amiibo Habit.


Sponsor: Get next level application monitoring with Raygun - The revolutionary software intelligence platform for your web and mobile apps. Take a free trial today



© 2017 Scott Hanselman. All rights reserved.
     

ZEIT now deployments of open source ASP.NET Core web apps with Docker

$
0
0

ZEIT is a new cloud service and "now" is the name of their deployment tool. ZEIT World is their DNS service. If you head over to https://zeit.co/ you'll see a somewhat cryptic animated gif that shows how almost impossibly simple it is to deploy a web app with ZEIT now.

ZEIT works with .NET Core and ASP.NET

You can make a folder, put an index.html (for example) in it and just run "now." You'll automatically get a website with an autogenerated name and it'll be live. It's probably the fastest and easiest deploy I've ever seen. Remember when Heroku (then Azure, then literally everyone) started using git for deployment? Clearly being able to type "now" and just get a web site on the public internet was the next step. (Next someone will make "up" which will then get replaced with just pressing ENTER on an empty line! ;) )

Jokes aside, now is clean and easy. I appreciate their organizational willpower to make an elegant and simple command line tool. I suspect it's harder than it looks to keep things simple.

All of their examples use JavaScript and node.js, but they also support Docker, which means they support open source ASP.NET Core on .NET Core! But do they know they do? ;) Let's find out.

And more importantly, how easy is it? Can I take a site from concept to production in minutes? Darn tootin' I can.

First, make a quick ASP.NET Core app. I'll use the MVC template with Bootstrap.

C:\Users\scott\zeitdotnet>dotnet new mvc

Content generation time: 419.5337 ms
The template "ASP.NET Core Web App" created successfully.

I'll do a quick dotnet restore to get the packages for my project.

C:\Users\scott\zeitdotnet>dotnet restore

Restoring packages for C:\Users\scott\zeitdotnet\zeitdotnet.csproj...
Generating MSBuild file C:\Users\scott\zeitdotnet\obj\zeitdotnet.csproj.nuget.g.props.
Generating MSBuild file C:\Users\scott\zeitdotnet\obj\zeitdotnet.csproj.nuget.g.targets.
Writing lock file to disk. Path: C:\Users\scott\zeitdotnet\obj\project.assets.json
Restore completed in 2.93 sec for C:\Users\scott\zeitdotnet\zeitdotnet.csproj.

NuGet Config files used:
C:\Users\scott\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
https://api.nuget.org/v3/index.json
C:\LocalNuGet
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

Now I need to add a Dockerfile. I'll make one in the root that looks like this:

FROM microsoft/aspnetcore

LABEL name="zeitdotnet"
ENTRYPOINT ["dotnet", "zeitdotnet.dll"]
ARG source=.
WORKDIR /app
EXPOSE 80
COPY $source .

Note that I could have ZEIT build my app for me if I used the aspnetcore Dockerfile that includes the .NET Core SDK, but that would not only make my deployment longer, it would also make my docker images a LOT larger. I want to include JUST the .NET Core runtime in my image, so I'll build and publish locally.

ZEIT now is going to need to see my Dockerfile, and since I want my app to include the binaries (I don't want to ship my source in the Docker image up to ZEIT) I need to mark my Dockerfile as "Content" and make sure it's copied to the publish folder when my app is built and published.

<ItemGroup>
  <None Remove="Dockerfile" />
</ItemGroup>
<ItemGroup>
  <Content Include="Dockerfile">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Content>
</ItemGroup>
I'll add this my project's csproj file. If I was using Visual Studio, this is the same as right clicking on the Properties of the Dockerfile, setting it to Content and then "Always Copy to Output Directory."

Now I'll just build and publish to a folder with one command:

C:\Users\scott\zeitdotnet>dotnet publish

Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.

zeitdotnet -> C:\Users\scott\zeitdotnet\bin\Debug\netcoreapp1.1\zeitdotnet.dll

And finally, from the .\bin\Debug\netcoreapp1.1\ folder I run "now." (Note that I've installed now and signed up for their service, of course.)

C:\Users\scott\zeitdotnet\bin\Debug\netcoreapp1.1\publish>now

> Deploying ~\zeitdotnet\bin\Debug\netcoreapp1.1\publish
> Ready! https://zeitdotnet-gmhcxevqkf.now.sh (copied to clipboard) [3s]
> Upload [====================] 100% 0.0s
> Sync complete (196.18kB) [2s]
> Initializing…
> Building
> ▲ docker build
> ---> 035a0a1401c3
> Removing intermediate container 289b9e4ce5d9
> Step 6 : EXPOSE 80
> ---> Running in efb817308333
> ---> fbac2aaa3039
> Removing intermediate container efb817308333
> Step 7 : COPY $source .
> ---> ff009cfc48ea
> Removing intermediate container 8d650c1867cd
> Successfully built ff009cfc48ea
> ▲ Storing image
> ▲ Deploying image
> Deployment complete!

Now has put the generated URL in my clipboard (during deployment you'll get redirected to a lovely status page) and when it's deployed I can visit my live site. But, that URL is not what I want. I want to use a custom URL.

I can take one of my domains and set it up with ZEIT World's DNS but I like DNSimple (ref).

I can add my domain as an external one after adding a TXT record to my DNS to verify I own it. Then I setup a CNAME to point my subdomain to alias.zeit.co.

C:\Users\scott\Desktop\zeitdotnet>now alias https://zeitdotnet-gmhcxevqkf.now.sh http://zeitdotnet.hanselman.com

> zeitdotnet.hanselman.com is a custom domain.
> Verifying the DNS settings for zeitdotnet.hanselman.com (see https://zeit.world for help)
> Verification OK!
> Provisioning certificate for zeitdotnet.hanselman.com
> Success! Alias created:
https://zeitdotnet.hanselman.com now points to https://zeitdotnet-gmhcxevqkf.now.sh [copied to clipboard]

And that's it. It even has a nice SSL certificate that they applied for me. It doesn't terminate to SSL all the way into the docker container's Kestral web server, but for most things that aren't banking it'll be just fine.

All in all, a lovely experience. Here's my Hello World ASP.NE Core app running in ZEIT and deployed with now  at http://zeitdotnet.hanselman.com (if you are visiting this long after this was published, this sample MAY be gone.)

I am still learning about this (this whole exercise was about 30 total minutes and asking Glenn Condron a docker question) so I'm not clear how this would work in a large multi-container deployment, but as long as your site is immutable (don't write to the container's local disk!) ZEIT says it will scale your single containers. Perhaps docker-compose support is coming?


Sponsor: Did you know VSTS can integrate closely with Octopus Deploy? Join Damian Brady and Brian A. Randell as they show you how to automate deployments from VSTS to Octopus Deploy, and demo the new VSTS Octopus Deploy dashboard widget. Register now!



© 2017 Scott Hanselman. All rights reserved.
     

Options for CSS and JS Bundling and Minification with ASP.NET Core

$
0
0

Maria and I were updating the NerdDinner sample app (not done yet, but soon) and were looking at various ways to do bundling and minification of the JSS and CS. There's runtime bundling on ASP.NET 4.x but in recent years web developers have used tools like Grunt or Gulp to orchestrate a client-side build process to squish their assets. The key is to find a balance that gives you easy access to development versions of JS/CSS assets when at dev time, while making it "zero work" to put minified stuff into production. Additionally, some devs don't need the Grunt/Gulp/npm overhead while others absolutely do. So how do you find balance? Here's how it works.

I'm in Visual Studio 2017 and I go File | New Project | ASP.NET Core Web App. Bundling isn't on by default but the configuration you need IS included by default. It's just minutes to enable and it's quite nice.

In my Solution Explorer is a "bundleconfig.json" like this:

// Configure bundling and minification for the project.

// More info at https://go.microsoft.com/fwlink/?LinkId=808241
[
{
"outputFileName": "wwwroot/css/site.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/js/site.min.js",
"inputFiles": [
"wwwroot/js/site.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optionally generate .map file
"sourceMap": false
}
]

Pretty simple. Ins and outs. At the top of the VS editor you'll see this yellow prompt. VS knows you're in a bundleconfig.json and in order to use it effectively in VS you grab a small extension. To be clear, it's NOT required. It just makes it easier. The source is at https://github.com/madskristensen/BundlerMinifier. Slip this UI section if you just want Build-time bundling.

BundleConfig.json

If getting a prompt like this bugs you, you can turn all prompting off here:

Tools Options HTML Advanced Identify Helpful Extensions

Look at your Solution Explorer. See under site.css and site.js? There are associated minified versions of those files. They aren't really "under" them. They are next to them on the disk, but this hierarchy is a nice way to see that they are associated, and that one generates the other.

Right click on your project and you'll see this Bundler & Minifier menu:

Bundler and Minifier Menu

You can manually update your Bundles with this item as well as see settings and have bundling show up in the Task Runner Explorer.

Build Time Minification

The VSIX (VS extension) gives you the small menu and some UI hooks, but if you want to have your bundles updated at build time (useful if you don't use VS!) then you'll want to add a NuGet package called BuildBundlerMinifier.

You can add this NuGet package SEVERAL ways. Which is awesome.

  • Add it from the Manage NuGet Packages menu
  • Add it from the command line via "dotnet add package BuildBundlerMinifier"
    • Note that this adds it to your csproj without you having to edit it! It's like "nuget install" but adds references to projects!  The dotnet CLI is lovely.
  • If you have the VSIX installed, just right-click the bundleconfig.json and click "Enable bundle on build..." and you'll get the NuGet package.
    Enable bundle on build

Now bundling will run on build...

c:\WebApplication8\WebApplication8>dotnet build

Microsoft (R) Build Engine version 15
Copyright (C) Microsoft Corporation. All rights reserved.

Bundler: Begin processing bundleconfig.json
Bundler: Done processing bundleconfig.json
WebApplication8 -> c:\WebApplication8\bin\Debug\netcoreapp1.1\WebApplication8.dll

Build succeeded.
0 Warning(s)
0 Error(s)

...even from the command line with "dotnet build." It's all integrated.

This is nice for VS Code or users of other editors. Here's how it would work entirely from the command prompt:

$ dotnet new mvc

$ dotnet add package BuildBundlerMinifier
$ dotnet restore
$ dotnet run

Advanced: Using Gulp to handle Bundling/Minifying

If you outgrow this bundler or just like Gulp, you can right click and Convert to Gulp!

Convert to Gulp

Now you'll get a gulpfile.js that uses the bundleconfig.json and you've got full control:

gulpfile.js

And during the conversion you'll get the npm packages you need to do the work automatically:

npm and bower

I've found this to be a good balance that can get quickly productive with a project that gets bundling without npm/node, but I can easily grow to a larger, more npm/bower/gulp-driven front-end developer-friendly app.


Sponsor: Did you know VSTS can integrate closely with Octopus Deploy? Join Damian Brady and Brian A. Randell as they show you how to automate deployments from VSTS to Octopus Deploy, and demo the new VSTS Octopus Deploy dashboard widget. Register now!


© 2017 Scott Hanselman. All rights reserved.
     

Visual Studio 2017 can automatically recommend NuGet packages for unknown types

$
0
0

There's a great feature in Visual Studio 2015.3 and Visual Studio 2017 that is turned off by default. It does use about ~10 megs of memory but it makes me so happy that I turn it on.

It's under C# | Advanced in Tools Options. Or you can just type "Advanced" in the Quick Launch Bar (via Ctrl+Q if you like) to jump there.

I turn on "Suggest usings for types in NuGet packages" and "Suggest usings for types in reference assemblies."

I turn on "Suggest usings for types in NuGet packages" and "Suggest usings for types in reference assemblies."

For example, if I am typing some code and start referencing a Type that isn't in my project but could be...you know how sometimes you just need a using statement to bring in a namespace? In this Web App, I already have Json.NET so it recommends a using statement to bring it into scope.

Can't find JSON

But in this Console App, I have no packages beyond the defaults. When I start using a type like JObject from a popular NuGet, Visual Studio can offer to install Json.NET for me!

Find and install latest version

Or another example:

XmlDocument

And then I can immediately continue typing with intellisense. If I know what I'm doing, I can bring in something like this without ever using the mouse or leaving the line.

JObject is now usable

Good stuff! 


Sponsor: Check out JetBrains Rider: a new cross-platform .NET IDE. Edit, refactor, test, build and debug ASP.NET, .NET Framework, .NET Core, or Unity applications. Learn more and get access to early builds!



© 2017 Scott Hanselman. All rights reserved.
     

Command Line: Using dotnet watch test for continuous testing with .NET Core 1.0 and XUnit.net

$
0
0

I've installed .NET Core 1.0 on my machine. Let's see if I can get a class library and tests running and compiling automatically using only the command line. (Yes, some of you are freaked out by my (and other folks') appreciation of a nice, terse command line. Don't worry. You can do all this with a mouse if you want. I'm just enjoying the CLI.

NOTE: This is considerably updated from the project.json version in 2016.

First, I installed from http://dot.net/core. This should all work on Windows, Mac, or Linux.

C:\> md testexample & cd testexample


C:\testexample> dotnet new sln
Content generation time: 33.0582 ms
The template "Solution File" created successfully.

C:\testexample> dotnet new classlib -n mylibrary -o mylibrary
Content generation time: 40.5442 ms
The template "Class library" created successfully.

C:\testexample> dotnet new xunit -n mytests -o mytests
Content generation time: 87.5115 ms
The template "xUnit Test Project" created successfully.

C:\testexample> dotnet sln add mylibrary\mylibrary.csproj
Project `mylibrary\mylibrary.csproj` added to the solution.

C:\testexample> dotnet sln add mytests\mytests.csproj
Project `mytests\mytests.csproj` added to the solution.

C:\testexample> cd mytests

C:\testexample\mytests> dotnet add reference ..\mylibrary\mylibrary.csproj
Reference `..\mylibrary\mylibrary.csproj` added to the project.

C:\testexample\mytests> cd ..

C:\testexample> dotnet restore
Restoring packages for C:\Users\scott\Desktop\testexample\mytests\mytests.csproj...
Restoring packages for C:\Users\scott\Desktop\testexample\mylibrary\mylibrary.csproj...
Restore completed in 586.73 ms for C:\Users\scott\Desktop\testexample\mylibrary\mylibrary.csproj.
Installing System.Diagnostics.TextWriterTraceListener 4.0.0.
...SNIP...
Installing Microsoft.NET.Test.Sdk 15.0.0.
Installing xunit.runner.visualstudio 2.2.0.
Installing xunit 2.2.0.
Generating MSBuild file C:\Users\scott\Desktop\testexample\mytests\obj\mytests.csproj.nuget.g.props.
Generating MSBuild file C:\Users\scott\Desktop\testexample\mytests\obj\mytests.csproj.nuget.g.targets.
Writing lock file to disk. Path: C:\Users\scott\Desktop\testexample\mytests\obj\project.assets.json
Installed:
16 package(s) to C:\Users\scott\Desktop\testexample\mytests\mytests.csproj

C:\testexample> cd mytests & dotnet test

Build started, please wait...
Build completed.

Test run for C:\testexample\mytests\bin\Debug\netcoreapp1.1\mytests.dll(.NETCoreApp,Version=v1.1)
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait...
[xUnit.net 00:00:00.5539676] Discovering: mytests
[xUnit.net 00:00:00.6867799] Discovered: mytests
[xUnit.net 00:00:00.7341661] Starting: mytests
[xUnit.net 00:00:00.8691063] Finished: mytests

Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 1.8329 Seconds

Of course, I'm testing nothing yet but pretend there's a test in the tests.cs and something it's testing (that's why I added a reference) in the library.cs, OK?

Now I want to have my project build and tests run automatically as I make changes to the code. I can't "dotnet add tool" yet so I'll add this line to my test's project file:

<ItemGroup>

<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
</ItemGroup>

Like this:

Adding <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />

Then I just dotnet restore to bring in the tool.

NOTE: There's a color bug using only cmd.exe so on "DOS" you'll see some ANSI chars. That should be fixed in a minor release soon - the PR is in and waiting. On bash or PowerShell things look fin.

In this screenshot, you can see as I make changes to my test and hit save, the DotNetWatcher Tool sees the change and restarts my app, recompiles, and re-runs the tests.

Test Run Successful

All this was done from the command line. I made a solution file, made a library project and a test project, made the test project reference the library, then built and ran the tests. If I could add the tool from the command line I wouldn't have had to manually touch the project file at all.

Again, to be sure, all this is stuff you can (and do) do in Visual Studio manually all the time. But I'll race you anytime. ;)


Sponsor: Check out JetBrains Rider: a new cross-platform .NET IDE. Edit, refactor, test, build and debug ASP.NET, .NET Framework, .NET Core, or Unity applications. Learn more and get access to early builds!


© 2017 Scott Hanselman. All rights reserved.
     

Trying ASP.NET Core on the Google Cloud Platform "App Engine Flexible Environment"

$
0
0

Last week I used Zeit and "now" to deploy an ASP.NET Core app (via a container) to the Zeit cloud. Tonight the kids are asleep so I thought I'd deploy to the Google Cloud. They've got beta support for open source ASP.NET so it's a perfect time. Google even has Google Cloud Tools for Visual Studio (2015).

I'll install the Google Cloud SDK. I checked "beta" as well.

Installing the Google Cloud SDK

Install it, login to your Google account and setup/select a project. I make a new folder and put an "app.yaml" in there with this inside as a directive to the Google Cloud Platform.

runtime: aspnetcore

env: flex

Here's a gratuitous screenshot:

App.yaml

I did a dotnet new, dotnet restore, and finally a:

dotnet publish -c Release

which makes a publish folder that will get sent up to the cloud.

IMPORTANT NOTE: I initially tried to push a .NET Core app using the .NET Core 1.1 runtime but Google Cloud's beta support in the flexible environment is set up for the 1.0.3 runtime (using their own custom docker base image) as of the time of this blog post, so you'll want to "dotnet new mvc --framework netcoreapp1.0" and set the "RuntimeFrameworkVersion" to get that specific shared LTS (Long Term Support) version. As soon as the Google Cloud flex runtime has the latest LTS (1.0.4, at the time of this writing) then apps would just roll forward.

<PropertyGroup>
  <TargetFramework>netcoreapp1.0</TargetFramework>

<RuntimeFrameworkVersion>1.0.3</RuntimeFrameworkVersion> </PropertyGroup>

Otherwise you'll get errors. Fortunately those errors are very clear.

.NET Core Runtime 1.0.3 supported

The walkthrough on Google Cloud suggests you copy the app.yaml file using a standard CLI copy command. However, since you're going to need that app.yaml EVERY publish, just add it to the csproj like this:

<ItemGroup>

<Content Include="app.yaml" CopyToOutputDirectory="Always" />
</ItemGroup>

This way it'll end up in publish automatically. You can then publish to the "AppEngine flexible environment:

dotnet restore

dotnet publish -c Release
gcloud beta app deploy .\bin\Release\netcoreapp1.0\publish\app.yaml
gcloud app browse // THIS IS JUST TO VISIT IT AFTER IT'S PUBLISHED

NOTE: You may get an ERROR that billing isn't enabled, or that the cloudbuild.googleapis.com aren't enabled. You'll need to ensure you have an active Free Trial, then go to the API Manager in the Google Cloud Platform dashboard and enable "Google Cloud Container Builder API." I also had to manually enable the API for the "Flexible" Environment and confirm I had a valid billing account.

Needed to enable some Billing APIs in the Google Cloud

Once I enabled a few APIs, I just did a standard "gcloud beta app deploy" as above:

gcloud beta app deploy

Pretty cool stuff! Here is my ASP.NET Core app running on GCP's Flex engine:

ASP.NET on Google Cloud

You can "tail" your app with "gcloud app logs tail -s default" and you'll see the output from .NET Core and ASP.NET (and Kestrel) in the Google Cloud!

gcloud app logs tail -s default

Or online in the Google "Stackdriver" logging page:

Google Stackdriver Logging page showing ASP.NET Core Logging

Go read up more on the Google Cloud Platform Blog. They even support Kubernetes clusters with ASP.NE Core apps packaged as Docker containers.


Sponsor: Thanks to Redgate! Track every change to your database! See who made changes, what they did, & why, with SQL Source Control. Get a full version history in your source control system. See how.



© 2017 Scott Hanselman. All rights reserved.
     

Writing and debugging Linux C++ applications from Visual Studio using the "Windows Subsystem for Linux"

$
0
0

I've blogged about the "Windows Subsystem for Linux" (also known as "Bash on Ubuntu on Windows") many times before. Response to this Windows feature has been a little funny because folks try to:

  • Minimize it - "Oh, it's just Cygwin." (It's actually not, it's the actual Ubuntu elf binaries running on a layer that abstracts the Linux kernel.)
  • Design it - "So it's a docker container? A VM?" (Again, it's a whole subsystem. It does WAY more than you'd think, and it's FASTer than a VM.)

Here's a simple explanation from Andrew Pardoe:

1. The developer/user uses a bash shell.
2. The bash shell runs on an install of Ubuntu
3. The Ubuntu install runs on a Windows subsystem. This subsystem is designed to support Linux.

It's pretty cool. WSL has, frankly, kept me running Windows because I can run cmd, powershell, OR bash (or zsh or Fish). You can run vim, emacs, tmux, and run Javascript/node.js, Ruby, Python, C/C++, C# & F#, Rust, Go, and more. You can also now run sshd, MySQL, Apache, lighttpd as long as you know that when you close your last console the background services will shut down. Bash on Windows is for developers, not background server apps. And of course, you apt-get your way to glory.

Bash on Windows runs Ubuntu user-mode binaries provided by Canonical. This means the command-line utilities are the same as those that run within a native Ubuntu environment.

I wanted to write a Linux Console app in C++ using Visual Studio in Windows. Why? Why not? I like VS.

Setting up Visual Studio 2017 to compile and debug C++ apps on Linux

Then, from the bash shell make sure you have build-essential, gdb's server, and openssh's server:

$ sudo apt update

$ sudo apt install -y build-essential
$ sudo apt install -y gdbserver
$ sudo apt install -y openssh-server

Then open up /etc/ssh/sshd_config with vi (or nano) like

sudo nano /etc/ssh/sshd_config

and for simplicity's sake, set PasswordAuthentication to yes. Remember that it's not as big a security issue as you'd think as the SSHD daemon closes when your last console does, and because WSL's subsystem has to play well with Windows, it's privy to the Windows Firewall and all its existing rules, plus we're talking localhost also.

Now generate SSH keys and manually start the service:

$ sudo ssh-keygen -A

$ sudo service ssh start

Create a Linux app in Visual Studio (or open a Makefile app):

File | New Project | Cross Platform | Linux

Make sure you know your target (x64, x86, ARM):

Remote GDB Debugger options

In Visual Studio's Cross Platform Connection Manager you can control your SSH connections (and set up ones with private keys, if you like.)

Tools | Options | Cross Platfrom | Connection Manager

Boom. I'm writing C++ for Linux in Visual Studio on Windows...running, compiling and debugging on the local Linux Subsystem

I'm writing C++ in Visual Studio on Windows talking to the local Linux Subsystem

BTW, for those of you, like me, who love your Raspberry Pi tiny Linux computers...this is a great way to write C++ for those little devices as well. There's even a Blink example in File | New Project to start.

Also, for those of you who are very advanced, stop using Mingw-w64 and do cool stuff like compiling gcc 6.3 from source under WSL and having VS use that! I didn't realize that Visual Studio's C++ support lets you choose between a number of C++ compilers including both GCC and Clang.


Sponsor: Thanks to Redgate! Track every change to your database! See who made changes, what they did, & why, with SQL Source Control. Get a full version history in your source control system. See how.


© 2017 Scott Hanselman. All rights reserved.
     

How to control PowerPoint on Windows with a Bluetooth Nintendo Switch JoyCon controller! (or a Surface Pen)

$
0
0

I usually use a Logitech Presentation Clicker to control PowerPoint presentations, but I'm always looking for new ways. Michael Samarin has a great app called KeyPenX that lets you use a Surface pen to control PowerPoint!

However, I've also got this wonderful Nintendo Switch and two JoyCon controllers. Rachel White reminded me that they are BlueTooth! So why not pair them to your machine and map some of their buttons to keystrokes?

Let's do it!

First, hold the round button on the black side of the controller between the SL and SR buttons, then go into Windows Settings and Add Bluetooth Device.

Add a Bluetooth Device

You can add them both if you like! They show up like Game Controllers to Windows:

Hey a JoyCon is a JoyStick to Windows!

Ah, but these are Joysticks. We need to map JoyStick Actions to Key Presses. Enter JoyToKey. If you keep using it (even though you can use it free) it's Shareware, you can buy JoyToKey for just $7.

Hold down a button on your Joystick/Joycon to see what it maps to. For example, here I'm clicking in on the stick and I can see that's Button 12.

Using JoyToKey to map JoyCons to PowerPoint

Map them anyway you like. I mapped left and right to PageUp and PageDown so now I can control PowerPoint!

Using JoyToKey to map JoyCons to PowerPoint

And here it is in action:

ZOMG YOU CAN CONTROL POWERPOINT WITH THE #NintendoSwitch JoyCon! /ht @ohhoe

A post shared by Scott Hanselman (@shanselman) on


So fun! Enjoy!


Sponsor: Did you know VSTS can integrate closely with Octopus Deploy? Watch Damian Brady and Brian A. Randell as they show you how to automate deployments from VSTS to Octopus Deploy, and demo the new VSTS Octopus Deploy dashboard widget. Watch now



© 2017 Scott Hanselman. All rights reserved.
     

Ruby on Rails on Azure App Service (Web Sites) with Linux (and Ubuntu on Windows 10)

$
0
0

Running Ruby on Rails on Windows has historically sucked. Most of the Ruby/Rails folks are Mac and Linux users and haven't focused on getting Rails to be usable for daily development on Windows. There have been some heroic efforts by a number of volunteers to get Rails working with projects like RailsInstaller, but native modules and dependencies almost always cause problems. Even more, when you go to deploy your Rails app you're likely using a Linux host so you may run into differences between operating systems.

Fast forward to today and Windows 10 has the Ubuntu-based "Linux Subsystem for Windows" (WSL) and the native bash shell which means you can run real Linux elf binaries on Windows natively without a Virtual Machine...so you should do your Windows-based Rails development in Bash on Windows.

Ruby on Rails development is great on Windows 10 because you've Windows 10 handling the "windows" UI part and bash and Ubuntu handling the shell.

After I set it up I want to git deploy my app to Azure, easily.

Developing on Ruby on Rails on Windows 10 using WSL

Rails and Ruby folks can apt-get update and apt-get install ruby, they can install rbenv or rvm as they like. These days rbenv is preferred.

Once you have Ubuntu on Windows 10 installed you can quickly install "rbenv" like this within Bash. Here I'm getting 2.3.0.

~$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv

~$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
~$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
~$ exec $SHELL
~$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
~$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
~$ exec $SHELL
~$ rbenv install 2.3.0
~$ rbenv global 2.3.0
~$ ruby -v
~$ gem install bundler
~$ rbenv reshash

Here's a screenshot mid-process on my SurfaceBook. This build/install step takes a while and hits the disk a lot, FYI.

Installing rbenv on Windows under Ubuntu

At this point I've got Ruby, now I need Rails, as well as NodeJs for the Rails Asset Pipeline. You can change the versions as appropriate.

@ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -

$ sudo apt-get install -y nodejs
$ gem install rails -v 5.0.1

You will likely also want either PostgresSQL or MySQL or Mongo, or you can use a Cloud DB like Azure DocumentDB.

When you're developing on both Windows and Linux at the same time, you'll likely want to keep your code in one place or the other, not both. I use the automatic mount point that WSL creates at /mnt/c so for this sample I'm at /mnt/c/Users/scott/Desktop/RailsonAzure which maps to a folder on my Windows desktop. You can be anywhere, just be aware of your CR/LF settings and stay in one world.

I did a "rails new ." and got it running locally. Here you can se Visual Studio Code with Ruby Extensions and my project open next to Bash on Windows.

image

After I've got a Rails app running and I'm able to develop cleanly, jumping between Visual Studio Code on Windows and the Bash prompt within Ubuntu, I want to deploy the app to the web.

Since this is a simple "Hello World" default rails app I can't deploy it somewhere where the Rails Environment is Production. There's no Route in routes.rb (the Yay! You're on Rails message is development-time only) and there's no SECRET_KEY_BASE environment variable set which is used to verify signed cookies. I'll need to add those two things. I'll change routes.rb quickly to just use the default Welcome page for this demo, like this:

Rails.application.routes.draw do
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
    get '/' => "rails/welcome#index"
end

And I'll add the SECRET_KEY_BASE in as an App Setting/ENV var in the Azure portal when I make my backend, below.

Deploying Ruby on Rails App to Azure App Service on Linux

From the New menu in the Azure portal, choose to Web App on Linux (in preview as of the time I wrote this) from the Web + Mobile option. This will make an App Service Plan that has an App within it. There are a bunch of application stacks you can use here including node.js, PHP, .NET Core, and Ruby.

NOTE: A few glossary and definition points. Azure App Service is the Azure PaaS (Platform as a Service). You run Web Apps on Azure App Service. An Azure App Service Plan is the underlying Virtual Machine (sall, medium, large, etc.) that hosts n number of App Services/Web Sites. I have 20 App Services/Web Sites running under a App Service Plan with a Small VM. By default this is Windows by can run Php, Python, Node, .NET, etc. In this blog post I'm using an App Service Plan that runs Linux and hosts Docker containers. My Rails app will live inside that App Service and you can find the Dockerfiles and other info here https://github.com/Azure-App-Service/ruby or use your own Docker image.

Here you can see my Azure App Service that I'll now deploy to using Git. I could also FTP.

Ruby on Rails on Azure

I went into Deployment OPtions and setup a local (to Azure) git repro. Now I can see that under Overview.

image

On my local bash I add azure as a remote. This can be set up however your workflow is setup. In this case, Git is FTP for code.

$ git add remote azure https://scott@rubyonazureappservice.scm.azurewebsites.net:443/RubyOnAzureAppService.git

$ git add .
$ git commit -m "initial"
$ git push azure master

This starts the deployment as the code is pushed to Azure.

Azure deploying the Rails app

IMPORTANT: I will also add "RAILS_ENV= production" and a SECRET_KEY_BASE=to my Azure Application Settings. You can make a new secret with "rake secret."

If I'm having trouble I can turn on Application Logging, Web Server Logging, and Detailed Error Messages under Diagnostic Logs then FTP into the App Service and look at the logs.

FTPing into Azure to look at logs

This is all in Preview so you'll likely run into issues. They are updating the underlying systems very often. Some gotchas I hit:

  • Deploying/redeploying requires an explicit site restart, today. I hear that'll be fixed soon.
  • I had to dig log files out via FTP. They are going to expose logs in the portal.
  • I used the Kudu "sidecar" site at mysite.scm.azurewebsite.net to get shell access to the Kudu container, but I'd like to be able to ssh into or get to access to the actual running container from the Azure Portal one day.

That said, if you'd like more internal details on how this works, you can watch a session from Connect() last year with developer Nazim Lala. Thanks to James Christianson for his debugging help!


Sponsor: Did you know VSTS can integrate closely with Octopus Deploy? Watch Damian Brady and Brian A. Randell as they show you how to automate deployments from VSTS to Octopus Deploy, and demo the new VSTS Octopus Deploy dashboard widget. Watch now



© 2017 Scott Hanselman. All rights reserved.
     

Setting up a Shiny Development Environment within Linux on Windows 10

$
0
0

While I was getting Ruby on Rails to work nicely under Ubuntu on Windows 10 I took the opportunity to set up my *nix bash environment, which was largely using defaults. Yes, I know I can use zsh or fish or other shells. Yes, I know I can use emacs and screen, but I am using Vim and tmux. Fight me. Anyway, once my post was done, I starting messing around with open source .NET Core on Linux (it runs on Windows, Mac, and Linux, but here I'm running on Linux on Windows. #Inception) and tweeted a pic of my desktop.

By the way, I feel totally vindicated by all the interest in "text mode" given my 2004 blog post "Windows is completely missing the TextMode boat." ;)'

Also, for those of you who are DEEPLY NOT INTERESTED in the command line, that's cool. You can stop reading now. Totally OK. I also use Visual Studio AND Visual Studio Code. Sometimes I click and mouse and sometimes I tap and type. There is room for us all.

WHAT IS ALL THIS LINUX ON WINDOWS STUFF? Here's a FAQ on the Bash/Windows Subsystem for Linux/Ubuntu on Windows/Snowball in Hell and some detailed Release Notes. Yes, it's real, and it's spectacular. Can't read that much text? Here's a video I did on Ubuntu on Windows 10.

A number of people asked me how they could set up their WSL (Windows Subsystem for Linux) installs to be something like this, so here's what I did. Note that will I've been using *nix on and off for 20+ years, I am by no means an expert. I am, and have been, Permanently Intermediate in my skills. I do not dream in RegEx, and I am offended that others can bust out an awk script without googling.

C9RT5_bUwAALJ-H

So there's a few things going on in this screenshot.

  • Running .NET Core on Linux (on Windows 10)
  • Cool VIM theme with >256 colors
  • Norton Midnight Commander in the corner (thanks Miguel)
  • Desqview-esque tmux splitter (with mouse support)
  • Some hotkey remapping, git prompt, completion
  • Ubuntu Mono font
  • Nice directory colors (DIRCOLORS/LS_COLORS)

Let's break them down one at a time. And, again, your mileage may vary, no warranty express or implied, any of this may destroy your world, you read this on a blog. Linux is infinitely configurable and the only constant is that my configuration rocks and yours sucks. Until I see something in yours that I can steal.

Running .NET Core on Linux (on Windows 10)

Since Linux on Windows 10 is (today) Ubuntu, you can install .NET Core within it just like any Linux. Here's the Ubuntu instructions for .NET Core's SDK. You may have Ubuntu 14.04 or 16.04 (you can upgrade your Linux on Windows if you like). Make sure you know what you're running by doing a:

~ $ lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial
~ $

If you're not on 16.04 you can easily remove and reinstall the whole subsystem with these commands at cmd.exe (note the /full is serious and torches the Linux filesystem):

> lxrun /uninstall /full

> lxrun /install

Or if you want you can run this within bash (will take longer but maintain settings):

sudo do-release-upgrade

Know what Ubuntu your Windows 10 has when you install .NET Core within it. The other thing to remember is that now you have two .NET Cores, one Windows and one Ubuntu, on the same (kinda) machine. Since the file systems are separated it's not a big deal. I do my development work within Ubuntu on /mnt/d/github (which is a Windows drive). It's OK for the Linux subsystem to edit files in Linux or Windows, but don't "reach into" the Linux file system from Windows.

Cool Vim theme with >256 colors

That Vim theme is gruvbox and I installed it like this. Thanks to Rich Turner for turning me on to this theme.

$ cd ~/

$ mkdir .vim
$ cd .vim
$ mkdir colors
$ cd colors
$ curl -O https://raw.githubusercontent.com/morhetz/gruvbox/master/colors/gruvbox.vim
$ cd ~/
$ vim .vimrc

Paste the following (hit ‘i’ for insert and then right click/paste)

set number

syntax enable
set background=dark
colorscheme gruvbox
set mouse=a

if &term =~ '256color'
" disable Background Color Erase (BCE) so that color schemes
" render properly when inside 256-color tmux and GNU screen.
" see also http://snk.tuxfamily.org/log/vim-256color-bce.html
set t_ut=
endif

Then save and exit with Esc, :wq (write and quit). There's a ton of themes out there, so try some for yourself!

Norton Midnight Commander in the corner (thanks Miguel)

Midnight Commander is a wonderful Norton Commander clone that Miguel de Icaza started, that's licensed as part of GNU. I installed it via apt, as I would any Ubuntu software.

$ sudo apt-get install mc

There's mouse support within the Windows conhost (console host) that bash runs within, so you'll even get mouse support within Midnight Commander!

Midnight Commander

Great stuff.

Desqview-esque tmux splitter (with mouse support)

Tmux is a terminal multiplexer. It's a text-mode windowing environment within which you can run multiple programs. Even better, you can "detach" from a running session and reattached from elsewhere. Because of this, folks love using tmux on servers where they can ssh in, set up an environment, detach, and reattach from elsewhere.

NOTE: The Windows Subsystem for Linux shuts down all background processes when the last console exits. So you can detach and attach tmux sessions happily, but just make sure you don't close every console on your machine.

Here's a nice animated gif of me moving the splitter on tmux on Windows. YES I KNOW YOU CAN USE THE KEYBOARD BUT THIS GIF IS COOL.

Some hotkey remapping, git prompt, completion

I am still learning tmux but here's my .tmux.conf. I've made a few common changes to make the hotkey creation of windows easier.

#remap prefix from 'C-b' to 'C-a'

unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

# split panes using | and -
bind | split-window -h
bind _ split-window -v
unbind '"'
unbind %
bind k confirm kill-window
bind K confirm kill-server
bind < resize-pane -L 1
bind > resize-pane -R 1
bind - resize-pane -D 1
bind + resize-pane -U 1
bind r source-file ~/.tmux.conf

# switch panes using Alt-arrow without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# Enable mouse control (clickable windows, panes, resizable panes)
set -g mouse on
set -g default-terminal "screen-256color"

I'm using the default Ubuntu .bashrc that includes a check for dircolors (more on this below) but I added this for git-completion.sh and a git prompt, as well as these two alias. I like being able to type "desktop" to jump to my Windows Desktop. And the -x on Midnight Commander helps the mouse support.

alias desktop="cd /mnt/c/Users/scott/Desktop"

alias mc="mc -x"
export CLICOLOR=1
source ~/.git-completion.sh
PS1='\[\033[37m\]\W\[\033[0m\]$(__git_ps1 " (\[\033[35m\]%s\[\033[0m\])") \$ '
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM="auto"

Git Completion can be installed with:

sudo apt-get install git bash-completion

Ubuntu Mono font

I really like the Ubuntu Mono font, and I like the way it looks when running Ubuntu under Windows. You can download the Ubuntu Font Family free.

Ubuntu Mono

Nice directory colors (DIRCOLORS/LS_COLORS)'

If you have a black command prompt background, then default colors for directories will be dark blue on black, which sucks. Fortunately you can get .dircolors files from all over the wep, or set the LS_COLORS (make sure to search for LS_COLORS for Linux, not the other, different LSCOLORS on Mac) environment variable.

I ended up with "dircolors-solarized" from here, downloaded it with wget or curl and put it in ~. Then confirm this is in your .bashrc (it likely is already)

# enable color support of ls and also add handy aliases

if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi

Make a big difference for me, and as I mention, it's totally, gloriously, maddeningly configurable.

Nice dircolors

Leave YOUR Linux on Windows tips in the comments!


Sponsor: Did you know VSTS can integrate closely with Octopus Deploy? Watch Damian Brady and Brian A. Randell as they show you how to automate deployments from VSTS to Octopus Deploy, and demo the new VSTS Octopus Deploy dashboard widget. Watch now


© 2017 Scott Hanselman. All rights reserved.
     

ASP.NET - Overposting/Mass Assignment Model Binding Security

$
0
0

imageThis little post is just a reminder that while Model Binding in ASP.NET is very cool, you should be aware of the properties (and semantics of those properties) that your object has, and whether or not your HTML form includes all your properties, or omits some.

OK, that's a complex - and perhaps poorly written - sentence. Let me back up.

Let's say you have this horrible class. Relax, yes, it's horrible. It's an example. It'll make sense in a moment.

public class Person

{
public int ID { get; set; }
public string First { get; set; }
public string Last { get; set; }
public bool IsAdmin { get; set; }
}

Then you've got an HTML Form in your view that lets folks create a Person. That form has text boxes/fields for First, and Last. ID is handled by the database on creation, and IsAdmin is a property that the user doesn't need to know about. Whatever. It's secret and internal. It could be Comment.IsApproved or Product.Discount. You get the idea.

Then you have a PeopleController that takes in a Person via a POST:

[HttpPost]

[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Person person)
{
if (ModelState.IsValid)
{
_context.Add(person);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(person);
}

If a theoretical EvilUser found out that Person had an "IsAdmin" property, they could "overpost" and add a field to the HTTP POST and set IsAdmin=true. There's nothing in the code here to prevent that. ModelBinding makes your code simpler by handling the "left side -> right side" boring code of the past. That was all that code where you did myObject.Prop = Request.Form["something"]. You had lines and lines of code digging around in the QueryString or Form POST.

Model Binding gets rid of that and looks at the properties of the object and lines them up with HTTP Form POST name/value pairs of the same names.

NOTE: Just a friendly reminder that none of this "magic" is magic or is secret. You can even write your own custom model binders if you like.

The point here is that folks need to be aware of the layers of abstraction when you use them. Yes, it's convenient, but it's hiding something from you, so you should know the side effects.

How do we fix the problem? Well, a few ways. You can mark the property as [ReadOnly]. More commonly, you can use a BindAttribute on the method parameters and just include (whitelist) the properties you want to allow for binding:

public async Task<IActionResult> Create([Bind("First,Last")] Person person)

Or, the correct answer. Don't let models that look like this get anywhere near the user. This is the case for ViewModels. Make a model that looks like the View. Then do the work. You can make the work easier with something like AutoMapper.

Some folks find ViewModels to be too cumbersome for basic stuff. That's valid. There are those that are "All ViewModels All The Time," but I'm more practical. Use what works, use what's appropriate, but know what's happening underneath so you don't get some scriptkiddie overposting to your app and a bit getting flipped in your Model as a side effect.

Use ViewModels when possible or reasonable, and when not, always whitelist your binding if the model doesn't line up one to one (1:1) with your HTML Form.

What are your thoughts?


Sponsor: Check out JetBrains Rider: a new cross-platform .NET IDE. Edit, refactor, test, build and debug ASP.NET, .NET Framework, .NET Core, or Unity applications. Learn more and get access to early builds!



© 2017 Scott Hanselman. All rights reserved.
     

Penny Pinching in the Cloud: Lift and Shift vs App Services - When a VM in the Cloud isn't what you want

$
0
0

I got an interesting question today. This is actually an extremely common one so I thought I'd take a bit to explore it. It's worth noting that I don't know the result of this blog post. That is, I don't know if I'll be right or not, and I'm not going to edit it. Let's see how this goes!

The individual emailed and said they were new to Azure and said:

Question for you.  (and we may have made a mistake – some opinions and help needed)
A month or so ago, we setup a full up Win2016 server on Azure, with the idea that it would host a SQL server as well two IIS web sites

Long story short, they were mired in the setup of IIS on Win2k6, messing with ports, yada yada yada. '

All they wanted was:

  • The ability to right-click publish from Visual Studio for two sites.
  • Management of a SQL Database from SQL Management Studio.

This is a classic "lift and shift" story. Someone has a VM locally or under their desk or in hosting, so they figure they'll move it to the cloud. They LIFT the site as a Virtual Machine and SHIFT it to the cloud.

For many, this is a totally reasonable and logical thing to do. If you did this and things work for you, fab, and congrats. However, if, at this point, you're finding the whole "Cloud" thing to be underwhelming, it's likely because you're not really using the cloud, you've just moved a VM into a giant host. You still have to feed and water the VM and deal with its incessant needs. This is likely NOT what you wanted to do. You just want your app running.

Making a VM to do Everything

If I go into Azure and make a new Virtual Machine (Linux or Windows) it's important to remember that I'm now responsible for giving that VM a loving home and a place to poop. Just making sure you're still reading.

NOTE: If you're making a Windows VM and you already have a Windows license you can save like 40%, so be aware of that, but I'll assume they didn't have a license.

You can check out the Pricing Calculator if you like, but I'll just go and actually setup the VM and see what the Azure Portal says. Note that it's going to need to be beefy enough for two websites AND a SQL Server, per the requirements from before.

Pricing for VMs in Azure

For a SQL Server and two sites I might want the second or third choice here, which isn't too bad given they have SSDs and lots of RAM. But again, you're responsible for them. Not to mention you have ONE VM so your web server and SQL Server Database are living on that one machine. Anything fails and it's over. You're also possibly giving up perf as you're sharing resources.

App Service Plans with Web Sites/Apps and SQL Azure Server

An "App Service Plan" on Azure is a fancy word for "A VM you don't need to worry about." You can host as many Web Apps, Mobile Apps/Backends, Logic Apps and stuff in one as you like, barring perf or memory issues. I have between 19 and 20 small websites in one Small App Service Plan. So, to be clear, you put n number of App Services as you'd like into one App Service Plan.

When you check out the pricing tier for an App Service Plan, be sure to View All and really explore and think about your options. Some includes support for custom domains and SSL, others have 50 backups a day, or support BizTalk Services, etc. They start at Free, go to Shared, and then Basic, Standard, etc. Best part is that you can scale these up and down. If I go from a Small to a Medium App Service Plan, every App on the Plan gets better.

However, we don't need a SQL Server, remember? This is going to be a plan that we'll use to host those two websites. AND we can use the the same App Service Plan for staging slots (dev/test/staging/production) if we like. So just get the plan that works for your sites, today. Unlike a VM, you can change it whenever.

App Service Plan pricing

SQL Server on Azure is similar. You make a SQL Server Database that is hosted on a SQL Server that supports the number of Database Throughput Units that I need. Again, because it's the capital-C Cloud, I can change the size anytime. I can even script it and turn it up and down on the weekends. Whatever saves me money!

SQL Azure Pricing

I can scale the SQL Server from $5 to a month to bajillions and everything in between.

What the difference here?

First, we started here

  • VM in the Cloud: At the start we had "A VM in the Cloud." I have total control over the Virtual Machine, which is good, but I have total control over the Virtual Machine, which is bad. I can scale up or out, but just as one Unit, unless I split things up into three VMs.

Now we've got.

  • IIS/Web Server in the Cloud: I don't have to think about the underlying OS or keeping it patched. I can use Linux or Windows if I like, and I can run PHP, Ruby, Java, .NET, and on and on in an Azure App Service. I can put lots of sites in one Plan but the IIS publishing endpoint for Visual Studio is automatically configured. I can also use Git for deployment as well
  • SQL Server in the Cloud: The SQL Server is managed, backed up, and independently scalable.

This is a slightly more "cloudy" of doing things. It's not microservices and independently scalable containers, but it does give you:

  • Independently scalable tiers (pricing and CPU and Memory and disk)
  • Lots of automatic benefits - backups, custom domains, ssl certs, git deploy, App Service Extensions, and on and on. Dozens of features.
  • Control over pricing that is scriptable. You could write scripts to really pinch pennies by scaling your units up and down based on time of day or month.

What are your thoughts on Lift and Shift to IaaS (Infrastructure as a Service) vs using PaaS (Platform as a Service)? What did I forget? (I'm sure lots!)


Sponsor: Check out JetBrains Rider: a new cross-platform .NET IDE. Edit, refactor, test, build and debug ASP.NET, .NET Framework, .NET Core, or Unity applications. Learn more and get access to early builds!



© 2017 Scott Hanselman. All rights reserved.
     

Audit and Optimize your Windows 10 Search Indexing Options

$
0
0

I was getting frustrated with the speed (or lack of) of Windows Search within Windows 10 lately. I went over to my Indexing Options - just hit Start and type Indexing Options - and was surprised to see that there was over 1.5 MILLLION items indexed! That seems like a big number. Why so large?

I checked my "index these locations" list and didn't see anything weird, but I did note that Indexing does include c:\users\YOURNAME by default. That seems reasonable, because it is reasonable.

However, I also noted that I had a LOT of ".folders" (dot folders) under my C:\users\YOURNAME folder adding up to a few gigs of config text files, caches and general crap.

I was able to significantly lower the number of items indexed from over a million to a reasonable 215k items just by excluding (un-checking) folders that I knew didn't matter to me as much.

Go to Indexing Options and click Modify:

Indexing Options

Go to your C drive (or wherever ~\YOURNAME is) and go to your top level User folder. I unchecked a bunch of the stuff that didn't matter to me.

Indexing Location

For average users this won't matter, but for developers who install a bunch of utilities, have their Dropbox or OneDrive in the c:\users folder, a 5 min audit of your indexed files can give your Indexed Files a nice refresh.


Sponsor: Check out JetBrains Rider: a new cross-platform .NET IDE. Edit, refactor, test, build and debug ASP.NET, .NET Framework, .NET Core, or Unity applications. Learn more and get access to early builds!


© 2017 Scott Hanselman. All rights reserved.
     

Managing dotnet Core 2.0 and dotnet Core 1.x versioned SDKs on the same machine

$
0
0

Tons of great announcements this week at the BUILD conference. I'll slowly blog my take on some of the cooler features, but for now here's a rollup of the major blog posts for developers:

You can download and get started with .NET Core 2.0 Preview 1 right now, on Windows, Linux and macOS:

If you already have .NET Core on your machine, you'll already be able to type "dotnet --version" at the terminal or command line. Go ahead and try it now. Mine says:

C:\Users\scott> dotnet --version

2.0.0-preview1-005977

Remember on Windows you can check out c:\program files\dotnet\sdk and see all the SDK versions you have installed:

Lots of .NET Core versions

Typing dotnet will pick the most recent one...but it's smarter than that. Remember that you can set the current SDK version with a global.json file. Global.json's presence will override from the folder its in, all the way down.

If I make a folder on my desktop and put this global.json in it:

{

"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.3"
}
}

It will force my dotnet runner to use the .NET Core SDK version I asked for. That "projects" line isn't needed for the versioning, but it's nice to be able to select what folders have projects inside.

C:\Users\scott\Desktop\test> dir

Directory of C:\Users\scott\Desktop\test
05/11/2017 09:22 PM <DIR> .
05/11/2017 09:22 PM <DIR> ..
05/11/2017 09:23 PM 45 global.json
1 File(s) 45 bytes
2 Dir(s) 85,222,268,928 bytes free

C:\Users\scott\Desktop\test> dotnet --version
1.0.3

At this point - with a valid global.json - making a new project with dotnet new will make an app with a netcoreapp1.x version. If I move elsewhere and dotnet new I'll get a netcoreapp2.0. In this example, it's the pretense of that global.json that "pins" my SDK version.

Alternatively, I could keep the dotnet.exe 2.0 SDK and install 1.x templates. This would mean I could create whatever I want AND pass in the version.

First I'll add the 1.x templates into my 2.0 SDK. This just needs to happen once.

dotnet new -i Microsoft.DotNet.Common.ProjectTemplates.1.x::1.0.0-*

Now, even though I'm "driving" things with a .NET Core 2.0 SDK, I can pass in --framework to control the project that gets created!

C:\Users\scott\Desktop\test> dotnet new console -o oneone --framework netcoreapp1.1

The template "Console Application" was created successfully.

C:\Users\scott\Desktop\test> dotnet new console -o twooh --framework netcoreapp2.0
The template "Console Application" was created successfully.

I can make libraries that target .NET Standard like this, passing in 2.0 or 1.6, or whatever netstandard I need.

C:\Users\scott\Desktop\lib> dotnet new classlib --framework netstandard2.0

The template "Class library" was created successfully.

There's two options that are not exactly opposites, but they'll give you different levels of control, depending on your needs.

  • You can control your SDK versioning folder by folder with global.json. That means your project's directories are "pinned" and know what SDK they want.
    • When you type dotnet new using a pinned SDK, you'll get the new project results for that pinned SDK. Typing dotnet run will do the right thing.
  • You can pass in --framework for templates that support it and dotnet new will create a template with the right runtime version. Typing dotnet run will do the right thing.

This is .NET Core 2.0 Preview 1, but you should be able to install it side by side with your existing apps and have no issues. If you know these few internal details, you should be able to manage multiple apps with multiple versions without much trouble.


Sponsor: Test your application against full-sized database copies. SQL Clone allows you to create database copies in seconds using MB of storage. Create clones instantly and test your application as you develop.



© 2017 Scott Hanselman. All rights reserved.
     
Viewing all 1148 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>