Nuget package extraction without build - c#

I have my own Nuget package and I want to "extract" it (get the dll inside it) without building the project.
Is it possible?
Can I do it to a specific folder?
If it is possible:
can I do it on "Nuget restore", "Nuget installation", project reference (when adding the project with the Nuget as a reference to other project)?
Is it possible to do a post-process such as writing the path of the extract dlls to a file?
Thanks.

Related

Issue finding and using lib folder in Nuget package C# project

I am working on creating a sample Nuget package to test out the process of creating an internal Nuget package for use in another project of mine. My end goal is to create a simple Nuget package, which can be installed onto another simple C# project, and tested out.
I have been following the Microsoft tutorial to create & publish a package using VS:
https://learn.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio-net-framework
I successfully created & published my package on nuget.org, called MyNugetPackage, and attempted to install it onto my other C# project called TestingMyNugetPackage. I received an error in the NuGet package console stating:
Package does not support any target framework
This error makes sense, because I had read about supporting multiple .NET versions and specifying the version under the lib folder, and I definitely did not do that when creating my package:
https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks
This idea of lib folder makes sense to me and I think I understand how to add my target .NET version to it. However, I cannot find this folder anywhere! It's not anywhere in the C# project directory. I assume I may need to create it on my own, but I'm not sure where to put it.
Many tutorials and SO questions I have read about this topic talk about how to use the lib folder, but no one ever says where it is. I'm a complete beginner to this and I know I am missing something obvious here, but I'm not sure what it is.
Edit: I did try to change my .nupkg file to a .zip file and extracting the contents in attempt to view the lib folder. This did work in extracting the contents, but I did not see any lib folder after expanding entire project tree and searching for lib.
Here is a quick layout of my C# solution tree:
Solution titled MyNugetPackage with a MyNugetPackage.sln file, a MyNugetPackage.csproj file, and a simple class Logger.cs that just has a public void Print(string text) { Console.WriteLine(text); } method:
MyNugetPackage
MyNugetPackage.csproj.1.0.0.nupkg
MyNugetPackage.nuspec
MyNugetPackage.sln
MyNugetPackage (folder)
bin (folder)
Debug (folder) -> .dll, .pdb
Release (folder) -> .dll, .pdb
obj (folder)
Debug (folder)
Release (folder)
Properties (folder)
AssemblyInfo.cs
Logger.cs
MyNugetPackage.csproj
Could someone direct me where I need to place my lib folder, so that I can add my supported .NET 4.7 framework reference, and successfully install my package?
A NuGet package (.nupkg) is just a zip file. If you are trying to view the contents of this file, open it like a zip file (using 7zip or something). Alternatively change the extension to zip. In the package you will find the "lib" folder as well as the .nuspec, and package folder (among other contents). But this is the resulting package that is built when you Pack your project, changes here would have no affect on your code.
If you're just trying to target one or more frameworks. In VS, edit your project file (.csproj). This file is an XML with a PropertyGroup that contains either a "TargetFramework" OR a "TargetFrameworks" element. To target a single framework add a TargetFramework element, to target multiple use the TragetFrameworks instead.
To target a single .Net framework:
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
Alternatively, you can target multiple frameworks.
<PropertyGroup>
<TargetFrameworks>net472; netcoreapp3.0; netcoreapp2.1</TargetFrameworks>
</PropertyGroup>
This would target .Net 4.7.2, .Net Core 3.0, and .Net Core 2.1

How to create .dll from Nuget package?

I have a program written in C# and there is a TwitchLib.dll that provides some stuff about Twitch.tv API I guess and I want to update the .dll since there were some changes in API. How can I get .dll from a nuget package (TwitchLib).
I've tried going to /.nuget/packages/twitchlib/3.0.1/ and there is no TwitchLib.dll while for example in /.nuget/packages/twitchlib.client/3.0.3/ there is. I need .dll that is for whole TwitchLib library, not only specific parts of library.
Just build the class library by clicking the right click on solution explorer and you will see the NameOfLibrary.dll file in packages folder of your project directory.

How to reference Nuget binaries in Wix Bundle PayLoad?

I am publishing my Bootstrapper.dll on a local nuget server during its build, and this is working fine. But to use it in my Bundle projects (wixproj), I can't find any direct method to reference this in PayLoad.
As a workaround I have created a dummy C# project, adding the nuget reference, Copy Local=True and then referencing this dummy C# project's TargetDir\Bootstrapper.dll in Bundle PayLoad.
Question: Is there any way to avoid using dummy C# project and using nuget referenced binaries in Bundle's PayLoad directly?
Thanks
You can install the NuGet package in your Wix Bootstrapper project. Create a install.ps1 to update Payloads in your Bundle.wxs. At the end of install.ps1 save the project.
$project.Save($project.FullName)
Don't forget to undo the changes made in install.ps1 in uninstall.ps1 to keep everything nice an clean.
The above described procedure will save you from creating C# dummy project.

add metadata extractor to project without nuget

Due to some project needs I will need to add metadata extractor to my project without using Nuget(as I cannot use the VS package manager). I am having trouble adding it as an external project. What is the best way to add it externally without using Nuget ?
NuGet allows you to download packages:
On this page (https://www.nuget.org/packages/MetadataExtractor/):
That will download a .nupkg file, which you can rename to .zip then find the .dll file inside.
You'd need to do the same things for any dependencies.
Honestly if you could use NuGet it'd be much easier for you. But that is the workaround.

Install nupkg from local nuget package

I have followed http://www.hanselman.com/blog/CreatingANuGetPackageIn7EasyStepsPlusUsingNuGetToIntegrateASPNETMVC3IntoExistingWebFormsApplications.aspx this guide to create my own nuget package. The only problem is when i use the console to install my package it just adds the cs files directly to the project instead of createing a .dll and add it as a package. The content folder of my nuget only contains two cs files is that why it doesn't create the package as a dll and instead just uses the cs files directly?
Look at your original nuspec file for whether it's including the output DLLs or the raw CS's (probably the latter). Fix it and make sure the assemblies go into lib/netXX (e.g. lib/net45), not "content".
Also, the file is just a ZIP. Inspect it before you use it to ensure that it contains the right files.

Categories