Native dependencies not copied when indirectly referenced as a NuGet dependency - c#

I have an internal NuGet package that is dependent on another NuGet package that has native dependencies. In a .NET SDK console application I am referencing the internal NuGet package and indirectly referencing the other NuGet package that has the native dependencies.
When the NuGet package with native dependencies is referenced indirectly, the native dependencies are not copied properly to the bin directory.
If the NuGet package with native dependencies is installed directly as a direct dependency, then the native dependencies are copied over properly.
Will this always be the case, and we just need to add the NuGet package with native dependencies as a direct dependency to any project using our internal NuGet package? Or is there something that could be added to our internal NuGet package or something that could be added to the other NuGet package to get native dependencies to copy correctly when referenced indirectly?
Our internal NuGet package is build with dotnet pack using info from the csproj file to create the NuGet package.

I was able to resolve this using the package reference modifiers described here Controlling dependency assets
The default for PrivateAssets is to prevent contentfiles, analyzers, and build files from propagating to referencing projects. The native files were in the build folder of the NuGet package that I was referencing along with the .targets file to define what files needed to be copied. Changing PrivateAssets to only exclude contentfiles and analyzers fixed the problem of downstream projects not copying the native files properly.
<PackageReference Include="SomeLibraryWithNativeDependenciesInTheBuildFolder" Version="1.2.3">
<PrivateAssets>contentfiles,analyzers</PrivateAssets>
</PackageReference>

Related

Can I use the DLLs included in the nuget package

I used Nuget package explorer to pack some third party DLLs into one package and published to my nuget server, many of my projects need refer to those third party DLLs and I don't want to add DLL references over and over again. With nuget I only need to install one package.
But after installing that package, i can see those DLLs in the packages folder, but I cannot use classes in those DLLs.
Is that possible to use classes in the DLLs of that nuget package?

Nuget package does not contain dll, only a build folder

I have a large project that needs to use several Nuget packages, but Nuget packages cannot be used on our corporate network. So I have extracted the dlls from all of the packages and linked directly to them instead. This package, however, does not have a dll: VideoLAN.LibVLC.Windows
Instead, it contains a large build folder with a lot of native libraries. How can I build this to create the dll and only the needed libraries? I don't need all of the different language libraries.

Can I add a NuGet package as a runtime dependency?

I Have a .NET class library (no core or std) and I would like to add a NuGet package as a runtime dependency. With runtime dependency i mean i do not like to add the package as a normal reference, since my project does not use this package. I however DO need all the dlls in the package to be copied to the output folder, because i need them at runtime.
'Why?'
Because i am working with a plugin-based model.

StyleCop.Analyzers Nuget Dependencies

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.

How do you publish a nuget package when it has dependencies on non nuget assemblies

Struggling to find any information online for this but I am in a scenario where I have a class library project that has dependencies on plenty of nuget packages, but also requires a local assembly which is not on nuget.
So for example godot creates a project for you which bungs in the dlls into a local folder for your project to reference and just adds Reference with hints to your csproj, now I need to depend on those assemblies for the library to work, but the consumers of this package would have to have those assemblies available locally.
So is there a way for nuget to be told that an assembly is needed but it isnt provided via nuget?

Categories

Resources