Skip to content

Commit f2a455a

Browse files
authored
Improve UnitsNet.Modular samples (#1722)
## Summary - reduce the UnitsNet.Modular sample portfolio to six purpose-focused scenarios with concise names - replace `ConsumerOwned` with a documented, solution-grouped `SharedUnitsLibrarySample` - let every sample switch between `ProjectReferences`, `LocalPackages`, and `PublishedPackages` through the IDE solution-platform selector - move the runnable compatibility pair into test fixtures and update documentation, CI, VS Code, and devcontainer paths ## Motivation The previous samples mixed dependency sources into separate projects, used long or ambiguous names, and contained overlapping scenarios. This made it difficult to tell why each sample existed or to compare the same sample against source, locally packed, and published dependencies. The new solution platforms keep `Debug` and `Release` as build configurations while treating the dependency source as the IDE-selectable platform. Local package preparation runs once at solution level to avoid parallel pack races. ## Impact In Rider or Visual Studio, contributors can select combinations such as `Debug | LocalPackages` for the complete sample portfolio. Direct sample builds continue to default to project references. Outputs and restore state are isolated by dependency platform. ## Validation - `dotnet build UnitsNet.Modular.slnx --configuration Release -p:Platform=ProjectReferences` - `dotnet build UnitsNet.Modular.slnx --configuration Release -p:Platform=LocalPackages` - `dotnet build UnitsNet.Modular.slnx --configuration Release -p:Platform=PublishedPackages` - `dotnet test UnitsNet.Modular.slnx --configuration Release -p:Platform=ProjectReferences` — 116 tests passed - local-package custom and shared-units samples executed successfully - published-package getting-started sample executed successfully - `git diff --check`
1 parent c8aa7c1 commit f2a455a

75 files changed

Lines changed: 511 additions & 513 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer/unitsnet-modular/devcontainer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
22
"name": "UnitsNet.Modular playground",
33
"image": "mcr.microsoft.com/devcontainers/dotnet:10.0-noble",
4-
"postCreateCommand": "dotnet build UnitsNet.Modular/Samples/UnitsNet.Modular.Playground/UnitsNet.Modular.Playground.csproj",
4+
"postCreateCommand": "dotnet build UnitsNet.Modular/Samples/ModularPlayground/ModularPlayground.csproj -p:Platform=ProjectReferences",
55
"customizations": {
66
"vscode": {
77
"extensions": [
88
"ms-dotnettools.csdevkit"
99
],
1010
"settings": {
11-
"dotnet.defaultSolution": "UnitsNet.Modular/Samples/UnitsNet.Modular.Playground/UnitsNet.Modular.Playground.slnx",
11+
"dotnet.defaultSolution": "UnitsNet.Modular/Samples/ModularPlayground/ModularPlayground.slnx",
1212
"csharp.debug.console": "integratedTerminal",
13-
"terminal.integrated.cwd": "${workspaceFolder}/UnitsNet.Modular/Samples/UnitsNet.Modular.Playground"
13+
"terminal.integrated.cwd": "${workspaceFolder}/UnitsNet.Modular/Samples/ModularPlayground"
1414
}
1515
},
1616
"codespaces": {
1717
"openFiles": [
18-
"UnitsNet.Modular/Samples/UnitsNet.Modular.Playground/README.md",
19-
"UnitsNet.Modular/Samples/UnitsNet.Modular.Playground/Program.cs",
20-
"UnitsNet.Modular/Samples/UnitsNet.Modular.Playground/ApplicationUnits.cs",
21-
"UnitsNet.Modular/Samples/UnitsNet.Modular.Playground/GameScore.unitsnet.json",
22-
"UnitsNet.Modular/Samples/UnitsNet.Modular.Playground/Properties/launchSettings.json",
23-
"UnitsNet.Modular/Samples/UnitsNet.Modular.Playground/UnitsNet.Modular.Playground.csproj"
18+
"UnitsNet.Modular/Samples/ModularPlayground/README.md",
19+
"UnitsNet.Modular/Samples/ModularPlayground/Program.cs",
20+
"UnitsNet.Modular/Samples/ModularPlayground/ApplicationUnits.cs",
21+
"UnitsNet.Modular/Samples/ModularPlayground/ParcelCount.unitsnet.json",
22+
"UnitsNet.Modular/Samples/ModularPlayground/Properties/launchSettings.json",
23+
"UnitsNet.Modular/Samples/ModularPlayground/ModularPlayground.csproj"
2424
]
2525
}
2626
}

.github/workflows/unitsnet-modular-ci.yml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,44 @@ jobs:
7878
dotnet-version: 10.0.x
7979

8080
- name: Restore
81-
run: dotnet restore UnitsNet.Modular.slnx -p:UnitsNetModularSampleUpdateLocalPackagesOnBuild=true
81+
run: dotnet restore UnitsNet.Modular.slnx -p:Platform=ProjectReferences
8282

8383
- name: Build
84-
run: dotnet build UnitsNet.Modular.slnx --configuration Release --no-restore --no-incremental -p:UnitsNetModularSampleUpdateLocalPackagesOnBuild=true
84+
run: dotnet build UnitsNet.Modular.slnx --configuration Release --no-restore --no-incremental -p:Platform=ProjectReferences
8585

8686
- name: Test
87-
run: dotnet test UnitsNet.Modular.slnx --configuration Release --no-build -p:UnitsNetModularSampleUpdateLocalPackagesOnBuild=false
87+
run: dotnet test UnitsNet.Modular.slnx --configuration Release --no-build -p:Platform=ProjectReferences
8888

8989
- name: Native AOT smoke test
9090
run: |
91-
dotnet publish UnitsNet.Modular/Samples/UnitsNet.Modular.Lean.Sample/UnitsNet.Modular.Lean.Sample.csproj \
91+
dotnet publish UnitsNet.Modular/Samples/QuantitySelectionSample/QuantitySelectionSample.csproj \
9292
--configuration Release \
9393
--framework net10.0 \
9494
--runtime linux-x64 \
9595
--self-contained true \
9696
-p:PublishAot=true \
97-
-p:UnitsNetModularSampleUpdateLocalPackagesOnBuild=false \
97+
-p:Platform=ProjectReferences \
9898
--output Artifacts/UnitsNet.Modular.AotSmoke
99-
./Artifacts/UnitsNet.Modular.AotSmoke/UnitsNet.Modular.Lean.Sample
99+
./Artifacts/UnitsNet.Modular.AotSmoke/QuantitySelectionSample
100100
101101
- name: Run getting-started NuGet consumer
102102
shell: pwsh
103-
run: ./UnitsNet.Modular/Samples/UnitsNet.Modular.GettingStarted.Sample/run.ps1
104-
105-
- name: Run custom-definition NuGet consumer
106-
shell: pwsh
107-
run: ./UnitsNet.Modular/Samples/UnitsNet.Modular.NuGet.Sample/run.ps1
103+
run: ./UnitsNet.Modular/Samples/GettingStartedSample/run.ps1
104+
105+
- name: Run custom-definition NuGet consumer with isolated cache
106+
run: >-
107+
dotnet run
108+
--project UnitsNet.Modular/Samples/CustomQuantitySample/CustomQuantitySample.csproj
109+
--configuration Debug
110+
-p:Platform=LocalPackages
111+
-p:RestorePackagesPath=${{ runner.temp }}/unitsnet-modular-custom-packages-${{ github.run_id }}-${{ github.run_attempt }}
112+
113+
- name: Run published-package consumer
114+
run: >-
115+
dotnet run
116+
--project UnitsNet.Modular/Samples/GettingStartedSample/GettingStartedSample.csproj
117+
--configuration Release
118+
-p:Platform=PublishedPackages
108119
109120
- name: Pack
110121
run: dotnet pack UnitsNet.Modular/UnitsNet.Modular/UnitsNet.Modular.csproj --configuration Release --no-build --output Artifacts/UnitsNet.Modular.CI -p:UnitsNetModularPackForPublish=true

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "C#: UnitsNet.Modular.Playground",
5+
"name": "C#: ModularPlayground",
66
"type": "dotnet",
77
"request": "launch",
8-
"projectPath": "${workspaceFolder}/UnitsNet.Modular/Samples/UnitsNet.Modular.Playground/UnitsNet.Modular.Playground.csproj"
8+
"projectPath": "${workspaceFolder}/UnitsNet.Modular/Samples/ModularPlayground/ModularPlayground.csproj"
99
}
1010
]
1111
}

Directory.Build.props

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,4 @@
3131
<IncludeSymbols>true</IncludeSymbols>
3232
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
3333
</PropertyGroup>
34-
35-
<ItemGroup>
36-
<Compile Include="$(MSBuildThisFileDirectory)/NullableAttributes.cs" />
37-
</ItemGroup>
38-
3934
</Project>

Directory.Build.targets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!-- Licensed under MIT No Attribution, see LICENSE file at the root. -->
2+
<Project>
3+
<!-- Nullable flow-analysis attributes are built in on modern .NET targets. -->
4+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFrameworkIdentifier)' == '.NETFramework'">
5+
<Compile Include="$(MSBuildThisFileDirectory)NullableAttributes.cs" />
6+
</ItemGroup>
7+
</Project>

Directory.Solution.targets

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!-- Licensed under MIT No Attribution, see LICENSE file at the root. -->
2+
<Project>
3+
<!--
4+
This root-level file is imported by both repository solutions. The target is intentionally
5+
inert for the main UnitsNet solution, which does not define the LocalPackages platform.
6+
7+
A solution restore evaluates package-facing samples in parallel. Bootstrap the shared local
8+
feed once so their per-project restore hooks observe completed package stamps instead of
9+
launching concurrent dotnet pack processes.
10+
-->
11+
<Target Name="PrepareUnitsNetModularLocalPackagesForSolution"
12+
BeforeTargets="_GenerateRestoreGraph;Restore"
13+
Condition="'$(Platform)' == 'LocalPackages'">
14+
<Message Importance="high" Text="Preparing the repository-local UnitsNet.Modular packages..." />
15+
<MSBuild
16+
Projects="$(MSBuildThisFileDirectory)UnitsNet.Modular/Samples/SharedUnitsLibrarySample/SharedUnitsLibrarySample.Units/SharedUnitsLibrarySample.Units.csproj"
17+
Targets="_PackLocalUnitsNetModularPackages"
18+
BuildInParallel="false"
19+
Properties="Configuration=$(Configuration);Platform=LocalPackages;UnitsNetModularSampleUpdateLocalPackagesOnBuild=true" />
20+
</Target>
21+
</Project>

UnitsNet.Modular.slnx

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,81 @@
11
<Solution>
2+
<Configurations>
3+
<Platform Name="ProjectReferences" />
4+
<Platform Name="LocalPackages" />
5+
<Platform Name="PublishedPackages" />
6+
</Configurations>
7+
<!-- Core and test projects remain AnyCPU; only samples map dependency-mode platforms. -->
28
<Project Path="UnitsNet.Modular/UnitsNet.Modular/UnitsNet.Modular.csproj" />
39
<Project Path="UnitsNet.Modular/UnitsNet.Modular.Generator/UnitsNet.Modular.Generator.csproj" />
410
<Project Path="UnitsNet.Modular/UnitsNet.Modular.Generator.Tests/UnitsNet.Modular.Generator.Tests.csproj" />
511
<Project Path="UnitsNet.Modular/UnitsNet.Modular.Tests/UnitsNet.Modular.Tests.csproj" />
12+
<Folder Name="/_Files/">
13+
<File Path="UnitsNet.Modular/ARCHITECTURE.md" />
14+
<File Path="UnitsNet.Modular/Directory.Build.props" />
15+
<File Path="UnitsNet.Modular/Directory.Build.targets" />
16+
<File Path="UnitsNet.Modular/Directory.Packages.props" />
17+
<File Path="UnitsNet.Modular/MIGRATION.md" />
18+
<File Path="UnitsNet.Modular/README.md" />
19+
<File Path="UnitsNet.Modular/THIRD-PARTY-NOTICES.md" />
20+
<File Path="UnitsNet.Modular/UnitsNet.Modular.Versioning.props" />
21+
</Folder>
622
<Project Path="UnitsNet.Modular/UnitsNet.Modular.Compatibility.Tests/UnitsNet.Modular.Compatibility.Tests.csproj" />
723
<Folder Name="/Samples/">
8-
<Project Path="UnitsNet.Modular/Samples/DefinitionPackages/Fictional.Measurements.Definitions/Fictional.Measurements.Definitions.csproj" />
9-
<Project Path="UnitsNet.Modular/Samples/ConsumerOwned/ConsumerOwned.Units/ConsumerOwned.Units.csproj" />
10-
<Project Path="UnitsNet.Modular/Samples/ConsumerOwned/ConsumerOwned.Units.ProjectReferences/ConsumerOwned.Units.ProjectReferences.csproj" />
11-
<Project Path="UnitsNet.Modular/Samples/ConsumerOwned/ConsumerOwned.Domain/ConsumerOwned.Domain.csproj" />
12-
<Project Path="UnitsNet.Modular/Samples/ConsumerOwned/ConsumerOwned.Reporting/ConsumerOwned.Reporting.csproj" />
13-
<Project Path="UnitsNet.Modular/Samples/UnitsNet.Modular.AllSi.Sample/UnitsNet.Modular.AllSi.Sample.csproj" />
14-
<Project Path="UnitsNet.Modular/Samples/UnitsNet.Modular.Representative.Sample/UnitsNet.Modular.Representative.Sample.csproj" />
15-
<Project Path="UnitsNet.Modular/Samples/UnitsNet.Modular.Lean.Sample/UnitsNet.Modular.Lean.Sample.csproj" />
16-
<Project Path="UnitsNet.Modular/Samples/UnitsNet.Modular.Custom.Sample/UnitsNet.Modular.Custom.Sample.csproj" />
17-
<Project Path="UnitsNet.Modular/Samples/UnitsNet.Modular.Compatibility.UnitsNet.Sample/UnitsNet.Modular.Compatibility.UnitsNet.Sample.csproj" />
18-
<Project Path="UnitsNet.Modular/Samples/UnitsNet.Modular.Compatibility.Generated.Sample/UnitsNet.Modular.Compatibility.Generated.Sample.csproj" />
24+
<File Path="UnitsNet.Modular/Samples/README.md" />
25+
<Project Path="UnitsNet.Modular/Samples/GettingStartedSample/GettingStartedSample.csproj">
26+
<Platform Solution="*|ProjectReferences" Project="ProjectReferences" />
27+
<Platform Solution="*|LocalPackages" Project="LocalPackages" />
28+
<Platform Solution="*|PublishedPackages" Project="PublishedPackages" />
29+
</Project>
30+
<Project Path="UnitsNet.Modular/Samples/QuantitySelectionSample/QuantitySelectionSample.csproj">
31+
<Platform Solution="*|ProjectReferences" Project="ProjectReferences" />
32+
<Platform Solution="*|LocalPackages" Project="LocalPackages" />
33+
<Platform Solution="*|PublishedPackages" Project="PublishedPackages" />
34+
</Project>
35+
<Project Path="UnitsNet.Modular/Samples/CustomQuantitySample/CustomQuantitySample.csproj">
36+
<Platform Solution="*|ProjectReferences" Project="ProjectReferences" />
37+
<Platform Solution="*|LocalPackages" Project="LocalPackages" />
38+
<Platform Solution="*|PublishedPackages" Project="PublishedPackages" />
39+
</Project>
40+
<Project Path="UnitsNet.Modular/Samples/ModularPlayground/ModularPlayground.csproj">
41+
<Platform Solution="*|ProjectReferences" Project="ProjectReferences" />
42+
<Platform Solution="*|LocalPackages" Project="LocalPackages" />
43+
<Platform Solution="*|PublishedPackages" Project="PublishedPackages" />
44+
</Project>
45+
</Folder>
46+
<Folder Name="/Samples/Profiles/">
47+
<Project Path="UnitsNet.Modular/Samples/Profiles/AllSiProfileSample/AllSiProfileSample.csproj">
48+
<Platform Solution="*|ProjectReferences" Project="ProjectReferences" />
49+
<Platform Solution="*|LocalPackages" Project="LocalPackages" />
50+
<Platform Solution="*|PublishedPackages" Project="PublishedPackages" />
51+
</Project>
52+
</Folder>
53+
<Folder Name="/Samples/Shared Units Library/">
54+
<Project Path="UnitsNet.Modular/Samples/SharedUnitsLibrarySample/SharedUnitsLibrarySample.Units/SharedUnitsLibrarySample.Units.csproj">
55+
<Platform Solution="*|ProjectReferences" Project="ProjectReferences" />
56+
<Platform Solution="*|LocalPackages" Project="LocalPackages" />
57+
<Platform Solution="*|PublishedPackages" Project="PublishedPackages" />
58+
</Project>
59+
<Project Path="UnitsNet.Modular/Samples/SharedUnitsLibrarySample/SharedUnitsLibrarySample.Domain/SharedUnitsLibrarySample.Domain.csproj">
60+
<Platform Solution="*|ProjectReferences" Project="ProjectReferences" />
61+
<Platform Solution="*|LocalPackages" Project="LocalPackages" />
62+
<Platform Solution="*|PublishedPackages" Project="PublishedPackages" />
63+
</Project>
64+
<Project Path="UnitsNet.Modular/Samples/SharedUnitsLibrarySample/SharedUnitsLibrarySample.App/SharedUnitsLibrarySample.App.csproj">
65+
<Platform Solution="*|ProjectReferences" Project="ProjectReferences" />
66+
<Platform Solution="*|LocalPackages" Project="LocalPackages" />
67+
<Platform Solution="*|PublishedPackages" Project="PublishedPackages" />
68+
</Project>
69+
<Project Path="UnitsNet.Modular/Samples/SharedUnitsLibrarySample/Fictional.Measurements.Definitions/Fictional.Measurements.Definitions.csproj">
70+
<Platform Solution="*|ProjectReferences" Project="ProjectReferences" />
71+
<Platform Solution="*|LocalPackages" Project="LocalPackages" />
72+
<Platform Solution="*|PublishedPackages" Project="PublishedPackages" />
73+
</Project>
74+
<File Path="UnitsNet.Modular/Samples/SharedUnitsLibrarySample/README.md" />
75+
</Folder>
76+
<Folder Name="/Tests/" />
77+
<Folder Name="/Tests/Compatibility fixtures/">
78+
<Project Path="UnitsNet.Modular/UnitsNet.Modular.Compatibility.Tests/Fixtures/Generated/UnitsNet.Modular.Compatibility.GeneratedFixture.csproj" />
79+
<Project Path="UnitsNet.Modular/UnitsNet.Modular.Compatibility.Tests/Fixtures/Legacy/UnitsNet.Modular.Compatibility.LegacyFixture.csproj" />
1980
</Folder>
2081
</Solution>

0 commit comments

Comments
 (0)