Skip to content

Commit 81a7e70

Browse files
add local library debugging option (#45)
1 parent f2042bc commit 81a7e70

File tree

6 files changed

+139
-8
lines changed

6 files changed

+139
-8
lines changed

.devcontainer/devcontainer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
// AWS credentials for Claude Code (optional)
4343
"source=${localWorkspaceFolder}/.devcontainer/.aws,target=/home/vscode/.aws,type=bind",
4444
// Claude Code data (sessions, history, todos, etc.)
45-
"source=crucible-dev-claude,target=/home/vscode/.claude,type=volume"
45+
"source=crucible-dev-claude,target=/home/vscode/.claude,type=volume",
46+
// MSBuild files for local library development
47+
"source=${localWorkspaceFolder}/.devcontainer/msbuild/Directory.Build.props,target=/mnt/data/Directory.Build.props,type=bind",
48+
"source=${localWorkspaceFolder}/.devcontainer/msbuild/Directory.Build.targets,target=/mnt/data/Directory.Build.targets,type=bind"
4649
],
4750
"postCreateCommand": "bash -l .devcontainer/postcreate.sh",
4851
"postStartCommand": "bash -l .devcontainer/poststart.sh",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<PropertyGroup>
4+
<!-- Set to true to debug EntityEvents library locally -->
5+
<UseLocalEntityEvents>false</UseLocalEntityEvents>
6+
<!-- Detect if this is a library project (exclude from local source injection) -->
7+
<IsEntityEventsLibrary Condition="$(MSBuildProjectFullPath.Contains('crucible-common-dotnet'))">true</IsEntityEventsLibrary>
8+
</PropertyGroup>
9+
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<!-- When using local: add source files and generator (only if project references the package) -->
4+
<ItemGroup Condition="'$(UseLocalEntityEvents)' == 'true' AND '$(IsEntityEventsLibrary)' != 'true' AND '@(PackageReference->WithMetadataValue('Identity', 'Crucible.Common.EntityEvents'))' != ''">
5+
<Compile Include="/mnt/data/crucible/libraries/crucible-common-dotnet/src/Crucible.Common.EntityEvents/src/**/*.cs"
6+
Link="EntityEvents/%(RecursiveDir)%(Filename)%(Extension)" />
7+
<ProjectReference Include="/mnt/data/crucible/libraries/crucible-common-dotnet/src/Crucible.Common.EntityEvents.Generators/Crucible.Common.EntityEvents.Generators.csproj"
8+
OutputItemType="Analyzer" />
9+
</ItemGroup>
10+
11+
<!-- When using local: exclude contentFiles from the package -->
12+
<ItemGroup Condition="'$(UseLocalEntityEvents)' == 'true' AND '$(IsEntityEventsLibrary)' != 'true'">
13+
<PackageReference Update="Crucible.Common.EntityEvents" ExcludeAssets="contentFiles;build" />
14+
</ItemGroup>
15+
</Project>

Crucible.slnx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
<Project Path="/mnt/data/crucible/player/player.api/Player.Api/Player.Api.csproj" />
33
<Project Path="/mnt/data/crucible/player/vm.api/src/Player.Vm.Api/Player.Vm.Api.csproj" />
44
<Project Path="/mnt/data/crucible/caster/caster.api/src/Caster.Api/Caster.Api.csproj" />
5+
<Project Path="/mnt/data/crucible/libraries/crucible-common-dotnet/src/Crucible.Common.Authentication/Crucible.Common.Authentication.csproj" />
6+
<Project Path="/mnt/data/crucible/libraries/crucible-common-dotnet/src/Crucible.Common.EntityEvents.Generators/Crucible.Common.EntityEvents.Generators.csproj" />
7+
<Project Path="/mnt/data/crucible/libraries/crucible-common-dotnet/src/Crucible.Common.EntityEvents/Crucible.Common.EntityEvents.csproj" />
8+
<Project Path="/mnt/data/crucible/libraries/crucible-common-dotnet/src/Crucible.Common.Utilities/Crucible.Common.Utilities.csproj" />
59
<Project Path="/mnt/data/crucible/alloy/alloy.api/Alloy.Api/Alloy.Api.csproj" />
610
<Project Path="/mnt/data/crucible/topomojo/topomojo/src/TopoMojo.Api/TopoMojo.Api.csproj" />
711
<Project Path="Crucible.AppHost/Crucible.AppHost.csproj" />

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
Development Environment for Crucible
44

5-
# Getting Started
5+
## Getting Started
66

77
`crucible-development` is a [Development-Containers](https://containers.dev/)-based solution that uses .NET Aspire to orchestrate the various components of Crucible, along with supporting resources like an identity provider (Keycloak), a Postgres database server, and PGAdmin.
88

9-
## Setting up Docker
9+
### Setting up Docker
1010

1111
To use any dev container, you'll need to run Docker on your machine. [Docker Desktop](https://www.docker.com/) is a great way to get started if you're not confident administering Docker from the command line.
1212

13-
### Setting memory and storage limits
13+
#### Setting memory and storage limits
1414

1515
If you're on a Windows machine, Docker's consumption of your host machine's memory and storage is managed by [WSL2](https://learn.microsoft.com/en-us/windows/wsl/about). These will automatically scale to a percentage of your system's available resources, so you typically don't need to do any additional configuration.
1616

@@ -94,15 +94,15 @@ This repo is still under construction, so you may run into the occasional challe
9494

9595
- Some extensions (e.g. C#) very rarely seem to fail to install in the container's VS Code environment. If you see weird intellisense behavior or have compilation/debugging problems, ensure all extensions in the `devcontainers.json` file are installed in your container.
9696

97-
# Database seeding and backup
97+
## Database seeding and backup
9898

99-
## setup
99+
### Setup
100100

101101
... using blueprint as the example
102102
create a db-dumps folder under crucible-dev
103103
copy your blueprint.dump file into the db-dumps folder
104104

105-
## seed/restore a database
105+
### Seed/Restore a database
106106

107107
navigate to the db-dumps folder in the integrated terminal
108108
drop the blueprint database using pgadmin
@@ -113,7 +113,7 @@ docker exec -it crucible-postgres /bin/bash
113113
/usr/lib/postgresql/17/bin/psql --username=postgres blueprint < /tmp/blueprint.dump
114114
exit
115115

116-
## backup/dump a database
116+
### Backup/Dump a database
117117

118118
docker exec -it crucible-postgres /bin/bash
119119
pg_dump -U postgres blueprint > /tmp/blueprint.dump
@@ -193,3 +193,11 @@ Administration, Development, menu. The install process for this container instal
193193
`tool_userdebug` which allows site admins to easily toggle debug display via an icon added
194194
to the header just to the left of the user avatar in the upper right corner of the screen.
195195
This is the preferred method to enable display of debug messages inside of the browser.
196+
197+
## Library Development
198+
199+
The crucible-common-dotnet shared library is cloned into the `/mnt/data.crucible/libraries` directory. By default, APIs that use these libraries pull the published packages from NuGet. When developing or debugging these libraries, it is convenient to point the APIs to the local copy of the library. Developers can use the `scripts/toggle-local-library.sh` script to easily toggle between the default published NuGet packages and local Project References.
200+
201+
A Directory.Build.props file is mounted to `/mnt/data`. This file defines a variable `<UseLocalEntityEvents>false</UseLocalEntityEvents>`. If you want to use the local version of the Crucible.Common.EntityEvents library, copy this file to `/mnt/data/crucible` and set `<UseLocalEntityEvents>true</UseLocalEntityEvents>`. This will tell MSBuild to use a local project reference instead of the NuGet package and this file will not get checked into git. The script automates this process for you.
202+
203+
This pattern should be extended to the other libraries in crucible-common-dotnet as necessary in the future.

scripts/toggle-local-library.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Toggle local library debugging for EntityEvents dotnet library.
5+
# Usage: toggle-local-library.sh [on|off|status]
6+
# on - Enable local library debugging (Project Reference)
7+
# off - Disable local library debugging (NuGet)
8+
# status - Show current state
9+
# (no args) - Toggle current value
10+
11+
OVERRIDE_FILE="/mnt/data/crucible/Directory.Build.props"
12+
13+
get_current_value() {
14+
if [[ -f "$OVERRIDE_FILE" ]]; then
15+
echo "true"
16+
else
17+
echo "false"
18+
fi
19+
}
20+
21+
enable() {
22+
if [[ -f "$OVERRIDE_FILE" ]]; then
23+
echo "Local library debugging: already ON"
24+
return
25+
fi
26+
27+
# Create minimal override file that imports parent and overrides property
28+
cat > "$OVERRIDE_FILE" << 'EOF'
29+
<?xml version="1.0" encoding="utf-8"?>
30+
<Project>
31+
<!-- Import parent Directory.Build.props -->
32+
<Import Project="../Directory.Build.props" />
33+
34+
<PropertyGroup>
35+
<!-- Override to enable local library debugging -->
36+
<UseLocalEntityEvents>true</UseLocalEntityEvents>
37+
</PropertyGroup>
38+
</Project>
39+
EOF
40+
41+
echo "Local library debugging: ON"
42+
}
43+
44+
disable() {
45+
if [[ ! -f "$OVERRIDE_FILE" ]]; then
46+
echo "Local library debugging: already OFF"
47+
return
48+
fi
49+
50+
rm "$OVERRIDE_FILE"
51+
echo "Local library debugging: OFF"
52+
}
53+
54+
show_status() {
55+
local current=$(get_current_value)
56+
if [[ "$current" == "true" ]]; then
57+
echo "Local library debugging: ON (using local EntityEvents source)"
58+
echo "Override file: $OVERRIDE_FILE"
59+
else
60+
echo "Local library debugging: OFF (using NuGet packages)"
61+
echo "Override file: not created (using parent defaults)"
62+
fi
63+
}
64+
65+
case "${1:-}" in
66+
on)
67+
enable
68+
;;
69+
off)
70+
disable
71+
;;
72+
status)
73+
show_status
74+
;;
75+
"")
76+
# Toggle
77+
current=$(get_current_value)
78+
if [[ "$current" == "true" ]]; then
79+
disable
80+
else
81+
enable
82+
fi
83+
;;
84+
*)
85+
echo "Usage: $0 [on|off|status]"
86+
echo " on - Enable local library debugging"
87+
echo " off - Disable local library debugging"
88+
echo " status - Show current state"
89+
echo " (no args) - Toggle current value"
90+
exit 1
91+
;;
92+
esac

0 commit comments

Comments
 (0)