Im doing a project with .net Framework , but to run on the linux i need .net Core..
I heard that it is possible to change .net Core to .net Framework only with changes on the project.csproj with this:
<TargetFramework>netcoreapp1.1</TargetFramework>
to
<TargetFramework>v4.5.2</TargetFramework>
and i tried to do the opposite , but i got some erros on the project...
There's a way to do that?
Thanks!
You can not switch a .NET Framework project to .NET Core that easy.
You might change an empty project but not one you already started coding.
Possibly you'll need to rewrite or start from scratch.
There are some major differences between two
Format of configuration files (web.config vs appsettings.json)
See this post on providing backward compatibility for App.config, appSettings.config and Web.config XML-based configuration providers
Used libraries
Startup files (Global.asax vs Startup.cs)
Lack of static objects in .Net Core. Like Session and Application objects -
which is a good thing btw.
Many of the .Net Framework libraries are dependant on
app.config/web.config files
Related
I'm pulling my hair here. I can't seem to run two projects under the same solution where one uses .NET Core 6 and the other uses .NET Framework 4.7.2
I have set the MSBuild to Auto detect and this allows the .NET Framework project to run, but for some reason the .NET Core project appears with missing dependencies (can't read the symbol System) and then I get this error as well:
MSBuild cannot find TargetFramework assemblies for .NETFramework,Version=v6.0.
If I change the MSBuild, then .NET Core works and .NET Framework doesn't. Can't seem to get them to work together simultaneously. Any suggestions?
I have a solution with multiple projects, the notable projects are:
ContractProject
DataProject
WebProject
WebProject is a .NET Core project, the other two are .NET Framework.
This is the file structure, including the csproj and sln files:
DataProject references Dapper, which is a NuGet package.
When attempting to run the build configuration in TeamCity, I get the following (slightly reduced, redacted) error:
DapperWorklistRepository.cs(4,7): error CS0246: The type or namespace name 'Dapper' could not be found (are you missing a using directive or an assembly reference?) [REDACTED_PATH_TO_DATAPROJECT_CSPROJ_FILE]
......
Build FAILED.
......
Process exited with code 1
Step Build (.NET Core (dotnet)) failed
This is my only build step (.NET Core):
Any idea what I'm doing wrong? I have a feeling it may be something to do with the web project not being able to reference the projects one level back? I have tried setting the required paths in many different ways with no avail.
I ended up figuring this out, implementing a bit of a hack of a solution.
The problem lies in the fact that I'm referencing .NET Framework projects from a .NET Core project, and attempting to build them all in one step.
The work around required two things:
Firstly, I had to include a NuGet installer build step. I couldn't figure out how to target specifically .NET Framework projects (it doesn't support .NET Core), so I essentially duplicated the solution file, renamed it to NetCoreBuildHelper, and deleted the Web project reference. The reference remained in the original solution. I then referenced the new NetCoreBuildHelper solution in the NuGet Installer.
Secondly, I had to create a .NET Framework MSBuild step, which built the other projects (DataProject and ContractProject), referencing the NetCoreBuildHelper solution.
I'd love to hear responses to this if I could improve the solution, as it feels like a bit of a hack
This question is on the older side - but I'm interested in knowing if you arrived at any more information.
To the best of my knowledge, .Net Framework and .Net Core are fundamentally different platforms, so they are not meant to be referenced by one other. .Net Standard projects however, are intended to be a vehicle for code sharing that both .Net Core and .Net Framework can reference, as long as the Standard version being targeted is the correct version. For example, .Net Framework 4.8 is, at most, .Net Standard 2.0 compatible. If the .Net Framework projects were class libraries, it might be worth migrating those to be .Net Standard projects, and reference them from your .Net Core project.
I started a web project with .net core 2.1 and it works just fine.
But now a vendor says his server side component only works with .net 4.6.1
Can I now change the target framework on the project to 4.6.1 without rewriting the app?
The component helps export data to PDF and Excel, and uses many of the Standard Libraries. So I am at a loss on how to integrate this.
One idea is to create a separate API server that is on 4.6.1, for just the data export but the issue with that is security - the end user is logged into Server A, not Server B, so there are now security issues to deal with.
Maybe calling server B directly from Server A would be possible so I know the person is logged in, then returning the result back to the end user from Server A.
NOTE:Edit to 4.6.1 from 4.7.2 in the above in case that makes any difference.
Yes you can. Simply follow this here
Pulling code from the Stackoverflow link, you simply modify the .csproj file to suit your needs to the .NET Standard lib you're targeting.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
</PropertyGroup>
</Project>
By judging from the documentation provided by Microsoft and by a 3rd party service, you're advised to target .NET Standard for your .NET Core project in order to maximize compatibility with your vendor first. From there, you may most likely one to deploy a second server that completely targets .NET Core to roll out functions with modern APIs.
Take note that .NET Core 2.1 targets 4.6.1 onwards meaning that you will be writing a project that is unable to support anything older than that.
I want to note that the easiest way to run .netcore on the full .netframework is to start with such a project.
You can select .netcore/.net framework when you create the project. This will select all the correct libs for you to get started. Switching midstream can be done, but it takes fiddling with the libs to get the correct versions.
I Have a solution which contains the bunch of class libraries which is developed by .Net framework 4.6.2. I have to convert those class libraries into .Net core. Is there any best and fastest way to convert instead for rewrite the code.
This appears to be an official Microsoft resource for doing the migration. Summarized below:
(recommended) Retarget all projects you wish to port to target the .NET Framework 4.7.2 or higher.
(recommended) Use the .NET Portability Analyzer to analyze your assemblies and see if they're portable to .NET Core.
(recommended) Install the .NET API analyzer into your projects to identify APIs throwing PlatformNotSupportedException on some platforms and some other potential compatibility issues.
Convert all of your packages.config dependencies to the PackageReference format with the conversion tool in Visual Studio.
Create new projects for .NET Core and copy over source files, or attempt to convert your existing project file with a tool.
Port your test code.
Most of BCL is still the same API-wise, so conversion is definitely viable for consideration. Yes, there may be incompatibilities in your code (or more often - with your dependencies) and the easiest way to check is to try building it with .net core.
For more details about when to convert (and when to rewrite) or about options of performing the conversion you could follow this guide: Upgrading to .NET Core and .NET Standard Made Easy.
The easiest way to switch a .net framework project to a .netcore project is to open the csproj file and change the TargetFramework from something like this
<TargetFramework>net462</TargetFramework>
to something like this
<TargetFramework>netcoreapp3.1</TargetFramework>
You could also change it to .net standard, in case you want compatibility between .net core and .net framework consumer projects, by changing it to this:
<TargetFramework>netstandard2.0</TargetFramework>
You could target multiple frameworks like so:
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
Ensure you use the correct version number and obviously depending on what this project already targets, things are going to break and will need fixing. For example, you can't use a .net framework class library with a .net core project.
A more detailed process is provided here:
https://learn.microsoft.com/en-us/dotnet/core/porting/
I just ran into the same error that you saw (as per your comment to #ImrePĆ¼hvel) when I was trying to migrate a CLI project from .NET Framework to netcoreapp3.1:
"The expression "[Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries(_, netcoreapp3.1, '', x64, '', '')" cannot be evaluated. Input string was not in a correct format. C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets"
In my case, it was due to a misreading of the instructions.
The old framework had a tag:
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
This needs to be changed to:
<TargetFramework>netcoreapp3.1</TargetFramework>
NOT
<TargetFrameworkVersion>netcoreapp3.1</TargetFrameworkVersion>
I had simply changed v4.5 --> netcoreapp3.1 in the TargetFrameworkVersion tag without changing the tag name to TargetFramework.
So double-check that you changed:
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
to
<TargetFramework>netcoreapp3.1</TargetFramework>
(or whatever .NET Core version you want)
and NOT:
<TargetFrameworkVersion>netcoreapp3.1</TargetFrameworkVersion>
I was looking for possibilities for porting some web projects from Windows .NET framework to Ubuntu linux using open source .NET core
After a lot of struggle with Mono, which I have almost gave up. I was looking at .NET core as a new hope. Have anyone of us ported from .NET to .NET core?
If yes, can the possible problems like the ones I faced with Mono be shared?
Moving from .NET to .NET Core is a huge move, especially if you're going to take advantage of Core. There is not currently a one click port, and I doubt you'll ever get a one-click migration like migrating from a VS 2013 project to a VS 2015 project. The entire startup flow is different, and to automate switching to that would be incredibly difficult. For now, the way I am looking at it is that moving to .NET Core is essentially a rewrite. As to whether that is worth it to you for your project - well that's really hard to say and also probably not well suited to that site.
That said, if you do rewrite you can probably bring along a lot of your business logic. You just will need to redo a lot of the other structure.
There's no easy way to move a project from .NET Framework to .NET Core. Possibly you'll need to rewrite or start from scratch.
There are some major differences between two
Format of configuration files (web.config vs appsettings.json)
Used libraries
Startup files (Global.asax vs Startup.cs)
Lack of static objects in .Net Core. Like Session and Application
objects - which is a good thing btw.
Many of the .Net Framework libraries are dependant on
app.config/web.config files