creating nuget: can not package referenced dlls - c#

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.

Related

Add a MSBuild targets file to referencing projects

I have a ClassLib1 project that is referenced by many other projects. I want to know if there is a way to include a build targets file for those referencing projects via the ClassLib1? Similar to the way a nugget package can.

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

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.

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

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

Reference to Projects which have references to the same dll with different versions

in my c# class lib i have referenced different Projects which have references to the same dll with different versions.
Both references the nlog.dll but one project version 2.1 and the other 4.2.
The referenced project are class libs, too. Most of them are .net 2.0 and some 4.5.
Just make a Libraries folder if you need to and then create a version folder structure and 'add reference' to each project. If these are nuget packages then you shouldnt need to do this.
You need to install in the the GAC because you application has only one bin folder.
You can also try installing only NLog 4 with a <assemblyBinding> but no guarantees as NLog 2 and NLog 4 aren't fully compatible. (hence the major version change)

Categories