In order to use Serilog I had to install multiple Nuget packages to a project. My WPF app has multiple dlls. Should I install all required Nuget packages of serilog to all projects in my solution? Also in general if my solution that has multiple projects, having common Nuget project dependencies, whether Should I install it in all projects or there is any other procedure of implementation.
My app is .Net Framework 4.6 app.
Given you're targeting .NET Framework 4.6, I'm assuming you intend to use Serilog's ILogger to write logs.
In that case, you need to install the package Serilog in all projects that will write to the log. This package is where ILogger is implemented, which your projects will need.
All other packages (sinks, enrichers, etc.) need only to be installed on the project that actually configures the log (in your case, the WPF project).
Related
I need to migrate a .NET Core 3.1 C# project to .NET 6. The .NET Core 3.1 project uses the analyzers Microsoft.CodeAnalysis.NetAnalyzers and Microsoft.CodeAnalysis.CSharp.CodeStyle as NuGet packages.
For Microsoft.CodeAnalysis.NetAnalyzers Microsoft clearly states that it is not needed as a NuGet package anymore. https://github.com/dotnet/roslyn-analyzers#microsoftcodeanalysisnetanalyzers:
You do not need to manually install this NuGet package [Microsoft.CodeAnalysis.NetAnalyzers] to your project if you are using .NET5 SDK or later. These analyzers are enabled by default for projects targeting .NET5 or later.
What's not so clear to me is whether the Microsoft.CodeAnalysis.CSharp.CodeStyle NuGet package can also be abandoned. Some things I read and manual tests suggest that adding <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> to the project file is sufficient. However, I found no specific confirmation for this.
Can someone confirm or correct and ideally shed some light on the relationship between Microsoft.CodeAnalysis.CSharp.CodeStyle and <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>?
How install packages in Net 5.0 runtime of local (or remote) computer, so that will be available for all projects I create, without add explicitly to each project with nuget ?
Ideally each package installed in this way should be reachable just declaring it's namespace.
Example:
the package is Microsoft.Extensions.Configuration.Json
install this way the package
create a console .net application, and I do not add nuget package
use package classes just declaring "using Microsoft.Extensions.Configuration"
Hope there is a way to do this
This can't be done. It would quite quickly become unusable when different projects needs different versions of these packages (like when you start a new .Net 6 project in the future and all old projects want the .Net 5 assemblies).
What you could do however is to create your own meta package with your default list of packages, that way you would only need to install one package to your new projects which would then include all the ones you want.
How to create meta package (package of all packages) like Microsoft.AspNetCore.All in nuget?
I have created a Nuget package on a private Azure Artifacts environment, that houses a custom configuration for StyleCop.Analyzers so that the configuration for coding standards can be centralised. This all works absolutely fine and can be installed in other projects with no issue.
I have a separate class library which is being built into a Nuget package, and this project utilises my custom StyleCop package. This package also builds correctly, but in the list of dependencies is my custom StyleCop.Analyzers package. This means that everywhere the class library gets installed, the custom StyleCop.Analyzers package will be installed as well. I don't feel this is correct as it is purely a development-scoped package and should not be included as an actual dependency.
The class library does not feature a .nuspec file, everything is handled through the .csproj and some Azure Pipeline's wizardry. Is the dependency chain correct, or is there something that can be done to ensure that the custom StyleCop.Analyzers package is not listed as a dependency?
Turns out if you add <devDependency>true</devDependency> node to the .nuspec file then the dependency does not get shipped to packages that consume it.
I have an old project that runs on ASP.NET Core 2.1. The project has dependencies folder in which we have
assemblies
packages(nuget packages)
SDK
I am little bit confused by their usage and what does dependencies folder mean.
As far I know
assemblies are .net libraries that referenced into this project and it has a global scope in solution and cant be update until you manually update them.
nuget packages are installed using nuget package manager and are managed and updated when a new update but nuget package has only project scope.
sdk is like a set of tools that is used same like nuget package I think.
Here is the screenshot showing the dependencies format
.net core class library 2.1 Dependecies image
Another thing is that I am creating a new project when I add .net core class library. I have dependecies folder but it's missing
assemblies
packages(nuget packages)
SDK
but it has a new folder called framework
.net core 3.0 class library dependency image
I think I have to manually add these packages in my project. And what's the difference between these three?
Assemblies:- When we compile our source code then assembly gets generated in Visual Studio. Assembly consists of two parts Manifest and IL(Intermediate Language). Manifest contains assembly metadata means assembly's version requirements, security identity, names and hashes of all files that make up the assembly.
Packages:- A package is a container for the definitions of UML elements such as classes, use cases, and components. A package can also contain other packages. In UML Model Explorer, all the definitions inside a package are nested underneath the package.
Nuget Packages:- NuGet packages are pre-defined pieces of code which are reusable for other developers. You can add a NuGet package to your project and use it's functionality wherever you want in your project. We can also say that NuGet behaves like a platform, where developers can create and share code with the world.
SDK:-A SDK(software development kit) is a collection of APIs(Application Programming Interface) that you can reference as a single item in Visual Studio. The Reference Manager dialog box lists all the SDKs that are relevant to the project. When you add an SDK to a project, the APIs are available in Visual Studio.
Packages can not be added manually
here is the link in which it's been clearly explained how to add packages in visual studio:-
https://learn.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio
I'm moving over a project to make it into a nuget package. The project has preprocessor directives in it to check which custom build configuration the developer is in. If they are in Build config A then it pulls A service settings, if they are in B, then it pulls B's settings. The problem is when I package this service up and the nuget package is being used in a separate process with the same build configuration it doesn't respect the devs build configuration choice because the nuget has been compiled with whatever setting it was built in. We have set it up into 3 dlls in a single nuget package.
Is there a way to choose which nuget dll it uses based on the custom build configuration without modifying the csproj code?
Is there a way to choose which nuget dll it uses based on the custom build configuration without modifying the csproj code?
This is not supported as far as I am aware with the NuGet. You can only have one NuGet package with a specific build configurations in a single project's file. Moreover, NuGet now only supports multiple .NET framework versions, not supported multiple configurations.
You can have different NuGet packages if you have different build configurations. This project is specific use by library authors who have platform specific projects that need different NuGet packages.
Besides, It may be simpler to not use NuGet to add the assemblies to your project. Just use NuGet to pack the package with multiple dlls file, then directly reference the assemblies you need with conditions.