C#, Nuget Can I management Dependency Framework level assemblies? - c#

I'm Nuget packaging with CreateNewNugetPackageWithEachBuild.
Nuget auto installs dependencies another Nuget packages. It works.
But this is not work in Framework libraries like the System.Drawing namespace, UIAutomationTypes assemblies etc.
So when I install my Nuget package, after install that -> and goto "add reference" menu and add framework assemblies manually (System.Security or something, not yet added another DLLs when create project time).
Can I make Nuget pakcages to auto-include the .Net Framework level assemblies when install it?

Make .nuspec file in project folder (be with .csproj file) and define frameworkAssemblies in nuspec file and build it to makes nupkg contains framework level assemblies and auto include when install it

Related

Visual studio references show some libraries not loaded

I have been working maven projects since 2 two years.First of all, I import maven projects to eclipse then
thanks to my pom.xml some dependencies is installed and I see these dependencies on my maven dependencies folder on eclipe project explorer.It connected to my .M2 folder.
Right now , I import a .Net framework project (which is written with C#) in my visual studio program.The solution explorer (references section) show many dependencies(they gives error).Then I found these libraries then I created a folder which is called nugetPackages and I connected my nuget packages manager to that folder(tools/options/nuget package manager/package sources).I reopen my project and libraries on references section does not give any error.My question is where does that libraries names come from ? There are any file like that pom.xml.
I hope I can explain my situation.
Are the libraries (DLLs) that you want to reference in your project NuGet packages or just some framework libraries? If they are Nuget packages they should be described in packages.config file http://prntscr.com/1140xn0 for the classic .NET application (.net framework 4.5 for example) In a .Net Core applications the Nuget packages that are required are defined in the file .csproj file http://prntscr.com/11412iq. In both cases, you can download all required NuGet packages by right clicking on the .sln file and selecting Restore Nuget Packages http://prntscr.com/1140zsk This will automatically create the nugget folder and download all required Nuget packages. If you have manually added dlls you need to navigate to them and select them by right-clicking References - Add reference http://prntscr.com/114142x

How to use nuget packages in deployment for a visual studio solution

I have a solution which contains multiple c# projects. Some of these projects have nuget dlls as references.
By default nuget pulls all the dlls to a folder called packages in the solution folder (The dlls may depend on other nuget dlls so nuget pulls them too to the packages folder). This works fine for a normal build.
Now I want to deploy my application where all the .dlls are present in a single folder. What is the best way to collect all the nuget dlls into that folder.
Note: While adding Nuget references to a project, CopyLocal is set to true by default, so the nuget dlls are copied into the bin folder of that project. So, I can pull those dlls form there. But I am not sure how to pull the second order dependencies (Other nuget dlls on which the nuget dlls I reference depend on) as they are not copied to the bin folder of project.
But I am not sure how to pull the second order dependencies(Other nuget dlls on which the nuget dlls I reference depend on) as they are not copied to the bin folder of projec
According to the document Dependency resolution:
Any time a package is installed or reinstalled, which includes being
installed as part of a restore process, NuGet also installs any
additional packages on which that first package depends.
Those immediate dependencies might then also have dependencies on
their own, which can continue to an arbitrary depth.
So, when we install one nuget package to our project, NuGet will add the nuget package dll and its dependencies to the project. Besides, NuGet will set the property of CopyLocal to True by default for the dependencies. In this case, all the dependencies will also be copied to the bin folder.
For example, when we install the nuget package Microsoft.Owin to the Asp.net application project, its dependency owin will also be installed to the project by default and the property of CopyLocal is also set to True by default. After installation complete, the dependency owin will copied to the bin folder.
So, to resolve this issue, please make sure the dependencies of the installed nuget package are also added to the project, and check if the property of CopyLocal is set to True.

Packaging project reference in nuget : .net core

Currently I have a requirement where we have separate assemblies for contract and implementation. After creating a nuget package and attempting to consume nuget package, it fails because Package manager is unable to find dependent (contract) assembly.
This seems to be an open issue in .net core.
https://github.com/dotnet/cli/issues/3959
Unable to understand why such simple thing will not work in .net core. Looking for workaround for this issue.
It is simple to solve. You have 2 options:
A) Pack and Publish all your projects as Nuget packages:
You just add your dependencies as ProjectReference into your main projects. And continue development using project references. Also must pack all dependency projects as well. When you want to publish your packages using the same version just run:
dotnet pack -p:PackageVersion=2.1.0 also can add any other pack arguments.
Since during pack all ProjectReference will be transformed to Package dependencies. And version number is cascading into all package.
In this case your original main project and all of its dependencies will be Nuget packaged. Now you have to publish ALL. And when you want to install your Nuget package it will install all of its dependencies as well with the same version specified.
B) Package all output DLLs into a single Nuget package:
You can Publish only one Project as Nuget package and pack all other DLL into that package. First suppress pack to transform dependency from Project to Package. Find your ProjectReference and add PrivateAssets="All" to it. Should look like this:
<ProjectReference Include="yourproj.csproj" PrivateAssets="All" />
And add the following section to your .csproj file (to the project which should be packaged) to package dependency DLLs, change the DLL name and Framework version in <PackagePath>.
<ItemGroup>
<_PackageFiles Include="$(OutputPath)\yourproj.dll">
<BuildAction>None</BuildAction>
<PackagePath>lib\net5.0</PackagePath>
</_PackageFiles>
</ItemGroup>
After reading documentation I understood .net core discourages project reference instead advises to use package reference. This is mentioned in description heading in following doc.
https://github.com/dotnet/docs/blob/master/docs/core/tools/dotnet-pack.md
I published my contract assembly to nuget package and consumed it in implementation as nuget package.

Reference DLL from NuGet folder inside ASP.NET Core project on full .NET framework

I have created a new ASP.NET Core project which targets the full .NET 4.6 framework. So essentially what I want is to create an ASP.NET Core web application with the new .csproj format and the new dotnet tooling, but still target the full framework because we have many dependencies which cannot be ported that quickly to .NET Core.
There are some NuGet packages that include many DLLs, but after adding a PackageReference it only copies one DLL into the bin folder of the web application. Other DLLs I need to manually reference.
For example:
<ItemGroup>
<Reference Include="CustomDll">
<HintPath>..\packages\CustomPackage\version\lib\CustomDll.dll</HintPath>
</Reference>
</ItemGroup>
Now the problem is that with the new tooling and NuGet versions there is no packages folder under the solution path. It is typically in my users folder under .nuget\packages\....
Is there a macro that I can use with the new MSBuild to reference the global nuget folder or a setting that I can change so that the build actually copies all NuGet packages under the solution directory?
It looks like the dll in the NuGet package is placed directly in the lib folder and not lib\net45 which would enable the automatic tooling in that case. (The NuGet package has probably been manually assembled).
As a workaround, you can set the HintPath to $(NuGetPackageRoot)the.package.name\1.0.0\lib\the.dll.

creating nuget: can not package referenced dlls

Im trying to create a nuget using the "Nuget Package Explorer". The project references 2 dlls witch target .net4.0 and the main dll targets .net4.5.
As specified, i put the 2 referenced dlls in a folder inside the "lib" folder called "net40", the main dll in a folder called "net45", then i pushed the nuget wich is located here
But when i try to install it in another project, it doesnt take any of the dlls !
Am I doing something wrong ?
Thank you.
UPDATE:
The nuget package contains:
lib (folder)
net45 (folder)
MainAssembly.dll -> targets .net_4.5
Microsoft.VisualStudio.TextTemplating.10.0 -> targets .net_4
Microsoft.VisualStudio.TextTemplating.Interfaces.10.0 -> targets .net_4
notes:
MainAssembly needs the two other assemblies
I just want to target the .net version 4.5
the problem :
creating a nuget package using the structure above doesnt work, when intalling the nuget in a new project the MainAssembly is not added the list of references, only the two other assemblies are added.
The project references 2 dlls witch target .net4.0 and the main dll targets .net4.5.
As specified, i put the 2 referenced dlls in a folder inside the "lib" folder called "net40", the main dll in a folder called "net45", then i pushed the nuget wich is located here
A NuGet package can target multiple .NET framework versions. However, a .NET project cannot.
Your dependent assemblies must be placed in the same .NET framework version folder in order for them to install into the target project. So, if you want your NuGet package to target 4.0 and 4.5, the structure should look like:
lib
net40
MainAssembly.dll
DependentAssembly1.dll
DependentAssembly2.dll
net45
MainAssembly.dll
DependentAssembly1.dll
DependentAssembly2.dll
The main assembly in each group must target the same framework version as the parent folder. The dependent assemblies can target any version the same or lower than the target version.
Note that typically each assembly is packaged as a separate NuGet package and the NuGet packages depend on each other, rather than putting the dependent assembiles into the same package.

Categories