How to enable docker support ASP.NET applications in Visual Studio

Introduction

In this article, you will know that how to enable docker support for ASP.NET application in Visual Studio. We will create an ASP.NET Core application docker support and also enable docker support in an existing application.

Prerequisites

  • Docker for Windows
  • Visual Studio 2017 or later with the .NET Core cross-platform development workload

Enable Docker support in a new application

You can get Docker support in your project when you create a Visual Studio web project, either. NET Core or the full framework. If you choose the .NET Core framework, you get the option to add Docker support in the new project wizard but for the full framework, we can add Docker support later context menu “Solution Explorer”. See below steps to create a .NET Core project with Linux container support:

clip_image001

Docker tools in Visual Studio understand the difference between. NET Core and the. NET full framework so the generated files will nicely reflect those different targeted platforms.

To add Docker support for the full framework, go through previous post - Containerizing a .NET application

Enable Docker support in a new application

You add Docker support after creating a project is by right-clicking the project in the “Solution Explorer” and then select “Docker Support” option under the Add submenu.

clip_image003

Visual Studio will add DockerFile and .dockerignore to the project that will be used to build a docker container image starts with a reference to the base image dotnet:2.2-aspnetcore-runtime.

clip_image005

Note: To build this container, you need to switch the Docker tools for Windows on your machine to run Linux containers. If it is targeting to different operating system type, then you would get errors during the build since you can't mix Linux containers with Windows containers.

Docker support also added the generated YAML files. YAML files can be used together with docker-compose to execute Docker commands to a set of containers instead of only one at a time so that multiple container can work together for the microservices scenarios.

docker build -f "D:\DevWorkSpaces\GitHub\WebDevLearning\WebDev\WebDev.Containerized.MVCWeb\Dockerfile" -t webdevcontainerizedmvcweb:dev

clip_image007

Build Docker image from CLI

Open command prompt in administrative mode and run the below command  in project folder:

C:\Users\niranjansingh\Source\Repos\WebDevLearning\WebDev\WebDev.AspNETMVC>docker build .

clip_image001

Running application under Docker Environment

For .NET Core framework applications, Just run the application by selecting the Docker option just after the Run arrow button. After that application will build and create Docker image according to the settings provided in the DockerFile.

clip_image009

For my case application is targeting “Linux” and Docker for Windows on my system is configured to run the Windows contains so it will not build my case. So, remember to switch particular target Operating system containers before you build the application.

For a .NET framework application, make docker-compose as startup project. After this modify the .yml files to build and run the contains.

image

You will see Docker Compose button on the place of “Docker” in .NET full framework applications.

image

Click on Debug button to let the docker decompose to build and run the docker image on the bases of yml file configuration.

Enable code preview with the Visual Studio enhanced scroll bar

Introduction

This is the first time that I saw code preview through scrollbar in Visual Studio. I have use most of the Visual Studio IDE starting from Visual Studio 2002 and scrolling of code files done using the classic scrollbar.

Starting from Visual Studio 2013, an enhanced scrollbar feature is enabled but I was not aware of it till now. Recently I saw below code preview features through a wide scrollbar:

Enabling Visual Studio scrollbar code preview mode

By default, this feature is not enabled so that I have not used this cool feature before. Actually, it requires to switch the scrollbar mode and below are the steps to switch scrollbar mode:

  1. Open option using Tools menu and select “Options”
  2. In the options dialog select the Text Editor | All Languages | Scroll Bars node from left side menu
  3. Now change the scrollbar behavior to map mode and check the “Show Preview Tooltip” checkbox as shown in below image.

I found it a cool feature which enables the developer to view the see the code in tooltip by hovering on the scrollbar without scrolling down to the bottom of the code file.

You can find detailed information at Visual Studio scroll bar customization documentation.

Create/Update an offline installation of Visual Studio 2017

Introduction

In this article we learn that how to create an offline installer for Visual Studio 2017. Recently Visual Studio 2017 version 15.8 Released and then i have updated Visual Studio 2017 on my laptop. I have another machine which does not connect with high speed internet so I need to install Visual Studio through offline installer (ISO).

Microsoft designed Visual Studio 2017 installer to install specific modules (workload-based model) and allows to install minimal set of features to start development using Visual Studio.

Create Visual Studio 2017 offline installation media

Step 1 – Download the Visual Studio installer setup

It is recommended to use Visual Studio web installer because it will always install/ update to the latest version of the Visual Studio 2017.

Download the latest version of Visual Studio 2017 Web installer by clicking below links
Visual Studio Community 2017 | Visual Studio Professional 2017 | Visual Studio Enterprise 2017


Step 2 – Create/ Download installation setup files

To create updated version installation for Visual Studio, use the below command create or update the existing installation layout to a newer version. You don't have to specify any additional command-line parameters.

vs_enterprise.exe --layout d:\vs2017ent

It will create a complete local installation media for Visual Studio 2017 with all features and definitely it will take lots of time to download all the work loads.

You can also specify the language at the Visual Studio to download so that it will download installation files for the specified set of languages only

vs_enterprise.exe --layout d:\vs2017ent --lang en-US

In my case, I have already downloaded Visual Studio 2017 installation files earlier. This time I need to update this installation layout to transfer update on my offline computers.

Once the offline installation files saved at the specified location then transfer it on another computer and ready to install the Visual Studio 2017.

Click the vs_setup.exe file to start the installer then install the Visual Studio after selecting the required development environment features you want to install.

Clean up previous version obsolete package


During the update process of existing Visual Studio installation files, my computer drive gets full and some of the packages failed to download. I checked the installation layout folder and found that there are previous version packages also exists. I have removed few of them manually to complete the download process.

Visual Studio installations files folder size incrementally increase whenever we update the existing installation files. Visual Studio installation folder may have some obsolete packages that are no longer needed by the latest Visual Studio installation.

You can use the --clean option to remove obsolete packages from an offline cache folder.

Source of information: How to remove older versions from a layout

Step 1 – Find file path(s) to catalog manifest(s) that contain those obsolete packages

You can find the catalog manifests in an "Archive" folder in the offline layout cache. They are saved there when you update a layout. In the "Archive" folder, there is one or more "GUID" named folders, each of which contains an obsolete catalog manifest. The number of "GUID" folders should be the same as the number of updates made to your offline cache.

Step 2 - Run the “—clean” command by supplying the files paths to these catalogs

vs_enterprise.exe --layout d:\vs2017ent --lang en-US --clean d:\vs2017ent\Archive\d88a0497-7bee-42ad-8ea5-3361cd52e075\catalog.json




References:

Create an offline installation of Visual Studio 2017
Install Visual Studio 2017 on low bandwidth or unreliable network environments
Update a network-based installation of Visual Studio

How to fix error TFS connection error "You are not authorized to access …"

In this article we will know that how to fix the error when connecting a project collection in Visual Studio with Source Control Explorer open (TF30063: You are not authorized to access… project)

Scenario:
Recently, I must change my Active Directory account password due to password policy which force the user to change the password after few days. In my development environment TFS require AD credentials to connect with TFS services.

Solution:
Peoples from developer community suggested various ways to solve this issue. Few of them explained as below:

  1. One probable solution is clearing the Internet explorer 9 and above cache completely. The Team Foundation Server login apparently uses Internet Explorer which can be launched from Visual Studio though and It may conflict or try to match with cached credentials. After the cache clearing, Visual Studio ask to the correct login details screen or authenticate automatically.

    clip_image001

    Now logout from portal and login again with updated credentials

    clip_image003

  2. In my case removing the entry from credential manager which cached the previous password for the TFS connection.

    clip_image005

    Find and remove entry from web or Windows credentials where you find for your TFS service. I need to remove it from Windows Credentials

    clip_image007

    Restart Visual Studio and Then it worked again.
  3. Sometimes this problem gets resolved by clearing TFS cache from below location "C:\Users\%UserName%\AppData\Local\Microsoft\Team Foundation\7.0\Cache". Just press Win+R on keyboard and paste this path. Remove the cache and reconnect TFS with valid credentials again. It works if you are using multiple logins to connect the TFS Services.

Conclusion:

We have discovered ways to solve the TFS issue. It may work one of them to someone’s problem.