Reputation: 11
I have a .NET project using native .dll using [DllImport]
attributes. Our project guidelines forbid us from keeping any DLL as part of source code. I created NuGet package of same using nuspec file. Now problem is how to consume the package without referencing it to project. I would like to copy the DLL to output directory instead of referencing in the project.
I have tried adding in package config file and tried restoring packages using prebuild command and copying further which didn't work out.
Could anyone have any suggestion how to package native DLL and consume it in a project with referencing it somehow?
Upvotes: 1
Views: 556
Reputation: 47
Not super sure what your are asking for, ie you want the dll to be in the build directory but not reference it in you project.
I guess you can do this with targets.
IE: Nuget Nuspec file: (there are more required fields, but just listing the relevant fields)
<?xml version="1.0"?>
<package >
<metadata>
<id>NugetName.Core</id>
</metadata>
<files>
<file src="bin\Debug\YourDll.dll" exclude="lib\net452\YourDll.dll" />
<file src="YourDll.dll" target="build\YourDll.dll" />
<file src="NugetName.Core.targets" target="build\" />
</files>
</package>
The make a NugetName.Core.targets file
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)YourDll.dll">
<Link>YourDll.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Upvotes: 1