MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Revision 16 as of 2018-04-24 22:12:10
  • CSharp
  • dotnetcore

.Net core

.NET Core to develop console or Web applications. .NET Core is a set of runtime, library and compiler components that allow you to create apps that run on Windows, macOS and Linux.

  • https://www.microsoft.com/net/learn/get-started/windows

  • https://en.wikipedia.org/wiki/ASP.NET_Core

  • https://hub.docker.com/r/microsoft/dotnet/

  • https://docs.microsoft.com/pt-pt/dotnet/core/docker/building-net-docker-images

  • https://msdn.microsoft.com/en-us/library/ff361664(v=vs.110).aspx

In browser tutorial

  • https://www.microsoft.com/net/learn/in-browser-tutorial/1

Sample hello world

.
├── appSolution.sln
├── Dockerfile
├── myApp
│   ├── myApp.csproj
│   └── Program.cs
├── myLib
│   ├── Class1.cs
│   └── myLib.csproj
├── myLibTests
│   ├── myLibTests.csproj
│   └── UniTest1.cs

Dockerfile

FROM microsoft/dotnet:2.0-sdk
WORKDIR /app
RUN apt-get update
RUN apt-get install net-tools procps vim nano -y
RUN mkdir -p /app/myApp
RUN mkdir -p /app/myLib
RUN mkdir -p /app/myLibTests
ADD myApp/* /app/myApp/
ADD myLib/* /app/myLib/
ADD myLibTests/* /app/myLibTests/
ADD appSolution.sln /app/
RUN cd /app && dotnet clean && dotnet build
RUN cd /app/myLibTests && dotnet clean && dotnet test
CMD cd /app/myApp/ && dotnet bin/Debug/netcoreapp2.0/myApp.dll && tail -f /var/log/lastlog
#CMD  tail -f /var/log/lastlog

appSolution.sln

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "myApp", "myApp\myApp.csproj", "{5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "myLib", "myLib\myLib.csproj", "{00D6703F-2D64-4D9A-95AA-430DC38E4EC3}"
EndProject
Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Any CPU = Debug|Any CPU
                Debug|x64 = Debug|x64
                Debug|x86 = Debug|x86
                Release|Any CPU = Release|Any CPU
                Release|x64 = Release|x64
                Release|x86 = Release|x86
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
        EndGlobalSection
        GlobalSection(ProjectConfigurationPlatforms) = postSolution
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|x64.ActiveCfg = Debug|x64
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|x64.Build.0 = Debug|x64
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|x86.ActiveCfg = Debug|x86
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|x86.Build.0 = Debug|x86
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|Any CPU.Build.0 = Release|Any CPU
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|x64.ActiveCfg = Release|x64
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|x64.Build.0 = Release|x64
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|x86.ActiveCfg = Release|x86
                {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|x86.Build.0 = Release|x86
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|x64.ActiveCfg = Debug|x64
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|x64.Build.0 = Debug|x64
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|x86.ActiveCfg = Debug|x86
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|x86.Build.0 = Debug|x86
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|Any CPU.Build.0 = Release|Any CPU
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|x64.ActiveCfg = Release|x64
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|x64.Build.0 = Release|x64
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|x86.ActiveCfg = Release|x86
                {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|x86.Build.0 = Release|x86
        EndGlobalSection
EndGlobal

myApp/Program.cs

   1 using System;
   2 using myLib;
   3 
   4 namespace myApp
   5 {
   6     class Program
   7     {
   8         static void Main(string[] args)
   9         {
  10             Console.WriteLine( Class1.getHelloWorld() );
  11         }
  12     }
  13 }

myApp/myApp.csproj

   1 <Project Sdk="Microsoft.NET.Sdk">
   2 
   3   <ItemGroup>
   4     <ProjectReference Include="..\myLib\myLib.csproj" />
   5   </ItemGroup>
   6 
   7   <PropertyGroup>
   8     <OutputType>Exe</OutputType>
   9     <TargetFramework>netcoreapp2.0</TargetFramework>
  10   </PropertyGroup>
  11 
  12 </Project>

myLib/Class1.cs

   1 using System;
   2 
   3 namespace myLib
   4 {
   5     public class Class1
   6     {
   7         public static String getHelloWorld()
   8         {
   9             return "Hello world from library.";
  10         }
  11     }
  12 }

myLib/myLib.csproj

   1 <Project Sdk="Microsoft.NET.Sdk">
   2 
   3   <PropertyGroup>
   4     <TargetFramework>netstandard2.0</TargetFramework>
   5   </PropertyGroup>
   6 
   7 </Project>

myLibTests/UniTest1.cs

   1 using System;
   2 using Xunit;
   3 using myLib;
   4 
   5 namespace myLibTests
   6 {
   7     public class UnitTest1
   8     {
   9         [Fact]
  10         public void Test1()
  11         {
  12             Assert.Equal("Hello world from library." , Class1.getHelloWorld() );
  13         }
  14     }
  15 }

myLibTests/myLibTests.csproj

   1 <Project Sdk="Microsoft.NET.Sdk">
   2 
   3   <PropertyGroup>
   4     <TargetFramework>netcoreapp2.0</TargetFramework>
   5 
   6     <IsPackable>false</IsPackable>
   7   </PropertyGroup>
   8 
   9   <ItemGroup>
  10     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
  11     <PackageReference Include="xunit" Version="2.3.1" />
  12     <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
  13     <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
  14   </ItemGroup>
  15 
  16   <ItemGroup>
  17     <ProjectReference Include="..\myLib\myLib.csproj" />
  18   </ItemGroup>
  19 
  20 </Project>

Docker commands

   1 #build image
   2 docker build -t dotnetcorehello .
   3 # execute bash in running container
   4 docker exec -it $1 bash
   5 # delete all containers
   6 docker ps -a | awk '//{print $1}' | grep  -v "CONTAINER" | xargs -i sh -c 'docker stop {};docker rm {}'
   7 # execute container using inage dotnetcorehello
   8 docker run -d  dotnetcorehello
   9 # list all containers
  10 docker ps -a

dotnet core commands

   1 # build solution
   2 cd /app 
   3 dotnet clean 
   4 dotnet build
   5 # run tests for library myLibTests
   6 cd /app/myLibTests 
   7 dotnet clean 
   8 dotnet test
   9 # execute app
  10 cd /app/myApp/ 
  11 dotnet bin/Debug/netcoreapp2.0/myApp.dll

test Task

   1 using System;
   2 using System.Threading.Tasks;
   3 using System.Threading;
   4 
   5 namespace testTask
   6 {
   7     class Program
   8     {
   9         static void Main()
  10         {
  11             var x=1;
  12             Console.WriteLine($"ThreadId {Thread.CurrentThread.ManagedThreadId}");
  13             Task t = Task.Run( () => {
  14                 x++;
  15                 Console.WriteLine("Stuff");
  16                 Console.WriteLine($"ThreadId {Thread.CurrentThread.ManagedThreadId}");
  17             } );
  18             t.ContinueWith((Task task)=>{
  19                 x++;
  20                 Console.WriteLine("This the end !");
  21                 Console.WriteLine($"ThreadId {Thread.CurrentThread.ManagedThreadId}");
  22                 task.ContinueWith((Task t2)=>{
  23                     x++;
  24                     Console.WriteLine("t2 {0}",x);
  25                     Console.WriteLine("ThreadId {0}",Thread.CurrentThread.ManagedThreadId);
  26                 });
  27             });
  28             //t.Wait();  
  29             var tx = Task<long>.Run( ()=>{ return 11L; } );
  30 
  31             tx.ContinueWith((Task<long> txy)=>{
  32                 Console.WriteLine($"Res: {txy.Result}");
  33             });         
  34         }
  35     }
  36 }
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01