Publishing ASP.NET Core to Ubuntu - c#

Just letting you know that I'm new in Linux and have been trying for a while now to publish a ASP.NET Core website on Linux Ubuntu 18.04.
I have developed a test project in ASP.NET Core 2.1 in Visual Studio 2017 and I'm trying to publish it on Ubuntu 18.04.
I have followed the following steps described in this article:
https://blog.todotnet.com/2017/07/publishing-and-running-your-asp-net-core-project-on-linux/
Instead of publishing the test website described in the article I want to publish my own website. I'm publishing the website in Visual Studio 2017.
After publishing the website to the working directory on Linux I have the following files:
Docker.DotNet.dll
TestCoreWebsite1.deps.json
TestCoreWebsite1.dll
TestCoreWebsite1.pdb
TestCoreWebsite1.runtimeconfig.json
TestCoreWebsite1.Views.dll
TestCoreWebsite1.Views.pdb
web.config
When I type in the command in Linux terminal "journalctl -xe" I get the following error:
realpath(): Permission denied
System.UnauthorizedAccessException: Access to the path '/var/www/.dotnet' is denied. ---> System.IO.IOException: Permission denied
--- End of inner exception stack trace ---
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOpt
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.IO.File.Create(String path)
at Microsoft.Extensions.EnvironmentAbstractions.FileWrapper.CreateEmptyFile(String path)
at Microsoft.DotNet.Configurer.FileSentinel.Create()
at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel, IFirstTimeUseNot
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
at Microsoft.DotNet.Cli.Program.Main(String[] args)
tcore.service: Main process exited, code=exited, status=1/FAILURE
tcore.service: Failed with result 'exit-code'.
It tells me that "/var/www/.dotnet" is denied. In actual fact is that this path doesn't even exists.
What should I do to fix this problem?
Strange by following the steps of this article it still doesn't work.
leo#leo-virtual-machine:/var/www$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.401
Commit: 91b1c13032
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /usr/share/dotnet/sdk/2.1.401/
Host (useful for support):
Version: 2.1.3
Commit: 124038c13e
.NET Core SDKs installed:
2.1.401 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.0-preview1-002111-00 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
leo#leo-virtual-machine:/var/www$ dotnet --version
2.1.401
Is there a problem because I have multiple versions off .NET Core runtimes installed?

Related

Running .NET application on OSX fails with "No frameworks were found"

I'm attempting to compile and run a .net application on Mac OS (on our CI platform) but keep running into the following error message:
The framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
- No frameworks were found.
However, another .NET application (which from what I can see, has no differences with the target framework, and only small differences between the csproj contents) compiles and runs fine just before this application is compiled and run.
dotnet --list-sdks returns:
3.1.419 [/Users/username/.dotnet/sdk]
5.0.408 [/Users/username/.dotnet/sdk]
dotnet --list-runtimes returns:
Microsoft.AspNetCore.App 3.1.25 [/Users/username/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [/Users/username/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.25 [/Users/username/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [/Users/username/.dotnet/shared/Microsoft.NETCore.App]
So from this I can see that .NET 3.1 is installed, but why is the application unable to be executed? Am I missing something here? Would appreciate any help or pointers.
Thanks

OmniSharp formatter does not format C# files

The installed ms-dotnettools.csharp (v1.25.0) extension does not seem to format the C# code : my C# files witch I try to format popups me about missing C# formatter
Visual Studio Code
There is no formatter for 'csharp' files installed.
[Cancel] [Install Formatter...]
I open in the VSCode the entire root folder, containing several projects (C#, Angular etc.), and when opening individual Cs files and try to Shift+Alf+F to format the file, it asks me for the formatter.
I have the following VSCode configuration
Visual Studio Code
Version: 1.67.2 (user setup)
Commit: c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
Date: 2022-05-17T18:15:52.058Z (2 wks ago)
Electron: 17.4.1
Chromium: 98.0.4758.141
Node.js: 16.13.0
V8: 9.8.177.13-electron.0
OS: Windows_NT x64 10.0.19044
also this .net installs
.NET SDK (reflecting any global.json):
Version: 5.0.408
Commit: da985e2a23
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.408\
Host (useful for support):
Version: 5.0.17
Commit: 6a98414363
.NET SDKs installed:
3.1.419 [C:\Program Files\dotnet\sdk]
5.0.407 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
I've checked that, reset it and restarted VSCode, but it has any effect:
You need to either update .Net to 6+ or install a previous version of Omnisharp.
Version 1.25.0 requires .Net 6+. If that's not an option for your environment then you can install a previous version of the Omnisharp extension.
In order to do this, press ctrl/cmd + shift + x to bring the extensions side panel, then click on the configurations wheel and select 'Install another version'.
I tried 1.23.12 and the formatter is working now.
If you run into this issue again you can check the output of the extension to check what could be causing it.
I'm not sure if you found it already, but I'll leave it here in case someone else needs it.

Building an lambda zip file on the commandline in AWS codebuild fails with "the required library libhostfxr.so could not be found"

I am running a command during a AWS CodeBuild in order to build a lambda zip file.
The command is as follows:
dotnet lambda package --framework netcoreapp2.1 -o ../../artifacts/Jobs.zip
Here is the error:
**A fatal error occurred, the required library libhostfxr.so could not be found.
If this is a self-contained application, that library should exist in [/root/.dotnet/tools/.store/amazon.lambda.tools/3.3.1/amazon.lambda.tools/3.3.1/tools/netcoreapp2.1/any/].
If this is a framework-dependent application, install the runtime in the default location [/usr/share/dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location.
Makefile:28: recipe for target 'Jobs/artifacts/Jobs.zip' failed**
Because this is a container I have printed out the dotnet info:
.NET Core SDK (reflecting any global.json):
Version: 2.2.402
Commit: c7f2f96116
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /root/.dotnet/sdk/2.2.402/
Host (useful for support):
Version: 3.1.2
Commit: 916b5cba26
.NET Core SDKs installed:
2.2.402 [/root/.dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.7 [/root/.dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.7 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.7 [/root/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [/root/.dotnet/shared/Microsoft.NETCore.App]
So the project in Visual Studio is targeting .NET Core 2.1
This issue just started about 10 days ago. I was able to go back to an earlier commit, push it to GitHub which kicks of the code build in AWS. This earlier commit, when pushed 2 weeks ago was successful and I did not see this libhostfxr.so error. Basically anything I push now I get the above error.
While researching I found that because I am using a Container, I can use the flag
--self-contained=true and /p:PreserveCompilationContext=true
so that I can bundle all dependencies but that has not worked either.
Not sure what else to try at this point. Does anyone have any ideas? The target framework for these lambdas is .NET core 2.1.
After more research I found the solution here. https://github.com/aws/aws-codebuild-docker-images/issues/321
I need to set the DOTNET_ROOT in my yml file.

Dotnet test ignoring filter when on Linux

I'm using xunit, with trait attributes set on some of my tests. When running dotnet test I'm trying to filter by these traits. I have it working fine locally on my Windows machine but when I run the same command on my CI container then it doesn't filter my tests.
The command is:
dotnet test --filter Category=Integration
I'm using CircleCI with the container mcr.microsoft.com/dotnet/core/sdk:2.2
When I SSH to the box and try running the command, it just runs all of the tests.
dotnet --info from the container:
.NET Core SDK (reflecting any global.json):
Version: 2.1.700
Commit: c2ef055a0f
Runtime Environment:
OS Name: debian
OS Version: 9
OS Platform: Linux
RID: debian.9-x64
Base Path: /usr/share/dotnet/sdk/2.1.700/
Host (useful for support):
Version: 2.1.11
Commit: d6a5616240
.NET Core SDKs installed:
2.1.700 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.11 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.11 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.11 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
I've managed to resolve my issue just about. It appears it's a bug with the 16.1.0 SDK version (which dictates the version of vstest). As the issue was just on CI for me, I pinned the container I was using to
mcr.microsoft.com/dotnet/core/sdk#sha256:d0a71e1312be2618f320a7b7cc6d7423af3810542b3ffd35438108800ecfb958
which contains the 16.0.1 SDK. It's not the perfect fix but resolves my immediate issue.

Using Jenkins SonarQube MSBuild plugin with dotnet core on linux

i am struggling to both understand and get the Jenkins SonarQube MSBuild to analyse a dotnet core c# project and hoped someone could help out with it. I am able to run the scan using the following commands in an "Execute Shell" build step:
dotnet sonarscanner begin /k:"xxx" /n:"xxx" /v:"xxx"
dotnet build xx.sln --configuration Release
dotnet sonarscanner end
my current setup is:
Jenkins Server running on Amazon linux, on which i have installed jenkins (version 2.150.2) dotnet core and the sonarqube msbuild plugin
[jenkins#jenkins_qa sonar]# dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.2.104
Commit: 73f036d4ac
Runtime Environment:
OS Name: amzn
OS Version: 2
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/2.2.104/
Host (useful for support):
Version: 2.2.2
Commit: a4fd7b2c84
.NET Core SDKs installed:
2.1.4 [/usr/share/dotnet/sdk]
2.2.104 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
sonarqube server is installed on an Amazon Windows Instance.
I would like to use the plugin to run the analysis as this will include the report on the jenkins ui.
Thanks in advance

Categories