I'm extremely new to concepts like msbuild, nuget packages and .targets files, so please bear with me :)
I have a C# project which is supposed to generate a Nuget package which contains a native DLL. I'm able to get this working, but when I install that Nuget package in another C# project, the native DLLs are not copied over. For this issue, this question seems to be helpful:
Add native files from NuGet package to project output directory
However all the solutions there mention adding a .targets file into the build folder inside the nuget package. But how do I do this ??? In other words, where do I place this .targets file in my source code, such that when the project is built and the nuget package is generated, the .targets file is added into the nuget package (under 'build' folder) ??
This is the current contents of the nuget package that's generated on every build (notice that there's no .targets file):
root
| Com.CompanyName.Sdk.nuspec
| [Content_Types].xml
|
+---lib
| +---native
| | Com.CompanyName.Hashing.dll
| |
| \---netcoreapp3.1
| Com.CompanyName.Sdk.dll
| Com.CompanyName.Core.dll
|
+---package
| \---services
| \---metadata
| \---core-properties
| b2b8c6e91425459ba050043277f18f48.psmdcp
|
\---_rels
.rels
I assumed I might have to place the .targets file in the same location as the CSPROJ file, so currently it's located at the root directory of the project where the CSPROJ is also located.
This is the contents of my NUSPEC file, which is also in the root directory of the project:
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
.....some metadata here.....
<dependencies>
<group targetFramework="netcoreapp3.1"></group>
<group targetFramework="native"></group>
</dependencies>
</metadata>
<files>
<file src="Com.CompanyName.Sdk.dll" target="lib\netcoreapp3.1" />
<file src="Com.CompanyName.Core.dll" target="lib\netcoreapp3.1" />
<file src="Com.CompanyName.Hashing.dll" target="lib\native" />
</files>
</package>
Also, if the add the following import in the NUSPEC at the bottom with the other imports ...
<file src="Com.CompanyName.Sdk.targets" target="build\Com.CompanyName.Sdk.targets.targets" />
... I get an msbuild error that the .targets file isn't found:
C:\Program Files\dotnet\sdk\5.0.408\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5019: File not found: 'Microso
ft.Com.CompanyName.Sdk.targets'. [C:\git\sdk\sources\dev\Sdk\Com.CompanyName.Sdk.csproj]
So how do I fix this ??