Skip to content

Commit 4dca071

Browse files
authored
chore: SHC -dev package workflows gracefully handle -rc packages BED-7878 (#215)
* fix publish CommonSource build property * rewrite commonlib version resolution logic - dev packages should target next patch * readme cleanup
1 parent db2377e commit 4dca071

3 files changed

Lines changed: 65 additions & 44 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Build
3737
run: |
3838
VERSION=${{ github.ref_name }}
39-
dotnet build -c ${{ matrix.release.type }} -p:Version=${VERSION:1} -p:CommonLibSource=Release
39+
dotnet build -c ${{ matrix.release.type }} -p:Version=${VERSION:1} -p:CommonSource=Stable
4040
4141
- name: Zip
4242
run: 7z a -tzip -mx9 SharpHound_${{ github.ref_name }}${{ matrix.release.suffix }}_windows_x86.zip $PWD/bin/${{ matrix.release.type }}/net472/*

‎README.md‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,37 @@ To determine the SharpHound version compatible with a deployed BloodHound CE ins
1212

1313
Please refer to the [SharpHound section](https://bloodhound.specterops.io/collect-data/ce-collection/sharphound), part of the [BloodHound Community Edition documentation](https://bloodhound.specterops.io/home).
1414

15-
## Compile Instructions
15+
## Compilation Instructions
1616

17-
To build this project, use .net 5.0 and run the following:
17+
To build this project, using a .NET SDK run the following:
1818

19-
```
20-
dotnet restore .
19+
```bash
20+
dotnet restore
2121
dotnet build
2222
```
2323

24-
By default, the project will build with the latest version of the [SharpHoundCommon Library](https://github.com/SpecterOps/SharpHoundCommon).
24+
By default, the project builds against the next prerelease `-dev` version of the
25+
[SharpHoundCommon Library](https://github.com/SpecterOps/SharpHoundCommon)
26+
(tracking the v4 branch).
27+
28+
If you wish to build against a local copy of the library, ensure the `_CommonLibPath` and `_RPCPath` properties point to the correct DLLs, and run `dotnet build -p:CommonSource=Local`.
29+
30+
If `CommonLibsVersion` already contains a prerelease tag (e.g. `4.6.0-rc1`),
31+
that exact version is used as-is for both `Stable` and `Dev` sources.
2532

26-
To build against the latest stable release of the library, you can run `dotnet build -p:CommonLibSource=Stable`.
33+
| `CommonSource` (default: `Dev`) | Package resolved |
34+
|---------------------------------|-----------------------------------------------------------------------------|
35+
| `Dev` | Prerelease (e.g. `4.6.0-rc1`) or next patch `-dev*` (e.g. `4.6.1-dev*`) |
36+
| `Stable` | Current CommonLibsVersion (e.g. `4.6.0`) |
37+
| `Local` | Local `SharpHoundCommon` DLLs |
38+
39+
```bash
40+
dotnet build # Dev (default)
41+
dotnet build -p:CommonSource=Stable
42+
dotnet build -p:CommonSource=Local
43+
dotnet build --tl:off # To view CommonLib resolution logs
44+
```
2745

28-
If you wish to build against a local copy of the library, ensure the `CommonLibPath` and `RPCPath` properties point to the correct DLLs, and run `dotnet build -p:CommonLibSource=Local`.
2946

3047
## Requirements
3148

‎Sharphound.csproj‎

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,50 @@
1515
</PropertyGroup>
1616

1717
<PropertyGroup>
18-
<CommonLibsStableVersion>4.6.1</CommonLibsStableVersion>
19-
<CommonLibsReleaseVersion>4.6.1</CommonLibsReleaseVersion>
20-
<CommonLibPath>..\SharpHoundCommon\src\CommonLib\bin\$(Configuration)\net472\SharpHoundCommonLib.dll</CommonLibPath>
21-
<RPCPath>..\SharpHoundCommon\src\SharpHoundRPC\bin\$(Configuration)\net472\SharpHoundRPC.dll</RPCPath>
22-
23-
<!-- Derive the dev version by incrementing the patch of the stable version, mirroring
24-
the auto-increment logic in SharpHoundCommon's publish-dev-package pipeline.
25-
e.g. stable=4.6.0 → dev wildcard=4.6.1-dev* -->
26-
<_StablePatch>$([System.Text.RegularExpressions.Regex]::Match($(CommonLibsStableVersion), '[0-9]+$').Value)</_StablePatch>
27-
<_MajorMinor>$([System.Text.RegularExpressions.Regex]::Match($(CommonLibsStableVersion), '^[0-9]+\.[0-9]+').Value)</_MajorMinor>
28-
<CommonLibsDevVersion>$(_MajorMinor).$([MSBuild]::Add($(_StablePatch), 1))-dev*</CommonLibsDevVersion>
29-
18+
<CommonLibsVersion>4.6.1</CommonLibsVersion>
3019
<CommonSource>Dev</CommonSource>
20+
<_CommonSource>$(CommonSource.ToLower())</_CommonSource>
21+
<_CommonLibPath>..\SharpHoundCommon\src\CommonLib\bin\$(Configuration)\net472\SharpHoundCommonLib.dll</_CommonLibPath>
22+
<_RPCPath>..\SharpHoundCommon\src\SharpHoundRPC\bin\$(Configuration)\net472\SharpHoundRPC.dll</_RPCPath>
23+
</PropertyGroup>
3124

32-
<!-- Determine if we should use local DLLs -->
33-
<_UseLocalLibs Condition="'$(CommonSource.ToLower())' == 'local'">true</_UseLocalLibs>
34-
<_UseLocalLibs Condition="'$(_UseLocalLibs)' == ''">false</_UseLocalLibs>
25+
<Target Name="ValidateCommonSource" BeforeTargets="Build">
26+
<Error Condition="'$(_CommonSource)' != 'dev' AND '$(_CommonSource)' != 'stable' AND '$(_CommonSource)' != 'local'"
27+
Text="Invalid CommonSource value '$(CommonSource)'. Valid values are: Dev, Stable, Local." />
28+
</Target>
29+
30+
<PropertyGroup Condition="'$(_CommonSource)' == 'dev' AND !$(CommonLibsVersion.Contains('-'))">
31+
<!-- Derive the dev version by incrementing the patch of the stable version e.g. 4.6.0 → 4.6.1-dev* -->
32+
<_Major>$([System.Version]::Parse('$(CommonLibsVersion)').Major)</_Major>
33+
<_Minor>$([System.Version]::Parse('$(CommonLibsVersion)').Minor)</_Minor>
34+
<_Patch>$([System.Version]::Parse('$(CommonLibsVersion)').Build)</_Patch>
35+
<_DevVersion>$(_Major).$(_Minor).$([MSBuild]::Add($(_Patch), 1))-dev*</_DevVersion>
36+
</PropertyGroup>
3537

36-
<!-- Determine the package version -->
37-
<_CommonLibsVersion Condition="'$(CommonSource.ToLower())' == 'stable'">$(CommonLibsStableVersion)</_CommonLibsVersion>
38-
<_CommonLibsVersion Condition="'$(CommonSource.ToLower())' == 'release'">$(CommonLibsReleaseVersion)</_CommonLibsVersion>
39-
<_CommonLibsVersion Condition="'$(_CommonLibsVersion)' == ''">$(CommonLibsDevVersion)</_CommonLibsVersion>
38+
<PropertyGroup Condition="'$(_CommonSource)' != 'local'">
39+
<_ResolvedCommonVersion Condition="$(CommonLibsVersion.Contains('-'))">$(CommonLibsVersion)</_ResolvedCommonVersion>
40+
<_ResolvedCommonVersion Condition="'$(_ResolvedCommonVersion)' == '' AND '$(_CommonSource)' == 'dev'">$(_DevVersion)</_ResolvedCommonVersion>
41+
<_ResolvedCommonVersion Condition="'$(_ResolvedCommonVersion)' == ''">$(CommonLibsVersion)</_ResolvedCommonVersion>
4042
</PropertyGroup>
43+
44+
<ItemGroup Condition="'$(_CommonSource)' == 'local'">
45+
<Reference Include="SharpHoundCommonLib">
46+
<HintPath>$(_CommonLibPath)</HintPath>
47+
</Reference>
48+
<Reference Include="SharpHoundRPC">
49+
<HintPath>$(_RPCPath)</HintPath>
50+
</Reference>
51+
</ItemGroup>
52+
<ItemGroup Condition="'$(_CommonSource)' != 'local'">
53+
<PackageReference Include="SharpHoundCommon" Version="$(_ResolvedCommonVersion)" />
54+
<PackageReference Include="SharpHoundRPC" Version="$(_ResolvedCommonVersion)" />
55+
</ItemGroup>
56+
57+
<Target Name="LogCommonLibsSource" BeforeTargets="Build">
58+
<Message Text='CommonLib Source "$(CommonSource)":' Importance="high" />
59+
<Message Condition="'$(_CommonSource)' == 'local'" Text=" Resolved Using Local DLLs" Importance="high" />
60+
<Message Condition="'$(_CommonSource)' != 'local'" Text=" Resolved to NuGet Version: $(_ResolvedCommonVersion)" Importance="high" />
61+
</Target>
4162

4263
<ItemGroup>
4364
<PackageReference Include="CommandLineParser" Version="2.8.0" />
@@ -55,18 +76,6 @@
5576
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />
5677
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
5778
</ItemGroup>
58-
<ItemGroup Condition="'$(_UseLocalLibs)' == 'true'">
59-
<Reference Include="SharpHoundCommonLib">
60-
<HintPath>$(CommonLibPath)</HintPath>
61-
</Reference>
62-
<Reference Include="SharpHoundRPC">
63-
<HintPath>$(RPCPath)</HintPath>
64-
</Reference>
65-
</ItemGroup>
66-
<ItemGroup Condition="'$(_UseLocalLibs)' != 'true'">
67-
<PackageReference Include="SharpHoundCommon" Version="$(_CommonLibsVersion)" />
68-
<PackageReference Include="SharpHoundRPC" Version="$(_CommonLibsVersion)" />
69-
</ItemGroup>
7079
<ItemGroup>
7180
<Reference Include="System.DirectoryServices" />
7281
<Reference Include="System.DirectoryServices.Protocols" />
@@ -76,9 +85,4 @@
7685
<Message Text="Test" />
7786
<Exec Command="powershell -ep bypass -c &quot;. '$(ProjectDir)src\Powershell\Out-CompressedDLL.ps1';Out-CompressedDll -FilePath '$(TargetPath)' -TemplatePath '$(ProjectDir)src\\Powershell\Template.ps1' | Out-File -Encoding ASCII '$(TargetDir)$(TargetName).ps1'&quot;" />
7887
</Target>
79-
<Target Name="LogCommonLibsVersion" BeforeTargets="Build">
80-
<Message Text="Loading CommonLib Dependency:" Importance="high" />
81-
<Message Condition="'$(_UseLocalLibs)' == 'true'" Text=" Using Local DLLs" Importance="high" />
82-
<Message Condition="'$(_UseLocalLibs)' == 'false'" Text=" Package Version: $(_CommonLibsVersion)" Importance="high" />
83-
</Target>
8488
</Project>

0 commit comments

Comments
 (0)