im building an app using c# (not my first. other projects i dont have this problem). this one i included nuget package json
the problem that VS generates too many .dll files in my bin/debug folder (with exe). i don't want these dll files but it seems like the exe doesn't run without them (i coppied the exe to another path and run it)
when i search on the internet all the details about merging using some merge tool but my problem is related VisualStudio in the setting i believe?
This happens when you include a library which targets .NET Standard 1.5 or higher, from a project which targets .NET Framework 4.7.1 or lower.
The .NET Platform Standard table hints at this: it claims that .NET Framework 4.6.1 supports .NET Standard 1.5 or higher, but there's a footnote:
The versions listed here represent the rules that NuGet uses to determine whether a given .NET Standard library is applicable. While NuGet considers .NET Framework 4.6.1 as supporting .NET Standard 1.5 through 2.0, there are several issues with consuming .NET Standard libraries that were built for those versions from .NET Framework 4.6.1 projects. For .NET Framework projects that need to use such libraries, we recommend that you upgrade the project to target .NET Framework 4.7.2 or higher.
One of these issues is that you'll get a lot of extra DLLs, apparently because .NET Framework 4.6.1 only has partial support for .NET Standard 1.5.
The solution is for your project to target .NET Framework 4.7.2, or .NET Core.
Related
I want to create a Nuget Package for a C# library that targets .NET Framework 4.0 and higher.
If I put my library in a directory named Net40, will this cause issues for projects that target say 4.1 and higher?
Should i just publish my library in a lib folder without specifying the supported .NET Framework version?
My library supports .NET Framework 4.0 and higher.
The reason why I am asking is that sometimes projects get messed up quickly when they target a different platform whilst the installed libraries via NuGet target another platform version. At least I want to avoid issues when developers target 4.0 and higher.
I hope your advice will be very helpful.
The question is stupid enough, but it didn’t work with NuGet before. After installing the NuGet package through the console, to connect to PostgreSQL, files appeared that NetFramework should contain. Without copying these files, the project does not start. What to do to get rid of them and not copy them to the directory with the program. In my understanding, these files should be taken from the framework.
See screenshots:
All need files in project C#
My guess is that you have .Net Standard 2.0 libraries/dependencies in your project.
.NET 4.6.1 might add additional runtime dependencies in your output folder:
.NET 4.6.1, 4.6.2, .NET 4.7 and 4.7.1 all have partial .NET Standard
2.0 support in the natively shipped runtimes, but they still are .NET Standard 2.0 compliant by adding additional runtime dependencies into
your output folder to provide the missing functionality. NuGet along
with the runtime targeting handles automatically adding those
dependencies to your projects to provide the needed runtime support
for those extra features. A lot of those assemblies override behavior
from the base framework and .NET uses runtime redirects to route api
calls to the appropriate assemblies rather than than mscorlib.dll or
other system assemblies.
.NET 4.7.2 is the first version of the full .NET Framework that is
fully .NET Standard 2.0 compliant without any additional dependencies.
See: https://weblog.west-wind.com/posts/2019/Feb/19/Using-NET-Standard-with-Full-Framework-NET
In other words, targeting .NET 4.7.2 should get rid of the additional files.
Recently I started learning how to create Dynamic Link Libraries in Visual Studio with C#.
I followed online instructions on how to create DLLs:
https://learn.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio
http://www.c-sharpcorner.com/UploadFile/1e050f/creating-and-using-dll-class-library-in-C-Sharp/
https://blogs.msdn.microsoft.com/benjaminperkins/2017/04/13/how-to-make-a-simple-dll-as-an-assembly-reference-just-for-fun/
After completing these steps, I tried to add my .dll file to my projects.
On execution I receive this message:
System.IO.FileNotFoundException: 'Could not load file or assembly
'MySql.Connect, Version=1.0.0.2, Culture=neutral, PublicKeyToken=null'. The
system cannot find the file specified.'
I selected .NET Framework 4.6.1 when I started my project. The target framework in the Properties file under the Application tab is selected as .NET Framework 2.0.
The project that should reference to the file is targeting the .Net Core 2 Framework.
I've been at this problem for nearly a week and searched for online solutions.
Any help will be greatly appreciated.
You need to put the DLL somewhere that the runtime can find it. The easiest thing to do would be to put it in the same directory as the .exe, but you have other options as well (see How the Runtime Locates Assemblies).
It is important to carefully decide what platform you intend to use your DLL with.
I selected.NET Framework 4.6.1 when I started my project.
If you mean when you started your DLL project, then you have limited the types of applications that can consume this DLL to .NET Framework 4.6.1+.
Properties file under the Application tab is selected as .Net Framework 2.0.
If I understand correctly, you changed the DLL target from .NET Framework 4.6.1 to .NET Framework 2.0. This widens the compatibility so that the consuming library can be .NET Framework 2.0+. However, this is at the expense of all of the newer features of the .NET Framework.
Do note that official support (i.e. patches) for .NET Framework 2.0 has been gone for several years, and newer machines aren't likely to have it installed.
The project that should reference to the file is targeting the .Net Core 2 Framework.
Here's the crux of your issue. .NET Core ain't .NET Framework. It is a completely different platform.
That said, .NET Core has some limited support for referencing .NET Framework assemblies, but is it sure not to work with .NET Framework 2.0 (which again, hasn't been supported in years). Also, this "compatibility mode" probably means you lose cross-OS support, which is one of the main benefits of .NET Core.
Option 1
So, the knee jerk answer is to make your DLL target .NET Core if you want to use it with .NET Core applications.
Option 2
However, there is also an option to make a portable DLL that works with .NET Framework 4.5+ and .NET Core - make your DLL target .NET Standard.
See How to port from .net framework to .net standard for instructions on changing your DLL to target .NET Standard.
.Netstandard2 is released final with .Net Core 2.0 and vs2017.3 with nuget4.3 and API surface cover 32k (except 41 class) and full cover net461
Quoting from Announcing .NET Core 2.0
You can now reference .NET Framework libraries from .NET Standard libraries using Visual Studio 2017 15.3. This feature helps you migrate .NET Framework code to .NET Standard or .NET Core over time (start with binaries and then move to source). It is also useful in the case that the source code is no longer accessible or is lost for a .NET Framework library, enabling it to be still be used in new scenarios.
We expect that this feature will be used most commonly from .NET Standard libraries. It also works for .NET Core apps and libraries. They can depend on .NET Framework libraries, too.
The supported scenario is referencing a .NET Framework library that happens to only use types within the .NET Standard API set. Also, it is only supported for libraries that target .NET Framework 4.6.1 or earlier (even .NET Framework 1.0 is fine).
So, in .netcore2 environment we can continue build/use Full .Net Framework as we did many years without the need to switch to .netstandard2 libraries.
With multi target project ,(net64;netstandard2), we get .net standard 2.0 out of box free (zero time effort) with the same API coverage.
Can you share your experience regarding: Can we continue build Full Framework 4.6.1 class library and use it in .netcore2? what is the limitation?
When you build a .NET Framework library, you can only use 4.6.1 with .NET Standard. If you want to use a newer API that is in e.g. netstandard2.0 or .NET 4.7, you'd need to retarget your library to 4.7, which then cannot be used by netstandard2.0 / netcoreapp2.0 projects. Effectively, you are locked into .NET Framework version 4.6.1 and can (/should) never update it to a newer version. (Of course, there is a workaround involving disabling the implicit fallback definition and manually setting AssetTargetFallback in the consuming project, but it requires manually editing the .csproj file and instructing all package consumers to do so).
Furthermore, the compatibility layer does not protect against using APIs that are not implemented on netstandard so a consuming project may get exceptions about missing types, methods, assemblies etc. Only when you target .NET Standard, your library is guaranteed to work on .NET Standard conformant platforms.
A practical limitation currently is that referencing .NET Framework library projects(!) (not NuGet packages) from .NET Core is not possible / only works with specific setups and workarounds (you will get an incompatible target framework warning).
Our development team has many .net framework 4.6 projects (VS 2015).
We want to start a new .net core project to eventually deploy on linux.
We have installed VS 2017 and the .net core 2.0 preview.
But how can we reuse the existing library projects in this new one ?
We research but it is not clear for us :
- we need to change the target of the old projects from ".Net Framework 4.6" to ".NetStandard 1.x" ? (and solve the incompatibility)
- or we can use them like that ? (but how?)
Thanks
Microsoft publishes official guidelines for the porting process: https://learn.microsoft.com/en-us/dotnet/articles/core/porting/
To summarize:
Deal with your dependencies (by migrating them), recursively
Retarget your projects. Applications move to .NET core, libraries move to .NET Standard, where possible.
Use some helpful tooling to verify your ports
Test
So, to share things between .NET Framework and .NET Core, your libraries should target .NET Standard, as much as possible. Otherwise, you could possibly share the code and have to do multiple builds - build once targetting .NET Framework and again targetting .NET Core.
You can use/reference your old projects only if you target Full Framework in your new projects (which is not the case if you are going to run them on Linux).
If you started with preview you should convert you old projects to .Net Core projects and either target .NET Core 2.0 Preview or NetStandard 2.0 Preview. If you are not going to reference/use your old projects outside your application it might be better to target .NET Core 2.0 Preview because it might provide more API than NetStandard 2.0 Preview.