I am developing on a Windows 11 machine and I have a .NET 6 Swagger WebApi solution that references .Net Framework 4.7.2 project (due to migration reasons it has to stay fw472).
I dockerized the api solution and deployed it into a Linux container locally on my machine. To my surprise I was able to browse the Swagger api and trigger a rest endpoint that uses the fw472 library which successfully returned the results.
My question is how does .Net 6 solution support using a .Net 472 class library when it is deployed into a Linux container?
Related
I have a .net 5 web api that consists of a solution with most of projects being .net 5, but two of them are .net framework (v 4.7.2).
The web api works fine when I run it, and referring to .net framework projects is not a problem.
Now I am trying to upload this solution to azure app service using Github actions. The build step works fine, but when publishing, I get the following error:
C:\Users\runneradmin\AppData\Local\Microsoft\dotnet\sdk\5.0.202\Microsoft.Common.CurrentVersion.targets(4288,5):
error : MSB4803: The task "FormatUrl" 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. [path
to my .net framework .csproj]
I am trying to avoid updating the project to .net 5. Is there a way to configure my github actions to be able to publish .net framework projects as well?
So the web server i am using right now is a Apache web server which runs ASP.Net on mono but i can't seem to get a project up and running on the mono ASP.Net server as it all ways just lists the directories within the folder
I tried creating a ASP.Net project uploaded it didn't work
I tried creating a MVC project and uploading it, also did not work
I tried creating a project on a .net framework 4 and uploaded it but still no luck
I've run of out of ideas how to get this to work, is there i special way i should be compiling the project? or is there a specfic version of .net i should use, as the mono ASP.NET version says 4
Mono is a linux based runtime like the .NET framework is a windows based runtime. You don't have "mono ASP.NET web projects" - you have "ASP.NET web projects" that run on .net framework in windows or mono (maybe) in linux.
What I'd actually recommend you do is create a .net core site if this is a new project; microsoft provide core for windows and linux so it should be easier to get started developing something that compiles and runs on windows, and then is either transported compiled to linux or recompiled there.
Note that your apache (if you're dead set on using that) will probably need to be configured as a proxy so that it forwards requests through to Kestrel, which is hosting your app. Apache doesn't natively understand .NET anything, and will just see a .NET application as a bunch of folders and files
I have an ASP.NET WebAPI 2 application on .net 4.7
I add a Microsoft.Azure.ServiceBus nuget which has dependencies on .NET Standart
2.0
When I run my app locally on IIS Express inside VS2017 everything works fine.
When I deploy my app to Azure Web App I receive an error on any REST request
Method not found: 'System.Web.Http.Controllers.HttpRequestContext System.Net.Http.HttpRequestMessageExtensions.GetRequestContext(System.Net.Http.HttpRequestMessage)'
As far as I understand there is different version of System.Web.Http on Azure web app and on my dev machine.
Why this happens and what should I do to fix this?
I want to create an ASP.NET Core MVC 2 web application which I could host on Linux and Windows (i.e. in both OS). So, I am to use .Net Core. But when I create new ASP.NET Core MVC 2 web application I see two comboboxes. At first I am to select either .NET Frmework or .NET Core. The second combobox contains only ASP.NET Core 2.0.
Q1:
Does it mean that ASP.NET Core 2.0 is technology which is implemented in both frameworks (.Net Framework and .NET Core)?
It is impossible to switch .Net Framework to .NET Core for such project later. I could use .NET Core but here Microsoft writes that I am to use .NET Framework if I want to use Windows Service...
I want to use Nginx for Windows on my computer (instead of IIS) - it is interesting for me to try it. :) Here Microsoft describes how to host ASP.NET Core web application on Linux with NGinx. At the article the Create the service file topic exists. But it is for Linux... So, if I want to host my ASP.NET Core MVC 2 web application on Nginx in Windows then I am forced to use Windows Services (look here). But in the Host an ASP.NET Core app in a Windows Service article Microsoft writes that I am to use .NET Framework instead of .NET Core...
Q2
Does it mean that I can't the same project use for build my web application for Linux and Windows (for Windows Service)? Does it mean that for my goal I am to create two project: for .NET Framework and for .NET Core and to share the code sources for both projects?
Q1
Does it mean that ASP.NET Core 2.0 is technology which is implemented
in both frameworks (.Net Framework and .NET Core)?
.NET Core 2.0 and .NET Framework 4.6.1 are both implementations of .NET Standard 2.0. What this means is that they can both do the same things, and work mostly the same, but .NET Framework contains some Windows only libraries (System libraries such as Windows Forms) that mean it can only run on Windows. .Net Core programs can run on Windows, Linux and MacOS.
It is impossible to switch .Net Framework to .NET Core for such
project later. I could use .NET Core but here Microsoft writes that I
am to use .NET Framework if I want to use Windows Service...
While this is technically possible, you really want to avoid it. It's a huge headache, and usually breaks a lot of your code, with missing dependancies etc.
I want to use Nginx for Windows on my computer (instead of IIS) - it
is interesting for me to try it. :) Here Microsoft describes how to
host ASP.NET Core web application on Linux with NGinx. At the article
the Create the service file topic exists. But it is for Linux... So,
if I want to host my ASP.NET Core MVC 2 web application on Nginx in
Windows then I am forced to use Windows Services (look here). But in
the Host an ASP.NET Core app in a Windows Service article Microsoft
writes that I am to use .NET Framework instead of .NET Core...
I haven't personally used NGinx for Windows, but it looks as though they want you to set the target version for your NET Core app to NET Framework for the purposes of their example. Since .NET Core doesn't have the references to System specific libraries, you can easily change target to NET Framework. This doesn't make it a NET Framework project, it just changes the runtime against which Visual Studio will build it.
Q2
Does it mean that I can't the same project use for build my web
application for Linux and Windows (for Windows Service)? Does it mean
that for my goal I am to create two project: for .NET Framework and
for .NET Core and to share the code sources for both projects?
You can absolutely use the same application for both platforms, however it'll be a little different to how you're used to it. Since .NET Core is platform agnostic, Visual Studio won't generate an exe for you, it'll just generate dll files. You then use the dotnet command at the command line to start the program, e.g.
dotnet helloWorld.dll
This is how you run the program on any OS, provided you have the .NET Core runtime installed (There are plenty of guides on how to do this online).
Hope I've answered everything clearly :)
With the release of .NET Core RC2 Microsoft made it so there are now 3 Web Application templates:
ASP.NET Web Application (.NET Framework) — The old
ASP.NET Core Web Application (.NET Framework) — the new, to be hosting on Windows only
ASP.NET Core Web Application (.NET Core) — Linux, OSX, Windows
I am trying to use the new Core Web Application template but without trying to target Linux, OSX, Windows so it seems like the ASP.NET Core Web Application (.NET Framework) is perfect for me. It took me a while but I learned that in order to add a class library that will work with this project type you need to add a Class Library (.NET Core) and change the frameworks section to only be net461 to match the Web Application.
"frameworks": {
"net461": { }
}
My Question:
What is the difference between creating an ASP.NET Core Web Application (.NET Core) and in project.json making net461 the only target framework
and
just creating an ASP.NET Core Web Application (.NET Framework) project which only includes net461 by default.
Are there other differences that I am not aware of like the way the projects are published, etc.?
What is the difference between creating a ASP.NET Core Web Application
(.NET Core) and in project.json making.NET461 the only target
Framework
It's the same thing as making an ASP.NET Core Web Application (.NET Framework) project. The type of project between the two is determined by the .csproj file and you changed it in your .csproj from targeting .NET Core to targeting the .NET Framework. In previous release/beta versions of ASP.NET Core it was possible to have both Frameworks in a project.json file (which has been replaced by a simplified .csproj file in .NET Core 2.0 which more .NET developers are familiar with) but you could only publish to one.
just creating a ASP.NET Core Web Application (.NET Framework) project which only includes.NET461 by default.
Are there other difference that I am not aware of like the way the the projects are published, etc
If you target the .NET Framework and not .NET Core your app cannot be cross platform and your app can only run on Windows and not Linux/Mac.
The reason for there being separate ASP.NET Core Web Application (.NET Core) and ASP.NET Core Web Application (.NET Framework) is because the latter allows you to make use of functions, packages or 3rd party libraries that are dependent on Windows and the same .NET Framework or higher will be required to be installed on the machine.
The former doesn't have the .NET Framework requirement but allows your app to be cross platform and when you publish your app it publishes all the dependent .NET Core dll files to the publish directory in that way circumventing the .NET Framework installation requirement.
It will also affect compilation as if you target .NET Core and make use of a Windows specific function or package you will get a compilation error.
You can easily switch between the two by adjusting your .csproj to target the one or the other.
Microsoft Docs
You should use .NET Core for your server application when:
You have cross-platform needs.
You are targeting microservices.
You are using Docker containers.
You need high performance and scalable systems.
You need side by side of .NET versions by application.
You should use .NET Framework for your server application when:
Your application currently uses .NET Framework (recommendation is to extend instead of migrating)
You need to use third-party .NET libraries or NuGet packages not available for .NET Core.
You need to use .NET technologies that are not available for .NET Core.
You need to use a platform that doesn’t support .NET Core.
Update (2018/10/30)
It has been announced that ASP.Net Core 3 which has a release date in 2019 Q1, will only support .NET Core and NOT .NET Framework
As announced on the .NET Blog earlier this month, .NET Framework will get fewer of the newer platform and language features that come to .NET Core moving forward, due to the in-place update nature of .NET Framework and the desire to limit changes there that might break existing applications. To ensure ASP.NET Core can fully leverage the improvements coming to .NET Core moving forward, ASP.NET Core will only run on .NET Core starting from 3.0. Moving forward, you can simply think of ASP.NET Core as being part of .NET Core.
Customers utilizing ASP.NET Core on .NET Framework today can continue to do so in a fully supported fashion using the 2.1 LTS release. Support and servicing for 2.1 will continue until at least August 21, 2021 (3 years after its declaration as an LTS release) in accordance with the .NET Support Policy.
First see the difference in project.json files when you create ASP.NET Core Web Applications targeting different frameworks.
As per your question, if you change the framework in ASP.NET Core Web Application(.NET Core) project.json only to have net461 and save, it'll restore the packages and will give the following error.
If you remove Microsoft.NETCore.App dependency and saves the file, It'll again restore the dependencies and won't give any error.
If you notice the first image, this has finally become a ASP.NET Core Web Application with .NET Framework.
I was confused at first as well. The main difference is that ASP.NET Web Application (.NET Framework) is the normal asp.net that we have been using. It contains App_Start folder web.config, Global.asax etc.. (Like MVC5,You get the idea..).
Whereas ASP.NET Core Web Application (.NET Framework) is a core framework(MVC6). (Not dependent on System.Web). Brand new project.json.. startup.cs and program.cs etc... And it supports all the old libraries of .net framework as well.
with .net core, you can run your web pages application in Linux or mac os whereas the .net will only be good for windows, i.e. less portable.