Can you create a NuGet package for just an assembly - c#

Background: I am using Visual Studio 2019 Professional Version 16.11.15, and NuGet Package Manager 5.11. I was provided some 3rd party assemblies to use for my .NET Standard 2.0 class library. These dlls were installed locally on my machine by an installer. I added them to my project via "Add Project Reference". Here's a screenshot of them working.
Goal: Create a NuGet package for my .NET Standard 2.0 class library to be used internally by our dev team. It should encapsulate these 3rd party dlls as part of it. But I keep running into dead ends.
Important note: Xceed does not host these .NET Standard assembly versions on nuget.org, purposefully making my life difficult it seems...
I have tried:
Using the "Generate NuGet package on build" in the Package section of the project properties. This option does not attach the 3rd party assemblies with it. This includes setting the Copy Local option to "Yes".
Adding these 3rd party dlls to their own NuGet packages via NuGet Package explorer following this answer. I tried several different flavors of folder structures:
placing the dll at the root
placing the dll inside a "lib" folder
placing the dll inside a "lib/netstandard2.0" folder
None of these options worked when adding the NuGet packages to my project. The references to the assembly namespace weren't resolving in the code.
Has anyone had any success doing something like this before?

It turns out I was running into the problem of the NuGet packages not refreshing when updating it. I followed this the first part of this answer to solve that.
When using the folder structure "lib/" inside the NuGet package, I was running into this warning:
Warning NU1701 Package 'Xceed.Document.NETStandard 2.3.2' was restored using
'.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2,
.NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1,
.NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8'
instead of the project target framework '.NETStandard,Version=v2.0'.
This package may not be fully compatible with your project.
Once I updated to use "lib/netstandard2.0/" inside the NuGet package, I was able to add the NuGet packages to my library successfully and compile. Great success!

Related

How to work with NugetPackage and LocalProject at same time?

I got an issue working with Nuget packages and local projects.
I am working on a .Net Framework solution, with many projects and many of them are packaged with Nuget in a private repository. I am using PackageReferences to resolve nuget packages. I am working on solution with that kind of dependency tree.
StartUpProject
Project1(LocalProject)
Project2 v1.0.0(NugetPackage)
Project3 v1.0.0(NugetPackage)
Project3 v1.0.1(LocalProject)
When I want to debug or upgrade functionality of packaged project, I remove Nuget package and add that assembly as local project.
When I am navigating in the source code if I try to go to some function from the modified project, Visual Studio open the code as external assembly and does not resolve like local project.
Maybe the problem is other Nuget package (Project2) depends from I removed Nuget package (Project3) and Visual Studio still resolving that assembly as Nuget package.
The error that Visual Studio throws at compilation is CS0433: The type 'MyType' exist in both'Project3 , Version=1.0.0, ...' and in 'Project3, Version=1.0.1, ...'
What is way to work in that cases?
Is any way to force to use local project than dependency nuget package?
Thank you!

Use nuget package instead of project reference Visual studio

We have a solution with 7 to 8 different projects including class libraries and mvc apps. We are using .net 4.6.2 and netstandard 2.0.
We are trying to convert class libraries to nuget packages and instead of referencing the projects directly in our web apps, use nuget packages. We have created the packages and added them in packages.config and the packages are getting installed perfectly fine.
Now, when I remove previous reference and add a new reference and point it to the nuget package, my web apps doesn't work and give assembly not found error.
I think I'm not adding the reference correctly , and need help on this.
If you are using NuGet packages now then you would install the package into each project which needs the assemblies and NuGet will add the references for you. You don't add the references by adding them from the packages directory.
E.g. Install-Package MyPackage MyProject

Getting error attempting to publish a WPF which uses PackageReference

I'm working on upgrading one of our WPF applications. During my upgrade, I converted the application from using the packages.config format for NuGet packages to using the PackageReference format.
Everything seemed to work fine locally, but our build agent started complaining about our NuGet packages:
Error MSB3188: Assembly
'C:\Users\tfs\.nuget\packages\Utils\1.0.0\lib\net45\Utils.dll' must be
strong signed in order to be marked as a prerequisite.
This sort of makes sense because the Utils package is not referenced directly anymore. When you utilize the packages.config format, every NuGet package is referenced by the project, but when you utilize the PackageReference format, only the top-level packages are referenced; package dependencies are not included. Additionally, any projects which are referenced which have a NuGet dependency not explicitly referenced by the WPF project are also affected.
Adding the package dependencies directly to the WPF project solves this issue, but it seems like it shouldn't have to be done that way.
What's strange is when I go into the publish settings / application files for the project, the assemblies are not listed as Prerequisite, but they are marked as Install (Auto) instead.
Short of adding the NuGet package dependencies (not simply the top-level packages), what are my options here? Is there some sort of setting or msbuild parameter, etc. which I can use that allows me to use the PackageReference format while still only referencing the top-level packages?

Cannot find Math.net in References after installing package with NuGet in Visual Studio 2015

I'm trying to use the Math.net extension for Visual Studio 2015 with C#.
Unfortunately, after installing the package with
PM> Install-Package MathNet.Numerics -Version 3.20.0
I cannot find it anywhere in the Add References menu. I searched Assemblies->Framework and Assemblies->Extensions and COM, but it's not there
I wouldn't mind the just adding the DLL to my project, but I cannot find the DLL anywhere on https://numerics.mathdotnet.com , all the links take me to the NuGet package manager.
Also, do I need to distribute the MathNet dll with my application if I add it through the package manager, or does it build internally with the application?
Sorry, new to .net library management
I see that when I ran the command line, it added a packages folder to my project folder. Which has a few different versions of the library per .net version. Which I could browse to with Add Reference->Browse->Browse
Is this the correct way about adding a third party library?

Assembly visible in Package Explorer but not referenced when installed

I am creating a NuGet package from one of my projects using -IncludeReferencedProjects.
When I check the nupkg afterwards with the NuGet Package Explorer I see all referenced libraries inside the lib folder.
After installing the package in another project one of the before mentioned projects is not referenced.
I don't get any error messages when installing or packaging. Does anyone have an idea, what might cause this or is there a way to debug it somehow?
The Nuget package is hosted in our Team Services repository.
I found the answer. The problem was that the assembly name was ending with .Resources for some reason .Net or Visual Studio or NuGet can't handle that.

Categories

Resources