See the tests in VSCode and improvements in powershell–part 24

I wanted that the user can see the tests when running in  VSCode. So in devcontainer.json I have put

“extensions”: [
“ms-vscode.csharp”
“ms-vscode.csharp”,
“hbenl.vscode-test-explorer”,
“formulahendry.dotnet-test-explorer”
]

and in the settings.json on .vscode folder

 

dotnet-test-explorer.enableTelemetry”: false,
“dotnet-test-explorer.testProjectPath”:”**/*.sln”,
“dotnet-test-explorer.autoExpandTree”:true

 

So far, so good. But – I remember that powershell have a problem. And I figure why – before running

dotnet pwsh

I should run

dotnet tool restore

in order to run the dotnet-toolsjson from .config file

 

{

“version”: 1,

“isRoot”: true,

“tools”: {

“powershell”: {

“version”: “6.2.3”,

“commands”: [

“pwsh”

]

}

}

}

 

.And this command should be executed both in Docker and in Azure

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility

Deploy to Azure–part 23

Create in Azure an AppService infovalutar with InfovalutarRG resource group – can be done like here

https://docs.microsoft.com/en-us/azure/app-service/app-service-web-get-started-dotnet

or from the Azure Portal ( create AppService – I have put Linux with .NET Core 3.0)

Searching how to connect AzureDevOps – the connection should be added from Project Settings (a link at the bottom of the page)

Creating the service InfoValutarServiceConnection on AzureDevops

Saving the yaml files ( with inherent spaces problems)

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app-deployment?view=azure-devops

Now it says the error:

2019-11-28T19:02:29.1210252Z ##[error]Error Code: ERROR_DESTINATION_NOT_REACHABLE
More Information: Could not connect to the remote computer ("infovalutar.scm.azurewebsites.net"). On the remote computer, make sure that Web Deploy is installed and that the required process ("Web Management Service") is started.  Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_DESTINATION_NOT_REACHABLE.

Good – but my site is  https://infovalutar.azurewebsites.net/ ,  not infovalutar.scm.azurewebsites.net

Reading documentation from https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app-deployment?view=azure-devops

Changing from

– task: AzureRmWebAppDeployment@3

inputs:

azureSubscription: ‘InfoValutarServiceConnection’

WebAppName: ‘infovalutar’

Package: $(System.ArtifactsDirectory)/*InfoValLinuxX64*.zip

ResourceGroupName: ‘infovalutarRG’

to

– task: AzureRmWebAppDeployment@4

and hoping in magic  ( also, put in docker job

dependsOn:

– Build_With_Test

condition: and(succeeded(),false)

in order to not execute docker job now…

And now the deployment works! See yourself at https://infovalutar.azurewebsites.net/

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility

Debug Application under VSCode and Docker–part 22

What I wanted is that people that have only a container application ( docker) and  VSCode ( not Visual Studio , nor .NET Core Framework) be able to debug the application and run it. That means, I no longer require to install .NET Core SDK on the local PC

Read a lot

https://code.visualstudio.com/docs/remote/containers#_devcontainerjson-reference

https://github.com/microsoft/vscode-dev-containers/tree/master/containers/dotnetcore-3.0

https://code.visualstudio.com/docs/remote/containers

Some important things :

  1. in the devcontainer.json put  “shutdownAction”: “stopContainer”
  2. Delete continuously the vscode image if something wrong

docker container prune -f

docker images “vs*”

docker image rm <id of the prev image>

Now I have all in place ( see commit https://github.com/ignatandrei/InfoValutar/commit/474698d33e20e1aa6fc9e2fd6f4c42ea73e50b03 )

A .devContainer folder with a DockerFile and devcontainer.json ( to construct the docker container)

A .vscode folder with launch.json , devcontainer.json, settings.json  – to run F5 into the container

All I need is to Launch VSCode, press Remote-Container : Open Folder in Container, goto Infovalutar folder that has the .sln. Then press F5 in VS Code  and voila!

Now, anywhere I go, I can launch VSCode and debug the application.

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility

Making visible the application -part 21

Trying to make visible the docker with https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/ignatandrei/InfoValutar/master/PlayWithDocker/WebAPI.yml

leaving an issue: https://github.com/play-with-docker/play-with-docker/issues/370

 

Decided  to add to the readme the docker . Going to Shields.io . Putting some lines for beginners with docker.

Reading more about port –binding . Figuring this is is:

ENV ASPNETCORE_URLS=http://*:8080
#ENV ASPNETCORE_URLS=http://0.0.0.0:8080

And that was all !

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility

Docker–fourth part–part 20

Time to push to docker

1. putting the docker password into the pipeline variables

2. Modifying the yaml

3. Waiting for build

Error in Docker:  Incorrect name or password

Now, I want to create 2 jobs to isolate Docker from the main build.

I encounter some errors in the yaml file . That shows fast in the AzureDevops, but you must figure what it is by reading the line

/azure-pipelines.yml: (Line: 8, Col: 7, Idx: 271) – (Line: 8, Col: 7, Idx: 271): Mapping values are not allowed in this context.

/azure-pipelines.yml: (Line: 45, Col: 3, Idx: 1225) – (Line: 45, Col: 4, Idx: 1226): While parsing a block mapping, did not find expected key.

Job Build Docker has an invalid name. Valid names may only contain alphanumeric characters and ‘_’ and may not start with a number.

(a name attribte was not indented, steps was not found before script, build name having spaces)

Now trying to build again. Error because I have put the password variable from Azure secret? Delete the variable, putting another variable with the same name, not secret. Works!

Now I have on docker hub a new image, ignatandrei/infovalutar  : https://hub.docker.com/r/ignatandrei/infovalutar

You can run with

docker run –rm -it -p 8080:8080  ignatandrei/infovalutar:latest

And then go to http://localhost:8080/swagger/

And that was all! ( pipeline definition at https://dev.azure.com/ignatandrei0674/InfoValutar/_build?definitionId=5&_a=summary )

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility

Docker–third part–part 19

Trying different  codes in the csproj to add dynamically content from a folder ( including the dll’s copied there ) and to retrieve in the output directory: ( reading from internet of all those stuff)

Version 1:

<!–<Target Name=”ContentsBeforeBuild” AfterTargets=”BeforeBuild”>
<ItemGroup>
<Content Include=”plugins\**” />
</ItemGroup>
</Target>—>

Version 2:

<!–<Content Update=”plugins\**\*.dll” CopyToOutputDirectory=”Always” LinkBase=”plugins”>

</Content>—>

Version 3:
<!–<Content Update=”$([System.IO.Directory]::GetFiles(‘$(ProjectDir)plugins’, ‘*.*’, SearchOption.AllDirectories))” CopyToOutputDirectory=”PreserveNewest”>–>

<!–</Content>—>

Version 4: – works!

<ItemGroup>
<None Remove=”plugins\” />
<Content Include=”plugins\**\*.dll” CopyToOutputDirectory=”Always”/>
</ItemGroup>

 

Now, I want to make this docker each time that I modify  and show to the end users to test it.

However, this should be not in the same process as running the tests  – the tests should be very fast in order to see problems – the making of release software could take minutes.

Going to https://dev.azure.com/ignatandrei0674/ and making a new project to deal with this.Creating new project, integrating with GitHub – seamless integration with .NET Core – even created a azure-pipelines.yml for me.

Extra bonus: GitHub actions runs on Ubuntu. I will put Azure to run on Windows. This way, I know that the build of the project works either way

Now, a different error in docker:

Access to the path ‘C:\app\InfoValutar\InfoValutarDOS\obj\InfoValutarDOS.csproj.nuget.dgspec.json’ is denied.

Oh, forgot to put a .dockerignore . First I put where the docker file was –big mistake. Should be put where the folder to be included is!

Now ,a different error in docker

Access to the path ‘C:\app\InfoValutar\InfoValutarWebAPI\InfoValutarWebAPI.xml’ is denied.

Oh, give me a break! Delete the .xml and add later to .gitignore and .dockerignore ( as full path, I do not want to ignore ALL xml files)

I works now!!!!

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility

Docker–second part–part 18

Now , I must replace all with powershell files. Some problem  – if I build twice, it says : resource already exists. So I need to add

–Force

parameter.

Now pushing to GitHub https://github.com/ignatandrei/InfoValutar/commit/2c487963da53f04f94a0a7b060999f8e27635179

and see if it works. No, error on .sln build.

ObjectNotFound: (/home/runner/work/I\u2026nfoValutar/plugins”

Apparently, it is a Unicode character ?

Try to save as ASCII file. Waiting for GitHub action to do it’s magic.

Same Error – now putting some messages with echo to see what is there

echo “args 0 ”  $args[0]
echo “args 1 ” $args[1]
$a= Get-Location
echo $a
echo now copy

Now waiting for GitHub actions to display – it does NOT show the console from powershell, just the error!

Putting in After Build to copy the plugins.

Same error. Looking very, very attentive to the command , I see now. Can you see ?

pwsh $(ProjectDir)preBuild.ps1 “”$(RepoRoot)plugins\”  “$(TargetDir)”

Apparently, pwsh from Windows is more forgetful than the Linux one… ( or it is not the same ? Maybe because I have powershell on my PC ?)

Now ( after deleting double double quotes) shows also the powershell messages!

Now I can make docker!

And the first problem arises. When building the .sln , it copies to the output folder the plugins. But not when publish the csproj.

Try with –no-build when publish and adding

<RuntimeIdentifiers>win10-x64;linux-x64</RuntimeIdentifiers>

to the .csproj

Now, dotnet publish does not copy the plugins  – I should copy by hand ?

So – figure that I do not copy to the final output – but direct to the project.

1. I should copy there in the build event of the project – modify the arguments to have copy in the plugins folder

2. I should include in the .csproj any new plugins:

<Content Include=”plugins\**”>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

Error duplicate items  – found it was

<Content Update=”plugins\**” CopyToOutputDirectory=”PreserveNewest”>

3. Do not include in GitHub – already done – plugins folder is not included

Now trying to execute in swagger to give list of plugins / banks => internal server error

Trying to publish without single file => give empty list /banks. Let’s see  -but next time

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility

Docker–first part–part 17

Trying to put the web into docker. In order to have easy builds for the developer , we copy the sln, then the csproj , then dotnet restore, then copy files. This way we get advantage of Docker caching.

Created dockerForWebAPI.txt

and run

docker build -f dockerForWebAPI.txt  -t infovalutar ..

Docker has not recursive copy – https://github.com/moby/moby/issues/15858

Solution: copy the .csproj one by one. ( other solution:  .tar file and copy the .csproj into tar, then use ADD command)

So copy the .sln with

COPY InfoValutar/*.sln ./

Then trying to copy files

Version 1

COPY  InfoValutar/InfoValutarDOS/InfoValutarDOS.csproj ./

( not good, same dir)

Version 2

COPY  InfoValutar/InfoValutarDOS/InfoValutarDOS.csproj ./app/InfoValutarDOS/InfoValutarDOS.csproj

(not good , discovered that creates another app folder – thanks for the docker run –rm -it infovalutar:latest /bin/bash )

Version 3

COPY  InfoValutar/InfoValutarDOS/InfoValutarDOS.csproj ./InfoValutarDOS/InfoValutarDOS.csproj

Good. Now copy files and build solution

And now it is the moment when echo and xcopy for plugins will bite me  – no xcopy on linux….

The only thing that I know to work in WIndows and Linux is … Powershell.

Any .NET Core 3 has this – run pwsh. It remains to install to my directory –  see https://andrewlock.net/new-in-net-core-3-local-tools/

The version of powershell on my PC differs from the version on Windows Container from GitHub actions.  Switch to Ubuntu.

Again – does not work . Try with pwsh –Command.

It does work on GitHub actions but NOT on my PC ( does not recognize command. ) . Thinking different pwsh version.

But on thing is the same  – running file.

Create a powershell file

Copy-Item -Path $args[0] -Destination $args[1] –Recurse

and running this file with

pwsh $(ProjectDir)pb.ps1 “$(TargetDir)”  “$(SolutionDir)plugins\$(ProjectName)”

( Do not forget to run first

dotnet tool restore

in the solution folder!)

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility

Andrei Ignat weekly software news(mostly .NET)

* indicates required

Please select all the ways you would like to hear from me:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.