Using .NET Core 2.2, I want to create a NuGet package with native dependencies for different platforms (win-x64, linux-x64, linux-arm). The dependencies are pre-built DLLs/SOs using a C compiler.
I've successfully created the NuGet package with all dependencies put into the runtimes folder in a subfolder for each platform.
My problem is that I have a unit test project in the same solution and I need the native dependencies to be copied to the output folder for the unit tests to run successfully.
The question is where in the source to put the native dependencies so that the correct one is copied to the output folder when I build or publish for a specific platform. Also, what do I need to add to the .csproj file to achieve this?
Related
I have an SDK project in my solution. And i need to add a NuGet package ("customLib.net"), which provides the functionality to find the differences between files.
If you create a simple .Net Framework 4.7.2 console application and add this NuGet to it, then it will automatically download it along with all dependencies, including "customLib.redist.windows.x64". As i understand "customLib.net.dll" is an API for .net, and "customLib.dll" (which comes from "customLib.redist.windows.x64" package) is an engine itself, compiled for win-x64. The package is stored in SolutionFolder/packages. And there is a package.config file with all required references. And everything works as expected.
But if to add the same NuGet package to SDK (Class Library) project, which has the same target: .Net Framework 4.7.2, it should also download the NuGet package along with all dependencies. And it does. But it doesn't store the packages in SolutionFolder/packages folder, and there are no any package.config files. It stores them in global NuGet storage on C drive. And the problem is that when i launch the application it throws an exception in runtime:
"Unable to load DLL 'customLib': The specified module could not be found.".
And this dll doesn't exists in output folder. I solved this issue by downloading the "customLib.redist.windows.x64" NuGet package to the project, despite the fact that "customLib.net" already has a reference to this package. This is a little bit weird for me, and here are the questions:
Why, if a "customLib.net" depends on "customLib.redist.windows.x64", it does not copy dependent dll to the output folder? At the same time, the console application copies both libraries.
Why after downloading "customLib.redist.windows.x64" NuGet the "customLib.dll" file shows in my project root in Visual Studio with full path to "C:\Users\MyUsr\.nuget\packages\customLib.redist.windows.x64\1.0.1\runtimes\win-x64"?
As per the description, I can assume that you have .NET standard console application but you added the .Net core class library into it. That's why you are facing such issues.
Because in the .NET core library project, there is no package.config file and references were added directly to the csproj file. As well as packages downloaded to the user's directory, instead of the packages folder.
So, instead of adding a .Net core library, you need to add the .NET standard class library into your project
To know more about it refer to What is the difference between .NET Core and .NET Standard Class Library project types?
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
In the net core world, you have to invoke the publish command to bring the assemblies, referenced through nuget, into your projects output directory.
In the .NET Framework world, there is no publish command. My assumption was that msbuild always resolves the referenced nuget packages and copies the assemblies to the output directory. On my developer machine this works always.
Now we see problems that this does not happen during an automated build and colleagues started to add references with the GeneratePathProperty and do an explicit copy action with CopyToOutputDirectory. In my eyes that's wrong and error prone because transitive dependencies are not resolved automatically.
Can someone point me to a piece of msbuild documentation which explains the nuget handling?
I am pulling this project from a git repository that depends on Microsoft.SqlServer.Types which should install msvce120.dll and SqlServerSpatial140.dll. But for some reason it does not install them. They appear in the solution explorer as seen on the image. But the files are not there in windows explorer.
The project was cloned from a git repository. As soon as I tried to build the project, VS started downloading the necessary nuget packages, but this files fail to download. The original repository has these files marked as git ignored.
Where am I going wrong here? I could simply copy and paste the dlls from the original repository but I want to understand why they are not being downloaded or installed.
If you installed this package into a project using the <PackageReference> style of packages (typically found in .Net Standard / .Net Core applications), then the files are not added because there is a lack of support for the install / uninstall scripts used for this function.
Specifically, when installing / restoring this package, there is an install.ps1 script that is supposed to be ran which creates the folders and places the dll's you're referencing into these folders. Again, there is no support for this functionality in the <PackageReference> style of packaging.
This is juxtapose to the packaging style that uses Packages.config which DOES have support for install / uninstall scripts.
You can read more about this here: https://github.com/NuGet/Home/issues/6330
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