Scott Hanselman

Tiny top-level programs with C# 9 and SmallSharp and Visual Studio

February 09, 2021 Comment on this post [7] Posted in DotNetCore | Open Source | VS2019
Sponsored By

One of the things I'm always working on and am always excited about is making C# simpler for new folks.

With .NET 5, today, this works, as it includes C# 9

> dotnet new console
The template "Console Application" was created successfully

> echo System.Console.WriteLine("Hello World"); > program.cs

> dotnet run
Hello World

That's C# 9 top level programs. We should be able to remove even more. Skip the first command completely and do it all on one line, one file.

A hello world is either

using System;

Console.WriteLine("Hello World!");

or

System.Console.WriteLine("Hello World!");

or, scandalously

using System;
using static System.Console;

WriteLine("Hello World!");

Not sure how I feel about that last one. Regardless...would this work in Visual Studio 2019? What if I was teaching a class and wanted to have one file per homework assignment, for example? Right now Visual Studio only supports one top-level program per project. Make sense why, but for learning, why not allow folks to choose from the run/debug menu?

I'm going to add a reference to SmallSharp like this (or in Visual Studio)

> dotnet add package smallsharp

Now here's what my homework looks like in Visual Studio 2019! There's one menu item per top level program!

One menu item per top level program

This lovely prototype was done by Daniel Cazzulino (kzu) and you can learn more at https://github.com/devlooped/SmallSharp, or just try it out as I have here!

What do you think? How can small top-level programs help new people?

What about this?

> dotnet new microservice
> dotnet run

Sound off in the comments. How tight and simple would that be?


Sponsor: Tired of not finding the code you're looking for? Get Sourcegraph universal code search and search code across ALL your repos, languages, and code hosts. Find and fix code fast with Sourcegraph. Try it now!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Get on the Windows Terminal PREVIEW train - now with Settings UI

January 28, 2021 Comment on this post [0] Posted in Tools
Sponsored By

Turns out you can install both the Windows Terminal AND the Windows Terminal Preview side by side! This will let you try out all the upcoming features in this "skip next" version. You can grab the next version of the Windows Terminal at https://aka.ms/terminal-preview now.

The two Terminals can be pinned side by side if you like. Here you can see the Preview Terminal has a "Pre" badge in the taskbar.

Windows Terminal rocks

Historically you've had to edit a settings.json file - usually with Visual Studio Code and it's lovely json schema support, natch - but as of Windows Terminal 1.6, you've got a preview of the long-awaited Settings UI.

Get the Terminal 1.6 Preview, press Ctrl+, to get your settings.json, then paste this down by the actions array at the bottom:

{ "command": { "action": "openSettings", "target": "settingsUI" }, "keys": "ctrl+shift+," },

That'll make Ctrl+Shift+, bring up the new Settings UI!

Here is just one section! I thought I know all the settings but there's a TON I missed. You'll also notice all my Profiles on the left PLUS a Base Layer for inheritance. I was pleased to see the Grayscale vs ClearType (subpixel rgb anti-aliasing) choice, as well as some of the more obscure cursor options.

Windows Terminal Settings UI

A real color schema editor is also overdue, so it was awesome to see that as well.

Color schemes

You can, of course, hop between JSON the UI. Here's the UbuntuLegit (from Kayla!) color schema as a UI, above, and as JSON, below.

{
"background": "#2C001E",
"black": "#75F50A",
"blue": "#3465A4",
"brightBlack": "#555753",
"brightBlue": "#729FCF",
"brightCyan": "#34E2E2",
"brightGreen": "#8AE234",
"brightPurple": "#AD7FA8",
"brightRed": "#EF2929",
"brightWhite": "#EEEEEE",
"brightYellow": "#FCE94F",
"cursorColor": "#FFFFFF",
"cyan": "#06989A",
"foreground": "#EEEEEE",
"green": "#300A24",
"name": "UbuntuLegit",
"purple": "#75507B",
"red": "#CC0000",
"selectionBackground": "#FFFFFF",
"white": "#D3D7CF",
"yellow": "#C4A000"
},

I've been using Windows Terminal Preview as my primary lately, even over the "more stable" released version. Fortunately I can run both, but the Preview is my go-to right now.

Related Links


Sponsor: Protect your apps from reverse engineering and tampering with PreEmptive, the makers of Dotfuscator. Dotfuscator has been in-the-box with Microsoft Visual Studio since 2003. Visit preemptive.com/hanselminutes for a professional-grade trial.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Hack a TV into a Teams and Zoom Computer with EpocCam and Miracast

January 26, 2021 Comment on this post [12] Posted in Remote Work
Sponsored By

If you have a TV, you can turn it into a fancy conference room monitor and pretend you have a Surface Hub 2S. Let's see the different ways we can make Teams/Zoom meetings more a "walking around and thinking" experience, and less a "hunched in front of the laptop" experience.

Cheapest/Good - Wire up to a big TV

You can just get a nice HDMI cable and plug it into your TV and duplicate or extend your laptop's screen. In this simple scenario you're using your Laptop's mic and webcam, and just using the screen of your TV. You can also check your audio output and use the TV speakers as output if you like.

Doing this is not just a nice change of pace, but it reminds you of the options you have to hold meetings! It's your space...how many ways can you change your boring meeting into a new perspective by using the same space in a new way?

Cheap/Better - Wireless to a big TV

If you want to be wireless, you can use Miracast (if your computer/laptop/Surface supports it) or AirPlay or AirServer to "throw" your screen wirelessly to your TV. Some Samsung Smart TV support wireless communications built-in!

  • You may be able to throw from Windows to a Smart TV with AirServer software. You may be able to throw with AirPlay on your Mac to an Apple TV.
  • You may be able to get a Miracast HDMI dongle (amzn link) and make a dumb TV smart. This is the solution I use. I throw my Surface screen over Miracast to the TV.

Less Cheap/Best (for me) - Wireless to a big TV with a wireless Webcam via my iPhone

I have a TV on my wall in my office, but it doesn't lend itself to wires and moving my laptop. I wanted to throw the screen over there AND also have a webcam on top of the TV. Ideally there'd be a webcam in the bezel of the TV, but there isn't.

What's an ideal and cheap webcam? My iPhone is already a great device with a long life battery, it's portable, and a webcam. You can get a number of apps that will enable you to use your iPhone (or Android) as a webcam.

I decided on Elgato EpocCom to turn my iPhone into a webcam.

Troubleshooting: The docs aren't amazing, so you'll want to not only install the software, but confirm that the EpocCamService is enabled in the Windows Firewall for both Private AND Public Networks (or ensure your network is the same type as the type that's enabled for this service.) I had to manually allow the EpocCam Service to work on Private Networks.

Then you'll get the iPhone side of the app and your iPhone will show up as a camera. With the Pro version ($7.99) you'll get higher quality and microphone support.

Now I just put my iPhone on the top of the TV, run the EpocCam software, and then on my PC I throw my video to the TV and select the EpocCam virtual Camera. Now I can wander around my office and pace and talk and think, which is great!

Here I've got my Samsung Frame TV (amzn link) (I got it for just $600 as it's the 2018 model, I love it) and I've hooked up the Microsoft Wireless Display Adapter v2 (amzn link).

Using an iPhone as a Teams Camera

Other Alternatives

Once you familiarize yourself with these wireless options for throwing video and audio around, you'll find there is no right answer. There's only the answer that works for you! The results will be similar, but some of the solutions will fit better into your system or setup.

Here's some other ideas.

  • Use NDI Tools to throw formally throw video around your office and catch it with OBS or XSplit
  • Use a really long USB extension code and mount a cheap webcam on the top of the TV
  • Just use your iPhone or iPad or Android device and join Teams or Zoom with the phone itself! Then either wired (via adapter and HDMI) or wirelessly connect the device to your TV!

Leave your solutions in the comments!

There also appear to be Teams devices that will take a TV or Display and Teamsify it! I'll go educate myself about those as well!


Sponsor: Protect your apps from reverse engineering and tampering with PreEmptive, the makers of Dotfuscator. Dotfuscator has been in-the-box with Microsoft Visual Studio since 2003. Visit preemptive.com/hanselminutes for a professional-grade trial.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Using Tailscale on Windows to network more easily with WSL2 and Visual Studio Code

January 21, 2021 Comment on this post [3] Posted in Linux | Open Source | Win10
Sponsored By

Tailscale is a zero config mesh "VPN" that runs atop other networks and effectively "flattens" networks and allows users/services to more easily (and securely) communicate with each other.

For example, I've written extensively on how to SSH into WSL2 on Windows 10 from another machine and you'll note that there is not only a ton of steps but there's more than one way to do it!

I have talked about this for SSH, but if you're an active developer and want to share the services and sites you're working on with your coworkers and collaborators, there's a non-trivial amount of setup, management, and maintenance to deal with.

Phrased differently, "wouldn't it be easier if we were all just on the same network and subnet?"

WSL1 shares its networking stack with Windows 10, so the "machine" is the same. Whatever YourMachineName is, running a service on 5000 is the same if it's a Windows service or an app running in Linux under WSL1. However, in WSL2, your Linux environment is "behind" your Windows host. While WSL2 makes it easy to hit http://localhost:5000 by transparent port-forwarding, your WSL2 Linux machine isn't really a peer on the same network as your other devices.

Using a zero-configuration networking system like Tailscale (and similar services) levels the playing field - and the network. Due to some characteristics of WSL2 there are a few gotchas. Here's how I got it working for me.

Tailscale on WSL2

Get WSL

Get Tailscale

Modify WSL2

  • I can't get Tailscale today to startup on WSL2 with ipv6 install, so I disable it.
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1

Run Tailscale

Here you startup the daemon. There's no systemd (yet) on WSL2, but if you're on a version over Windows 10 build 21286, there are ways run commands on startup in the Windows Subsystem for Linux. Personally, I just do this in a bash script.

sudo tailscaled 

WSL doesn't have a way to do an interactive login process, so you wan tot create a pre-authentication key to authenticate a single machine. Then use that key, as I do here, to bring up Tailscale within WSL:

tailscale up --authkey=tskey-9e85d94f237c54253cf0

I like to keep this open in another Terminal Tab or Window Pane so I can watch the logs. It's interesting and verbose!

Within the Tailscale machines admin panel, you can see all the machines living on your new Tailscale network. Note that I have scottha-proto listed as Windows, and scottha-proto-1 listed as Linux. The first is my Host machine and the second (the -1) is my Linux WSL2 instance! They are now on a flat network! 

A list of all my Tailscale machines

I was also able to invite a user from outside my network with the new (coming soon) Tailscale node sharing feature. My friend Glenn is NOT in my organization, but just like I use OneDrive or DropBox to create a link to access ONE entity but not the WHOLE system, I can do the same here.

Shared my node with someone outside my network

Now I can have Glenn hit a service running in WSL2 from his house.

Make a Service and Bind it to the Tailscale Network

I've installed .NET 5 in my WSL2 Ubuntu system, made a folder, and run dotnet new web to make a Hello World microservice.

When I run the service - .NET or Node, or whatever - it essential that the service listen on the Tailscale network. Your Linux system in WSL2 is 'multi-homed' and is connected to multiple networks. By default my developer systems listen only on localhost.

For .NET there's several ways to listen on all networks (including Tailscale) but I used this one:

dotnet run --urls http://*:5100;https://*:5101

So here I've got myself connecting to the Tailscale IP that's associated with my WSL2 instance and hitting my Linux service running within:

Image

How far can we take this? Well, since I'm on the Tailscale network and Glenn has connected to it, the whole network is flat, so hitting my service is trivial! Here I am on Teams with my desktop on the bottom and Glenn's desktop on the top.

My service in WSL2 being hit my Glenn from a remote system

Cool. How far can we go?

Add Visual Studio Code and the Remote Development SSH Extension

Ok, so flat secure network, no limits! Can I make my WSL2 instance be treated as a remote development system for Glenn? Sure, why not?

To be clear - this is just me talking and experimenting, but there's something here. This can also be cross platform, Mac to Windows to WSL2, etc. You can also certainly use this section to create a VM in any cloud host or hoster, install Tailscale, stop worrying about port forwarding, and use it as a development box. Yes, you can just use WSL local, but this is fun and can be exploited in other cool ways.

On my WSL2 machine, I'll start up the ssh service. I could share public keys and do proper key-based login, but for this I'll do it by username.

I'll edit /etc/ssh/sshd_config and set the port, ListenAddress, and PasswordAuthentication to Yes. Here's an example:

Port 22
#AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::

PasswordAuthentication yes

I made glenn a local super user just in my WSL2 instance:

sudo adduser glenn
usermoid -aG sudo glenn

Glenn then installs the VS Code Remote Development pack and connects using Remote via SSH to my Tailscale IP. Here you can see VS Code from Glenn's machine is actually installing the VS Code Server and remote developers, and Glenn and code with VS Code architecturally split in half with the client on his Windows machine and the server on my WSL2 instance.

Note in the lower left corner, you can see his VS Code is connected to my WSL2 Linux instance's Tailscale IP!

Connected to Tailscale with VS Code

What do you think?

You may compare Tailscale to things like NGrok which offers a developer-oriented localhost tunneller, but there are some important differences. Do your research! I have no relationship with this company other than I'm a fan.


Sponsor: This week's sponsor is...me! This blog and my podcast has been a labor of love for 19 years. Your sponsorship pays my hosting bills for both AND allows me to buy gadgets to review AND the occasional taco. Join me!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Exploring my creativity through TikTok and YouTube technical education videos

January 15, 2021 Comment on this post [4] Posted in Musings
Sponsored By

Last year kind sucked, and the end of last year was particularly lame. I got off Twitter for a while and discovered TikTok. I went there as a creative outlet. If you choose to sign up you may get inundated with a bunch of stuff that makes no sense or has no relevance. However, within just a few days by searching for an “liking” topics that I wanted to hear about, I found a wonderful, joyful, diverse TikTok and have learned about everything from Sea Shanties to Indigenous Dances to Woodworking. It’s a lovely little community and I’ve enjoyed my week on it.

I've been trying out video lately, during these trying times, and have very much enjoyed both TikTok and YouTube as creative outlets. I sent out some of my favorite TikTok videos in my occasional newsletter this week.

Here’s some highlights of lovely things on TikTok I’ve found:

I also recently hit 100,000 subscribers on YouTube which is fun. Apparently they are sending me a plaque, so more on that soon. My most recent video is here What happens when you type a URL in the browser and press enter? I encourage you to go subscribe. You can get to my main playlist with the alias http://www.computerstufftheydidntteachyou.com

What kinds of creative outlets have you been exploring (to stay sane or otherwise) last year, and what are your plans for this year?


Sponsor: Looking for free secure coding training but don’t know where to turn? Check out Veracode Security Labs Community Edition to start hacking and patching real apps online. Try it today.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.