SQLitePCL.raw
SQLitePCL.raw copied to clipboard
Improve .targets file to include a new item gathering the native dlls
I'm using Costura to embed managed and native libraries in my app, so I'm using this trick to avoid copying the SQLite dlls into the output directory and embed them with Costura instead:
<Target Name="EmbedNativeSQLiteDllWithCosturaInsteadOfCopying" BeforeTargets="ResolveAssemblyReferences">
<ItemGroup>
<EmbeddedResource Include="$(NugetPackageRoot)\sqlitepclraw.lib.e_sqlite3.v110_xp\1.1.13\runtimes\win-x86\native\e_sqlite3.dll">
<Link>costura32\e_sqlite3.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(NugetPackageRoot)\sqlitepclraw.lib.e_sqlite3.v110_xp\1.1.13\runtimes\win-x64\native\e_sqlite3.dll">
<Link>costura64\e_sqlite3.dll</Link>
</EmbeddedResource>
<!-- See https://github.com/Microsoft/msbuild/issues/1983#issuecomment-294909216 -->
<Content Remove="@(Content)" Condition="'%(Filename)%(Extension)' == 'e_sqlite3.dll'" />
</ItemGroup>
</Target>
Ideally, the .targets files should define an MSBuild item, maybe SQLiteNativeLibraries that I could reference in my target instead of using $(NugetPackageRoot)\sqlitepclraw.lib.e_sqlite3.v110_xp\1.1.13\runtimes\... (and hardcoding the package version number).
My target could be then simplified like this:
<Target Name="EmbedNativeSQLiteDllWithCosturaInsteadOfCopying" BeforeTargets="ResolveAssemblyReferences">
<ItemGroup>
<EmbeddedResource Include="@(SQLiteNativeLibraries)">
<!-- Syntax could be simplified in the future in MSBuild, see [Metadata should support instance methods](https://github.com/microsoft/msbuild/issues/1155) -->
<Link Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').Contains('x86'))">costura32\%(Filename)%(Extension)</Link>
<Link Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').Contains('x64'))">costura64\%(Filename)%(Extension)</Link>
</EmbeddedResource>
<Content Remove="@(SQLiteNativeLibraries)" />
</ItemGroup>
</Target>
This is somehow related to #156. I could help implement these improvements but I'm currently having trouble understanding how the .targets file are automatically generated.
OK, I found gen_nuget_targets, working on it…
I need to look at that PR, but in the meantime, there's this, which might be relevant:
Fody/Costura#442
Yeah, I've seen that. I think Costura still makes sense if you deploy on .NET Framework, not everyone can migrate to .NET Core right now.
Also, there's still a benefit to having simplified .targets files and having SQLiteNativeLibraries defined.
Costura is being deprecated https://github.com/Fody/Costura/issues/442 so you should probably stop using it
Closing old/stale issue.