B10759

https://www.packtpub.com/application-development/hands-typescript-c-and-net-core-developers

Written by Francesco Abbruzzese and published by Packt publishing, this book has the subtitle 'Transition from C# to TypeScript 3.1 and build applications with ASP.NET Core 2'. Although the content has a risk of going out of date quick, the core concepts and programming idioms and structures explored in this book will still be relevant.

The first few chapters give a pretty good in-depth introduction to TypeScript language and introduces such things as classes and interfaces which some JavaScript developers may not be familiar with, but C# developers certainly would. After covering topics such as complex types and generics, the author shows us how patterns like the module pattern can be used to better organise your code. There are chapters on advanced ES6 such as iterators, generators, decorators and metadata. Later chapters cover technology specific subjects such as WebPack, which can be used to modularise and minify the resulting JavaScript code for better management as well as it's integration with ASP.Net Core. Angular also gets its own chapters which is fine, but with the advance of other frameworks such as React and Vue, this section could find itself skimmed over. There is a chapter dedicated to building TypeScript libraries which also includes sections on testing with Jasmine and packaging for NPM.

Code Samples

By accessing the website, you can download all the chapter code samples which is great to get up and running quickly if you want to copy samples into your project and great also if you want to follow along with what is being discussed in the book chapter.

Book Website

If you register on the Packt website at www.packtpub.com, you get access to all the code samples as a download and can read the book in the browser. One of the things I like about the website is its dark mode which makes it much easier on the eyes when reading at night. Also, as this is very much a hands-on book for practical use, you can copy and paste code samples into your own projects with ease. If you find learning code is easier when watching somebody else do it, there are also YouTube videos for each chapter that covers the main elements of the chapter. These videos are good to watch however, they do not have any sound so don't expect anybody to explain what is going on.

Conclusion

Personally, it is not often I purchase a book, with the preference to find what I want when I want and use tools such as Pluralsight and Stack Overflow as well as Microsoft Docs. However sometimes it is good to go through a more structured approach like what you would reading a university textbook. So, this book is very good and well written using language that although technical does not fill the pages with superfluous words but instead gets right to the nitty gritty which is exactly what you need in these time strapped days. With the bonus of the website, this book and many others from Packt are definitely worth the time.

Happy coding.

Wow what a title, but it does explain that this post covers debugging the full .net framework application (not .net core) running on a Server Core container (not Linux) from the comfort of a Windows 10 Pro machine running Visual Studio 2015 and Docker for Windows.

Running remote tools on a machine and attaching is a pretty straight forward task, but there a re a few hurdles in the way when doing it on Windows Server Core 2016 container, but once it is scripted it is pretty painless.

Firstly we need a decent Docker image to start with, luckily the guys at Microsoft have created the Microsoft/aspnet image we can start with so lets build up our dockerfile

FROM microsoft/aspnet
RUN mkdir C:\site

This gets the base image and creates directory that we are going to use for our web files.

RUN powershell -NoProfile -Command \
    Import-module IISAdministration; \
    New-IISSite -Name "Site" -PhysicalPath C:\site -BindingInformation "*:8000:

This creates the web application in IIS and binds it to port 8000 and our path to the web files.

RUN powershell -NoProfile -Command \
    Install-WindowsFeature -Name Web-Mgmt-Service

RUN powershell -NoProfile -Command \
    New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force

RUN powershell -NoProfile -Command \
    Get-Service -Name WMSVC

RUN powershell -NoProfile -Command \
    Set-Service WMSVC -startuptype "Automatic"
   
RUN powershell -NoProfile -Command \
    Start-Service -Name WMSVC

RUN powershell -NoProfile -Command \
    net user iisadmin P2ssw0rd /add

RUN powershell -NoProfile -Command \
    net localgroup administrators iisadmin /add

This section is completely optional and all it does is install the web management tools for remote administration. You may want to tweak the container settings such as application pool and start and stop it from the GUI on your Windows 10 machine. If you are not bothered about IIS settings, then you can omit this section.

RUN powershell -NoProfile -Command \
$acl = Get-Acl -Path "C:\inetpub\wwwroot";Set-Acl -Path "C:\site" -AclObject $acl;

This copies the directory permissions set up for the wwwroot directory and assigns it to the site directory, so we don’t end up with nasty permission denied issues.

EXPOSE 8000 8172 4020 4021

We need to expose 8000 for our web application, 8172 for remote IIS admin and 4020 and 4021 are the ports we need opening for remote debugging tools. Visual Studio 2015 remote tools use these ports, other versions use different ports and as yet I cannot find the ports for Visual Studio 2017.

Next we locate our dockerfile using a cmd prompt and run docker build

docker build -t iis-site .

It will take a while to run through and will be quicker in future builds as you will already have the layers that make up the final image.

Now we have our image, lets run with it:-

docker run -d -p 94:94 -v "C:\Users\username\Documents\Visual Studio 2015\Projects\WebApplication4\WebApplication4":c:\site --name web1 iis-site

This creates a container based on our previous iis-site image and creates a mapping to a directory on our Windows 10 machine to the site directory we created in the dockerfile; this container will have the name web1.

Lets test this by finding the ip address:-

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" web1

This gives me 172.19.184.110 and yours will be different as each container gets its own address. We know we are on port 8000 so open up a browser and browse to your home page:-

image

Great, now lets get debugging. In future releases of Visual Studio 2017 it will be possible to debug straight into a Windows container, but at the moment it is limited to Linux containers, so we need to do a bit more configuration.

We need to install the Remote Tools for Visual Studio 2015 so go here and download it.

Once downloaded, put the .exe in the same directory as your web application on your machine as that is already visible to the container. There are ways to automate the download using Invoke-WebRequest, but I had several issues with resolving the url so it was easier to do it myself.

Create a .bat file with the following and copy that also into the web application directory on your machine:-

rtools_setup_x64.exe /install /quiet

Get the id of the container by using the command:-

docker ps

With the id, lets open an interactive cmd prompt:-

docker exec -it 03a8eb766d5a cmd

Where 03a8eb766d5a is my container identifier.

Run the bat file:-

install-tools.bat

This will take a couple of minutes to run through, but when it is finished you can cd to the C:\Program Files\Microsoft Visual Studio 14.0\Remote Tools directory to take a look.

Exit out of the interactive session and get back to docker and run:-

docker exec -it 03a8eb766d5a "C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger\x64\msvsmon.exe" /nostatus /silent /noauth /anyuser /nosecuritywarn

This will start the remote debugging service msvsmon and your cmd prompt will just sit quiet with no cursor.

So now open up the web application in Visual Studio and go to Debug >> Attach to process

debug-1

Click on the Find button and it should find your container with its id and ip address showing, simply select it.

debug-2

debug-3

Now we need to make sure we choose Managed (v4.6, v4.5, v4.0) code or whatever version of the framework you are using. Also make sure show processes from all users is checked.

Scroll down and choose w3wp and attach. Check the security warning and then start debugging as you would normally do.

debug-4

Ideally it would be best if the remote tools could be downloaded as part of the build and the starting of msvsmon be automatic when F5 in Visual Studio. If you are happy with your container, you could save it as an image using the command:-

docker commit 03a8eb766d5a iis-debug-tools

Just remember to stop it first.

Happy coding.

HTTP Endpoint Monitoring for both Windows and Android
WebUp App