Publishing ASP.NET Core Applications on linux nginx server - linux

When publishing an ASP.NET Core application to a Linux server running nginx, is it necessary to install the .NET Core runtime on the server?

One of the options when publishing a .NET Core application is self contained deployments which include a version of the .NET Core runtime.
They are described (in the above link) as:
For a self-contained deployment, you deploy your app and any required third-party dependencies along with the version of .NET Core that you used to build the app. Creating an SCD doesn't include the native dependencies of .NET Core on various platforms, so these must be present before the app runs.
So your target machine will still need to have the libraries that .NET Core relies on, but it's entirely possible to publish you application and not have the .NET Core runtime installed on your target server.
Creating a SCD, you need to make a few changes to your csproj
<PropertyGroup>
<RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers>
</PropertyGroup>
The above would inform MSBuild that you want to target 64 bit Windows 10 and OSX 11.10.
Then you can create a published version of your app for one of those run platforms by running the following commands:
dotnet publish -c Release -r win10-x64
dotnet publish -c Release -r osx.10.11-x64
(the first line creates a SCD for Windows 10 64 bit, and the second does the same for OSX 10.11 64 bit.
Source: Self-contained deployment without third-party dependencies

Related

Running .net core without SDK but with runtime

I have two .net core applications running on Linux.
One of them is happy with .net core runtime while another one is demanding .net core SDK.
I can build both applications using dotnet publish with the following parameters:
dotnet publish Web/Web.csproj -o publish -c Release -r linux-x64 --self-contained false
Both projects target 3.1 (checked .csproj):
<TargetFramework>netcoreapp3.1</TargetFramework>
I am deploying them to the same VM server which has .net 3.1 runtime installed:
.NET Core SDKs installed:
No SDKs were found.
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
However, on start of one of those projects as systemctl service I am getting an error:
It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
https://aka.ms/dotnet-download
While I can successfully start the application manually using dotnet Web.dll
Does my build artifact requires SDK?
Any ideas how can I troubleshoot this behavior?
1- No, it shouln't require SDK
2- Hard to help you with the incomplete question
Have you tried to run the service with SDK installed? To check if that is the actual problem or just a misleading error.
Are you using Systemd integration package by Microsoft?
dotnet add package Microsoft.Extensions.Hosting.Systemd

What steps should I take to build and run .net core Web API application in 32-bit environment/runtime?

We developed an a .NET Core Web API application using the following technologies:
-NET Core (3.1)
-Visual Studio 2019
Unfortunately, we have to deploy said application to the following environment:
-32-bit Environment
-Windows Server 2008 R2 Enterprise (Service Pack 1)
-IIS Version 7.5
-8 GB RAM
Therefore, within my Visual Studio 2019, I brought up the application, and took the following steps:
Force x86 in VS go to the Properties > Build and change Platform target from Any CPU to x86
Created a Directory.Build.targets in the the .NET Core application's Project root directory:
<Project>
<PropertyGroup
Condition="'$(OS)' == 'Windows_NT' and
'$(PlatformTarget)' == 'x86' and
'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
'$(SelfContained)' != 'true'"
>
<RunCommand>$(MSBuildProgramFiles32)\dotnet\dotnet</RunCommand>
</PropertyGroup>
< /Project >
From Visual Studio 2019 Developer Command Prompt v16.4.6, I navigated to the .NET Core application's Project root directory.
I ran:
>
>
dotnet clean
...........................
.............
dotnet build
C:\Program
Files\dotnet\sdk\3.1.101\Microsoft.Common.CurrentVersion.targets(2726,5):
error MSB4216: Could not run the "ResolveComReference" task because
MSBuild could not create or connect to a task host with runtime "CLR4"
and architecture "x86". Please ensure that (1) the requested runtime
and/or architecture are available on the machine, and (2) that the
required executable "C:\Program Files\dotnet\sdk\3.1.101\MSBuild.exe"
exists and can be run.
[D:\ blah blah.csproj]
6 Warning(s)
1 Error(s)
Time Elapsed 00:00:04.63'
Could someone please tell me how I can build and run this application in a 32-bit environment?
What steps should I take to build and run .net core Web API
application in 32-bit environment/runtime?
It is quite strange. First, just as akseli and omajid said, try to install Net Core 3.1 x86 sdk version.
Then, try the following steps:
Steps
1) change build platform target to x86 in 32-bit environment.
2) when you migrate the project into 32-bit environment, please delete .vs hidden folder which exists under the solution folder, bin, obj folder.
3) open Developer Command Prompt for VS2019 in 32-bit environment(it call the msbuild.exe under C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe) to build your project.
4) try to use msbuild rather than dotnet build since MSBuild is more powerful and has a wider range of compilations.
msbuild xxx.csproj -t:build
msbuild xxx.csproj -t:clean
4) or add these node in your xxx.csproj file then build your project
<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Core'">
<GenerateResourceMSBuildArchitecture>CurrentArchitecture</GenerateResourceMSBuildArchitecture>
<GenerateResourceMSBuildRuntime>CurrentRuntime</GenerateResourceMSBuildRuntime>
</PropertyGroup>
Any feedback will be expected.
#akseli #omajid #perry-qian-msft #yongqing-yu Sorry, this failed to work, we had to move away from using .NET Core technology( and had to migrate over to .NET Framework 4.7.2) because it would work properly for a little while, and then give us 500 error, and then later some 401 error. I think it has something to do with the configuration because we are using:
-NET Core (3.1)
-In-Process within IIS Server
therefore, Within the standalone IIS Server, we should Not have to run the .NET Core (3.1) application within it's own application pool as "Not Managed Code" because it's all In-Process and .NET Core (3.1) can run on IIS. In any case, we do Not have time to resolve this problem so we migrate over to .NET Framework 4.7.2
#akseli #omajid #perry-qian-msft #yongqing-yu All Thank you for all your responses.
My Team Tech Lead found the solution by specifying the .NET Core Web API Application's Build Settings to "Any CPU" Within Visual Studio 2019. ( Within Visual Studio 2019, Right-click on .NET Core Web API Application, and then choose properties from the drop-down context menu, and then when the window pane shows up on, you select the Build Tab. )
Also, on the IIS Server, my Team Tech Lead ensured that that deployed .NET Core Web API Application's Application pool had the following settings( important to keep in mind that it is "Not Managed Code":

Simplest way to build dotnet SDK project requiring net461 on MacOS

I have a dotnet SDK .sln (and a build.proj) with <TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>. It builds on Windows using Visual Studio and dotnet build, but I'd also like it to build as many other places as possible. What do I need to put in my README.md and/or what can I put in the project files to make it build on Rider and/or on from bash on a Mac?
(using .NET Core SDK) The simplest way to build for a .NET Framework TFM when running on either macOS or Linux using the .NET Core CLI, is to utilize the .NET Framework Targeting Pack Nuget Packages from Microsoft (currently in preview):
These packages enable building .NET Framework projects on any machine with at least MSBuild or the .NET Core SDK installed.
The following scenarios and benefits are enabled for .NET Framework projects:
Build without requiring admin operations to install pre-requisites such as Visual Studio or .NET Framework targeting packs.
Build libraries on any operating system supported by the .NET Core SDK.
Build Mono-based projects.
You may either include the Microsoft.NETFramework.ReferenceAssemblies metapackage;
or use just the specific package, which is in your case Microsoft.NETFramework.ReferenceAssemblies.net461.
Add the package to the *.csproj or your Directory.Build.props:
<Project>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
Note: The PrivateAssets attribute controls which dependency assets will be consumed but won't flow to the parent project. See the docs.
Update
This is no longer required using the .NET 5 SDK (e.g. 5.0.100), which will now automatically add the PackageReference to the ReferenceAssemblies for .NET Framework.
In order to build via bash on a vanilla Mac, the minimal steps seem to be:
Install Mono 6.0 (5.2 is recommended for VS Mac interop, I dont care about that, and Mono 6.0's interop with Dotnet core is better)
Install dotnet SDK 2.2 (doesn't have to be exactly that, but it works for me)
Put this in a Directory.build.props file (open to improvements if anyone has any)
<Project>
<PropertyGroup>
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))'== 'true'">true</IsOSX>
</PropertyGroup>
<PropertyGroup Condition=" '$(IsOSX)' == 'true' ">
<FrameworkPathOverride>/Library/Frameworks/Mono.framework/Versions/Current/Commands/../lib/mono/4.6.1-api</FrameworkPathOverride>
</PropertyGroup>
</Project>
Bash: dotnet build SolutionFileName.sln should now work
Install Rider 2019.1 or later
Rider: should Just Work (it should autodetect msbuild 16.0 in the build tools section)

Azure .Net core with sql internal server error

I am following microsoft documentation to deploy .Net core with sql. when I go to my website the following is displayed:
An error occurred while starting the application. .NET Core X86
v4.1.1.0 | Microsoft.AspNetCore.Hosting version 1.1.2 |
Microsoft Windows 10.0.14393 | Need help?
When I run the app on local machine there are no errors and I am able to add toDo Items.
In my CsProj file:
<TargetFramework>netcoreapp1.1</TargetFramework>
I have seen other people with similar issue discuss a global.json file, but i do not see any and am not sure if I should create one and what exactly to put in it.
Possibly Related info:
When I push to azure in command line I get this error:
warning NU1701: Package 'Microsoft.Composition 1.0.27' was restored
using '.NETPortable,Version=v0.0,Profile=Profile259' instead of the
project target framework '.NETCoreApp,Version=v1.1'. This package may
not be fully compatible with your project. remote: Restore completed
in 269.7 ms for D:\home\site\repository\DotNetCoreSqlDb.csproj.
the deployment is successful though.
You could try to add the below to the <PropertyGroup> element in your DotNetCoreSqlDb.csproj
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
This is because the Microsoft.Composition 1.0.27 is an old nuget package which does not compatible with the your project target framework which is .NET Core 1.1.
The supported framework for the Microsoft.Composition 1.0.27 is as below:
Supported Platforms:
.NET Framework 4.5
Windows 8
Windows Phone 8.1
Windows Phone Silverlight 8
Portable Class Libraries
Reference: Package Microsoft.Composition 1.0.27 is not compatible with netcoreapp1.1

How to update .NET Core on Azure Web App?

I have my Azure Web App configured to deploy from a local git repository - I just push my changes to the Web App git repo and it builds and deploys the site.
I just updated to my ASP .NET Core site to: "version": "1.0.0-preview2-003133", previously it was 003131 which worked no problems.
I now get the response when doing the git push:
remote: GETSDKTOOLINGINFO : error : The project is configured to use .NET Core SDK version 1.0.0-preview2-003133 which is not installed or cannot be found under the path D:\Program Files (x86)\dotnet. These components are required to build and run this project. Download the version of .NET Core SDK specified in global.json or update the SDK version in global.json to the version that is installed.
I would prefer to update the .NET Core version on my Web App than downgrade, but how?
In case you are wonder how I have 3133 already: https://github.com/aspnet/Tooling/issues/801
You basically can not update the dotnet version on Azure. Currently the version of dotnet that is running is 003131. So you still have to use the previous version.
How are you building your release package?
I had this yesterday using a VSTS build process, when using the 'Visual Studio' build task it will fail with this error currently - changing your process to use the "CMD line" build task and "dotnet publish" allows the build to complete successfully.

Resources