I have inherited a .NET Framework 4.8 application that I'm able to compile using Visual Studio, however when trying to compile it using the dotnet
CLI Application I get CS0246 errors for all types I use from external dependencies.
The original error message, sorry for the German:
Archiver\Archiver.cs(2,7): error CS0246: Der Typ- oder Namespacename "log4net" wurde nicht gefunden (möglicherweise fehlt eine using-Direktive oder ein Assemblyverweis).
When running dotnet --list-sdk
I get the following output:
3.1.301 [C:\Program Files\dotnet\sdk]
5.0.402 [C:\Program Files\dotnet\sdk]
I've tried reinstalling and repairing the .NET Framework 4.8 multiple times but that didn't fix anything.
What do I need to do make the CLI realize where the framework is and hopefully fix my error?
CodePudding user response:
You can't. It's complicated, see below.
dotnet
is the CLI for .NET Core/.NET 5 and higher. It has never been compatible with .NET Framework .csproj projects and never will be. (It's complicated, see below.)
The answer you're looking for is basically: To build your .NET Framework project/solution from the command line, use MSBuild (or if you really, really, really have to use Visual Studio, devenv
).
You may be able to build a new, "SDK-style" project that targets net48 or similar. These projects were introduced with .NET Core and most .NET Framework projects in the wild are not of this type. To my knowledge, no template in Visual Studio produces them for .NET Framework projects since they haven't been built for it. For example, when using the Entity Framework NuGet package in one, the tooling is not installed and integrated the way it usually would be, since NuGet is integrated entirely differently between .NET Framework csprojs and "SDK-style" csprojs. If you have a project of this type, chances are you either a) created a .NET Standard project, b) created a .NET Core project and made it also target net48
, or c) created an SDK-style csproj more or less by hand.
In any case, there is no SDK for dotnet
to target .NET Framework, and it does not know what to do with .NET Framework-based Web Sites, ASP.NET csprojs, WPF/Windows Forms csprojs, Class Library csprojs and so on.