Archive for the ‘.NET Core’ Category

Dockerize .NET Core 2 Web App

Recently Microsoft officially announced .NET Core 2.
Installing the SDK in Visual Studio 2017 is available the creation of .NET Core 2 projects.
I tried to create a Docker solution with the new kid on the block.
Currently it seems that with Yeoman there are still no support for .NET Core 2, the available templates at the moment are only for .NET Core 1:

So i tried to create first the project with Visual Studio 2017:

I created a new Core Web App MVC named aspnetapp,

without enabling the native Microsoft support for Docker; launching the Web App it worked without issues:

Then i added a Dockerfile in the project root with this content, following the official page:

FROM microsoft/aspnetcore-build:2.0 AS build-env

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/aspnetcore:2.0
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]

And a .dockerfile in order to make the build context as small as possible


at this point from command prompt in the directory where is Dockerfile

docker build -t aspnetapp .

and then with

docker run -d -p 8080:80 --name myapp aspnetapp

the site this time runs from the container:

and we have the new image:

D:\work\MyDotNetCoreApp\aspnetapp>docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
aspnetapp                     latest              a7ed19cfc58e        8 hours ago         283MB

Categories: .NET Core, Docker, Vs2017

Publish .NET Core 1.0 site to Azure

I’m working to my first Angular2 site , and now that something is working i tried to publish on Azure.
First lesson learned: if you use ASP.NET Identity copy only the table structures(of AspNetRoles table, AspNetUsers and so on) to Azure SQL , but not the data: use a DbSeeder code in Startup .cs to create the initial set of Users, Roles, etc. otherwise you never get successfully the token.
The deployment is simple, as the normal (not Core) ASP.NET sites: right clic on the project then Deploy.
It is recommended to download from Azure the WebApp publish profile

when publish from Visual Studio (in my case, Vs2015)

In order to simplify the process.
Now the site started, but i got an error:

connecting to i noticed that there are not visible .json files… note that opening the web.config it says:
“Configure your application settings in appsettings.json. Learn more at
Oh well, but the Vs2015 publisher does not copy appsettings.json.. and the Core packages? where are? i should try with Vs2017…
So I created with the scm file manager an empty appsettings.json file and an empty package.json file, copied from my pc the text for both files, changed the connection string in appsettings.json.
Then i launched “npm install” in the scm console, that reloads the missing Core packages.
Finally, the site is working.

Categories: .NET Core, Angular 2, Azure

Angular2 changes

I’m working to a .NET Core site using Angular2, by default at every update to Angular new problems.
This time was easy: before in order to retrieve a textbox in a Typescript file i used


Now the syntax has changed, .get instead of .find


Categories: .NET Core, Angular 2