Skip to content

Commit d972f2e

Browse files
authored
Fix native library copying from NuGet package (v0.4.4) (#57)
* fix: Package native library in runtimes/{rid}/native/ for NuGet auto-copy (v0.4.4) Fixes d2wrapper native library not being copied to consuming projects. Changes: - Modified IncludeNativeLibrary target in D2Sharp.csproj to copy built native library to runtimes/{rid}/native/ during local builds - Added CopyD2SharpNativeLibrary target to D2Sharp.targets to copy native library from package to consuming project's bin/ - Targets file uses relative paths (../runtimes/{rid}/native/) to locate library in NuGet package cache - Package now includes native library in both lib/net8.0/ (backwards compat) and runtimes/{rid}/native/ (auto-copy) - Updated CHANGELOG.md with v0.4.4 release notes - Bumped version to 0.4.4 in D2Sharp.csproj - Updated NuGetExample to reference D2Sharp v0.4.4 - Verified rendering works: all 5 examples run successfully Resolves issue where v0.4.3 copied Worker files but not the native library. * chore: Ignore generated SVG files in NuGetExample * fix: Make native library copy conditional to prevent CI build failures The Copy task in IncludeNativeLibrary target now checks if the source file exists before attempting to copy. This prevents MSB3030 errors in CI builds where the native library may not be built yet. The CI workflow already handles native library placement by downloading artifacts from all platforms and manually copying them to runtimes/{rid}/native/, so this local copy is optional for CI builds.
1 parent b3d1952 commit d972f2e

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,5 @@ d2wrapper.h
102102
appsettings.*.json
103103

104104
tools/D2Sharp.DiagramCLI/output
105+
# Generated D2 diagram outputs
106+
examples/D2Sharp.NuGetExample/*.svg

CHANGELOG.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.4.4] - 2025-10-21
11+
12+
### Fixed
13+
- **NuGet packaging**: Fixed d2wrapper native library not being copied to consuming projects (v0.4.3 regression)
14+
- Modified `IncludeNativeLibrary` target in D2Sharp.csproj to copy built native library to `runtimes/{rid}/native/` directory during local builds
15+
- Added `CopyD2SharpNativeLibrary` target to D2Sharp.targets to automatically copy native library from package to consuming project's bin/
16+
- Targets file uses relative paths (`../runtimes/{rid}/native/`) to locate native library in NuGet package cache
17+
- Automatically detects platform (Windows/Linux/macOS) and handles correct file extension (.dll/.so/.dylib)
18+
- Fallback to project reference path (`../d2wrapper/`) for local development with project references
19+
- Package now includes native library in both `lib/net8.0/` (backwards compat) and `runtimes/{rid}/native/` (automatic copy)
20+
- Verified all examples run successfully and rendering works correctly
21+
- Users of v0.4.1, v0.4.2, or v0.4.3 should upgrade to v0.4.4 for working rendering
22+
1023
## [0.4.3] - 2025-10-21
1124

1225
### Fixed
@@ -15,7 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1528
- Rewrote D2Sharp.targets to use Copy task instead of Content items for reliable file copying
1629
- Fixed MSBuild ".." path error during NuGet restore by moving path resolution into build target
1730
- Verified all 13 Worker files now copy correctly from NuGet package
18-
- Users of v0.4.1 or v0.4.2 should upgrade to v0.4.3 for working process isolation
31+
- NOTE: v0.4.3 package is broken - Worker files copy but native library doesn't. Use v0.4.4 instead
1932

2033
## [0.4.2] - 2025-10-21
2134

@@ -388,7 +401,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
388401
- Go wrapper for D2 library
389402
- .NET 8.0 library
390403

391-
[Unreleased]: https://github.com/AlrikOlson/D2Sharp/compare/v0.4.3...HEAD
404+
[Unreleased]: https://github.com/AlrikOlson/D2Sharp/compare/v0.4.4...HEAD
405+
[0.4.4]: https://github.com/AlrikOlson/D2Sharp/compare/v0.4.3...v0.4.4
392406
[0.4.3]: https://github.com/AlrikOlson/D2Sharp/compare/v0.4.2...v0.4.3
393407
[0.4.2]: https://github.com/AlrikOlson/D2Sharp/compare/v0.4.1...v0.4.2
394408
[0.4.1]: https://github.com/AlrikOlson/D2Sharp/compare/v0.4.0...v0.4.1

examples/D2Sharp.NuGetExample/D2Sharp.NuGetExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="D2Sharp" Version="0.4.3" />
11+
<PackageReference Include="D2Sharp" Version="0.4.4" />
1212
</ItemGroup>
1313

1414
</Project>

src/D2Sharp/D2Sharp.csproj

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
<InternalsVisibleTo>D2Sharp.Benchmarks</InternalsVisibleTo>
1616

1717
<!-- Version information -->
18-
<VersionPrefix>0.4.3</VersionPrefix>
18+
<VersionPrefix>0.4.4</VersionPrefix>
1919
<VersionSuffix></VersionSuffix>
20-
<AssemblyVersion>0.4.3.0</AssemblyVersion>
21-
<FileVersion>0.4.3.0</FileVersion>
20+
<AssemblyVersion>0.4.4.0</AssemblyVersion>
21+
<FileVersion>0.4.4.0</FileVersion>
2222
<InformationalVersion>$(VersionPrefix)</InformationalVersion>
2323

2424
<!-- Package metadata -->
@@ -77,7 +77,22 @@
7777

7878
<!-- Include native library dynamically after it's built -->
7979
<Target Name="IncludeNativeLibrary" AfterTargets="BuildD2Wrapper" BeforeTargets="BeforeBuild">
80+
<PropertyGroup>
81+
<!-- Determine RID based on OS -->
82+
<_NativeLibRID Condition="$([MSBuild]::IsOSPlatform('Windows'))">win-x64</_NativeLibRID>
83+
<_NativeLibRID Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx-x64</_NativeLibRID>
84+
<_NativeLibRID Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux-x64</_NativeLibRID>
85+
</PropertyGroup>
86+
87+
<!-- Copy native library to runtimes/{rid}/native/ for NuGet packaging -->
88+
<MakeDir Directories="$(MSBuildProjectDirectory)/runtimes/$(_NativeLibRID)/native" />
89+
<Copy SourceFiles="$(OutputPath)$(NativeLibName)"
90+
DestinationFolder="$(MSBuildProjectDirectory)/runtimes/$(_NativeLibRID)/native/"
91+
SkipUnchangedFiles="true"
92+
Condition="Exists('$(OutputPath)$(NativeLibName)')" />
93+
8094
<ItemGroup>
95+
<!-- Package in lib/net8.0 for backwards compatibility and direct use -->
8196
<Content Include="$(OutputPath)$(NativeLibName)">
8297
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8398
<Pack>true</Pack>

src/D2Sharp/D2Sharp.targets

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,41 @@
3535
<!-- Warn if Worker files were not found -->
3636
<Warning Condition="'$(_D2SharpWorkerSourcePath)' == ''" Text="D2Sharp.Worker executable not found. Process isolation will not be available. Run 'dotnet build' at solution level or ensure Worker project is built." />
3737
</Target>
38+
39+
<!-- Copy d2wrapper native library to consuming project's output directory -->
40+
<Target Name="CopyD2SharpNativeLibrary" AfterTargets="Build">
41+
<PropertyGroup>
42+
<!-- Determine native library extension based on OS -->
43+
<_D2WrapperExtension Condition="$([MSBuild]::IsOSPlatform('Windows'))">.dll</_D2WrapperExtension>
44+
<_D2WrapperExtension Condition="$([MSBuild]::IsOSPlatform('OSX'))">.dylib</_D2WrapperExtension>
45+
<_D2WrapperExtension Condition="$([MSBuild]::IsOSPlatform('Linux'))">.so</_D2WrapperExtension>
46+
<_D2WrapperLibName>d2wrapper$(_D2WrapperExtension)</_D2WrapperLibName>
47+
48+
<!-- For NuGet package: try lib/net8.0 first (where D2Sharp packages it) -->
49+
<_D2WrapperNuGetLibPath>$(MSBuildThisFileDirectory)..\lib\net8.0\$(_D2WrapperLibName)</_D2WrapperNuGetLibPath>
50+
51+
<!-- Fallback: check runtimes/{rid}/native/ in case of multi-platform packaging -->
52+
<_D2WrapperRID Condition="$([MSBuild]::IsOSPlatform('Windows'))">win-x64</_D2WrapperRID>
53+
<_D2WrapperRID Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx-x64</_D2WrapperRID>
54+
<_D2WrapperRID Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux-x64</_D2WrapperRID>
55+
<_D2WrapperNuGetRuntimePath>$(MSBuildThisFileDirectory)..\runtimes\$(_D2WrapperRID)\native\$(_D2WrapperLibName)</_D2WrapperNuGetRuntimePath>
56+
57+
<!-- For project references: native library is in ../d2wrapper/ -->
58+
<_D2WrapperProjectPath>$(MSBuildThisFileDirectory)..\d2wrapper\$(_D2WrapperLibName)</_D2WrapperProjectPath>
59+
60+
<!-- Choose the path that exists (try lib/net8.0 first, then runtimes, then project) -->
61+
<_D2WrapperSourcePath Condition="Exists('$(_D2WrapperNuGetLibPath)')">$(_D2WrapperNuGetLibPath)</_D2WrapperSourcePath>
62+
<_D2WrapperSourcePath Condition="'$(_D2WrapperSourcePath)' == '' AND Exists('$(_D2WrapperNuGetRuntimePath)')">$(_D2WrapperNuGetRuntimePath)</_D2WrapperSourcePath>
63+
<_D2WrapperSourcePath Condition="'$(_D2WrapperSourcePath)' == '' AND Exists('$(_D2WrapperProjectPath)')">$(_D2WrapperProjectPath)</_D2WrapperSourcePath>
64+
</PropertyGroup>
65+
66+
<!-- Copy native library if found -->
67+
<Copy Condition="'$(_D2WrapperSourcePath)' != ''"
68+
SourceFiles="$(_D2WrapperSourcePath)"
69+
DestinationFolder="$(OutputPath)"
70+
SkipUnchangedFiles="true" />
71+
72+
<!-- Warn if native library was not found -->
73+
<Warning Condition="'$(_D2WrapperSourcePath)' == ''" Text="d2wrapper native library not found. D2Sharp rendering will not work. Ensure the native library is built and packaged correctly." />
74+
</Target>
3875
</Project>

0 commit comments

Comments
 (0)