I have problems with running .net core app on my Debian 9. All .net core versions below 2.0 preview returns
"Failed to initialize CoreCLR, HRESULT: 0x80131500" error during execute dotnet new, restore or e.g --version.
.NET core 2.0 preview works correctly but framework doesn't want to cooperate with JwtBearer - becasue Bearer has 1.1.2 version and dotnet returns
"Downgrade package detected bla bla...."
(Maybe you have idea how to build app with downgrade package?)
So I decided to move project to docker.
I downloaded docker with .net core 1.1. I created docker-compose file, where I add a volume mount to docker see my application.
Everything works correctly, but with one small exception.
When I execute dotnet restore, build and run on my docker, everyting is beeing override, so my Visual Studio Code immidietly shows me warrining "Unresolved dependencies ...." and all references to dotnet namespaces, class etc are highlighted in red.
How I can fix it?
Below is my docker-compose.yml
version: '2'
services:
webapi:
build: .
command: "/bin/bash"
container_name: webapi
volumes:
- /home/pb/docker-test/docker-compose:/app
- /home/pb/docker-test/docker-compose/Evento.Api/obj/
ports:
- "5000:80"
tty: true
/home/pb/docker-test/docker-compose/Evento.Api/obj/ I think that this directory makes problems becouse contains a few path which are changing after dotnet restore.
I tried to exclude that directory in this way, but it doesn't work. Event if direcotry is not mounted, dotenet creates it after dotnet restore, and override on host.
Dockerfile
FROM microsoft/aspnetcore-build
WORKDIR /app
Related
Create a docker image for a .NET Console application. But when trying to run the image, its throwing error.
Following section contains the Dockerfile content,
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/runtime:6.0
COPY bin/Release/net6.0/publish .
ENTRYPOINT ["dotnet", "MySampleApplication.dll"]`
Following is the error that I get while trying to run the docker image,
docker run collector
You must install or update .NET to run this application.
App: /MySampleApplication.dll
Architecture: x64
Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
.NET location: /usr/share/dotnet/
No frameworks were found.
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=6.0.0&arch=x64&rid=debian.11-x64`
Tried installing .NET sdk and runtime environment in Ubuntu, but still the same issue.
Your app might run from the console, but in MS terminology, it's not a console app. You get a message saying Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64) and that tells us that it's an ASP.NET application. ASP.NET is not included in the console image, but it is included in the aspnet image.
So change your Dockerfile to
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0
COPY bin/Release/net6.0/publish .
ENTRYPOINT ["dotnet", "MySampleApplication.dll"]
When you run it, you'll need to map port 80 to a host port to be able to talk to the application. So your docker run command will look something like
docker run -d -p 8080:80 collector
You should then be able to reach the application on http://localhost:8080/ from the host.
I stumble around a whole day trying to get a .net Core 3.1 App deployed with Jenkins.
My solution until today was:
dotnet publish "git/%SolutionPath%" -o "%WORKSPACE%/output/" -c Release -r win-x64 --self-contained true
Today I had a new app an an error:
error : MSB4803: The task "ResolveComReference" is not supported on the .NET Core version of MSBuild. Please use the .NET Framework version of MSBuild. See https://aka.ms/msbuild/MSB4803 for further details
So I started to try to switch from dotnet publish to msbuild - and the hell began. After dozens of errors, missing environment variales and other things I'm stuck with this runtime error.
An assembly specified in the application dependencies manifest (SgbAppInstaller.deps.json) was not found:
package: 'PropertyChanged.Fody', version: '3.2.6'
path: 'lib/netstandard1.0/PropertyChanged.dll'
I just want to compile my program. I really didn't expect it to be complicated.
The only thing I found to this topic is: Do not use msbuild, use donet publish for .net Core
I am trying to publish a C# .net core console app I made, to a Linux machine running Centos 7 64 bit. Currently, I am publishing the app using the command:dotnet publish -c release -r contos.7-x64. Unfortunately, it appears as though publishing in this way requires .net core to be installed on the target machine. Is it possible to do this where I do not need to install anything on the machine that I am publishing to?
In .NET Core 2.2 you can create a self-contained app (i.e. not requiring .NET Core runtime installed on host machine) with this command dotnet publish -r centos.7-x64 -c Release --self-contained. It'll produce executable and a lot of dependencies.
In .NET Core 3 you can compress all dependencies into a single file dotnet publish -r centos.7-x64 -c Release /p:PublishSingleFile=true. You can also add flag /p:PublishTrimmed=true to reduce executable size by tree trimming.
More details can be found here and here.
I found that the issue was that the project was not compiling to core 2. Rather, the project was compiling to version 1. After making this change, the published project was able to run on Centos.
I created a .Net core C# console application in Visual Studio and used the following steps to test it on Linux.
Use Visual Studio "Build -> Publish" menu item to create the executable files in ....\bin\Release\netcoreapp2.1\publish.
Copy the "publish" directory to the Linux machine
On Linux, chmod 777 myApp.dll
./myApp.dll
However, executing the app shows the error of
-bash: ./myApp.dll: cannot execute binary file
It looks like you did a Framework-Dependendent Deployment. Essentially, the publish command was:
dotnet publish -c Release
FDD assumes that you are going to have a .NET Core runtime to run your application on the target platform.
Once you copied over the publish directory to another machine (which could be Linux, macOS or Windows), your application still needs a .NET Core runtime to run your application.
Installing the .NET Core runtime depends on the particular Linux distribution that you are using. Once you have it installed, you can run your application by doing:
dotnet /path/to/publish/myApp.dll
An alternative to Framework Dependent Deployment is Self-Contained Deployment. In this mode, the published application will contain your application as well as a copy of the .NET Core runtime. On command line, doing a a SCD publish looks like this:
dotnet publish -r linux-x64 -c Release
For doing this in Visual Studio, see the link above. Then, you should see a bin\Release\netcoreapp2.1\linux-x64\publish\ directory that contains a myApp file. You can copy over this publish dir over to a Linux distribution and just run:
/path/to/linux-x64/publish/myApp
I have a .NET Core project that contained 2 projects:
SLN:
- Web-API
- Infrastructure
I was building it with docker using this dockerfile
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
COPY . ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/ .
ENTRYPOINT ["dotnet", "/app/Lab/out/API.dll"]
But now I have created a Web application as well in my solution
SLN:
- Web-API
- Web-App
- Infrastructure
Suddenly, docker isn't building anymore. How come?
How can I create two docker containers based on the same solution one for the Web-API and one for the Web-app?
Error message from Docker:
The "GetDotNetHost" task could not be loaded from the assembly /usr/share/dotnet/sdk/NuGetFallbackFolder/microsoft.aspnetcore.mvc.razor.viewcompilation/2.0.3/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tasks.dll. Assembly with same name is already loaded Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [/app/Lab/API.csproj]
So this problem is now finally fixed. It actually turned out it was a problem while compiling a .net core 2.0 project when having Razor views available:
Razor view precompilation is currently unavailable when performing a
self-contained deployment (SCD) in ASP.NET Core 2.0. The feature will
be available for SCDs when 2.1 releases. For more information, see
View compilation fails when cross-compiling for Linux on Windows.
What I needed to do was to add the nuget package:
Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
in my project to make it work. Strange thing was that it was building inside visual studio for Mac but not from the command prompt.