Skip to content

Commit

Permalink
Fix some issues relating to packaging of the native module.
Browse files Browse the repository at this point in the history
* Fix module being missing from NuGet packages.
* Include symbol files in Debug builds.
* Mark the module as CopyToOutputDirectory=PreserveNewest instead of Always in
  the packaged target that includes the module in user projects.
  • Loading branch information
alexrp committed Jan 7, 2024
1 parent c4dc716 commit eccb221
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
34 changes: 12 additions & 22 deletions src/injection/injection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,26 @@ assemblies into processes.</PackageDescription>
<PackageReference Include="PeNet" />
</ItemGroup>

<Target Name="_AddModule"
Returns="@(Content)">
<Target Name="_AddNativeLibraries"
BeforeTargets="AssignTargetPaths; _GetPackageFiles">
<MSBuild Projects="../module/module.cproj"
Targets="GetTargetPath">
Targets="_GetNativeLibraries">
<Output TaskParameter="TargetOutputs"
ItemName="_ModulePath" />
ItemName="_NativeLibrary" />
</MSBuild>

<ItemGroup>
<Content Include="@(_ModulePath)"
CopyToOutputDirectory="Always"
<Content Include="@(_NativeLibrary)"
Link="%(Filename)%(Extension)"
CopyToOutputDirectory="PreserveNewest"
PackagePath="ruptura" />
<_NativeLibrarySymbols Include="@(_NativeLibrary->'%(Symbols)')" />
<Content Include="@(_NativeLibrarySymbols)"
Link="%(Filename)%(Extension)"
CopyToOutputDirectory="PreserveNewest"
PackagePath="ruptura" />
</ItemGroup>
</Target>

<Target Name="_AddModules"
BeforeTargets="AssignTargetPaths">
<ItemGroup>
<_RuntimeIdentifiers Include="win-x64" />
<_Projects Include="$(MSBuildProjectFullPath)"
Properties="RuntimeIdentifier=%(_RuntimeIdentifiers.Identity)" />
</ItemGroup>

<MSBuild Projects="@(_Projects)"
Targets="_AddModule"
BuildInParallel="$(BuildInParallel)">
<Output TaskParameter="TargetOutputs"
ItemName="Content" />
</MSBuild>
</Target>

<Import Project="../system/system.targets" />
</Project>
4 changes: 2 additions & 2 deletions src/injection/injection.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
BeforeTargets="AssignTargetPaths"
Condition="'$(RupturaIncludeModules)' != 'false'">
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)../ruptura/ruptura-*.dll"
CopyToOutputDirectory="Always" />
<Content Include="$(MSBuildThisFileDirectory)../ruptura/ruptura-*.dll; $(MSBuildThisFileDirectory)../ruptura/ruptura-*.pdb"
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Target>
</Project>
25 changes: 25 additions & 0 deletions src/module/module.cproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,29 @@
<PackageReference Include="runtime.win-x86.Microsoft.NETCore.DotNetAppHost"
GeneratePathProperty="true" />
</ItemGroup>

<Target Name="_GetNativeLibrary"
Returns="@(_NativeLibrary)">
<ItemGroup>
<_NativeLibrary Include="$(TargetPath)"
Symbols="@(_DebugSymbolsOutputPath)"
RuntimeIdentifier="$(RuntimeIdentifier)" />
</ItemGroup>
</Target>

<Target Name="_GetNativeLibraries"
Returns="@(_NativeLibrary)">
<ItemGroup>
<_RuntimeIdentifiers Include="$(RuntimeIdentifiers)" />
<_Projects Include="$(MSBuildProjectFullPath)"
Properties="RuntimeIdentifier=%(_RuntimeIdentifiers.Identity)" />
</ItemGroup>

<MSBuild Projects="@(_Projects)"
Targets="_GetNativeLibrary"
BuildInParallel="$(BuildInParallel)">
<Output TaskParameter="TargetOutputs"
ItemName="_NativeLibrary" />
</MSBuild>
</Target>
</Project>

0 comments on commit eccb221

Please sign in to comment.