Skip to content

Commit e6b43a2

Browse files
authored
Fix building All Samples, added launch config generation.
1 parent a5f1922 commit e6b43a2

File tree

3 files changed

+108
-33
lines changed

3 files changed

+108
-33
lines changed

.vscode/launch.json

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
2-
// Use IntelliSense to find out which attributes exist for C# debugging
3-
// Use hover for the description of the existing attributes
4-
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
52
"version": "0.2.0",
63
"configurations": [
74
{
8-
"name": "All samples",
5+
"name": "All samples app",
96
"type": "coreclr",
107
"request": "launch",
118
"program": "dotnet",
@@ -19,28 +16,27 @@
1916
"/p:UnoRemoteControlPort=443",
2017
"--project=${workspaceFolder}/platforms/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj",
2118
"-p:TargetFrameworks=netstandard2.0",
22-
"-p:TargetFramework=net5.0",
19+
"-p:TargetFramework=net5.0"
2320
],
21+
"presentation": {
22+
"group": "1",
23+
"order": 1
24+
},
2425
"cwd": "${workspaceFolder}/platforms/CommunityToolkit.Labs.Wasm",
26+
"preLaunchTask": "generateAllSolution"
2527
},
2628
{
27-
"name": "CanvasLayout",
28-
"type": "coreclr",
29+
"type": "PowerShell",
2930
"request": "launch",
30-
"program": "dotnet",
31+
"name": "Discover samples",
32+
"script": "DiscoverSamples.ps1",
3133
"args": [
32-
"run",
33-
"build",
34-
"/r",
35-
"/bl",
36-
"/p:UnoSourceGeneratorUseGenerationHost=true",
37-
"/p:UnoSourceGeneratorUseGenerationController=false",
38-
"/p:UnoRemoteControlPort=443",
39-
"--project=${workspaceFolder}/labs/CanvasLayout/samples/CanvasLayout.Wasm/CanvasLayout.Wasm.csproj",
40-
"-p:TargetFrameworks=netstandard2.0",
41-
"-p:TargetFramework=net5.0",
34+
""
4235
],
43-
"cwd": "${workspaceFolder}/labs/CanvasLayout/samples/CanvasLayout.Wasm",
36+
"presentation": {
37+
"group": "2",
38+
"order": 2
39+
}
4440
}
4541
]
46-
}
42+
}

.vscode/tasks.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "generateAllSolution",
8+
"type": "shell",
9+
"command": "pwsh ./GenerateAllSolution.ps1",
10+
"group": "build"
11+
}
12+
]
13+
}

DiscoverSamples.ps1

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,107 @@
1+
Param (
2+
[Parameter(HelpMessage = "Disables suppressing changes to the ./.vscode/launch.json file in git, allowing changes to be committed.")]
3+
[switch]$allowGitChanges = $false
4+
)
5+
16
$templatedSampleProjectReferencesDefinitionMarker = "[TemplatedSampleProjectReferences]"
27
$sampleRefsPropsTemplatePath = 'common/Labs.SampleRefs.props.template';
38
$generatedSampleRefsPropsPath = 'common/Labs.SampleRefs.props';
49

10+
function CreateVsCodeLaunchConfigJson {
11+
param (
12+
[string]$projectName
13+
)
14+
15+
return "{
16+
`"name`": `"$projectName`",
17+
`"type`": `"coreclr`",
18+
`"request`": `"launch`",
19+
`"program`": `"dotnet`",
20+
`"args`": [
21+
`"run`",
22+
`"build`",
23+
`"/r`",
24+
`"/bl`",
25+
`"/p:UnoSourceGeneratorUseGenerationHost=true`",
26+
`"/p:UnoSourceGeneratorUseGenerationController=false`",
27+
`"/p:UnoRemoteControlPort=443`",
28+
`"--project=${workspaceFolder}/labs/$projectName/samples/$projectName.Wasm/$projectName.Wasm.csproj`",
29+
`"-p:TargetFrameworks=netstandard2.0`",
30+
`"-p:TargetFramework=net5.0`",
31+
],
32+
`"presentation`": {
33+
`"group`": `"2`",
34+
},
35+
`"cwd`": `"${workspaceFolder}/labs/$projectName/samples/$projectName.Wasm`",
36+
}";
37+
}
38+
539
# Execute ProjectReference generation for all heads
640
$sampleRefsPropsTemplate = Get-Content -Path $sampleRefsPropsTemplatePath;
741
Write-Output "Loaded sample ProjectReference template from $sampleRefsPropsTemplatePath";
842

943
# Add sample projects
1044
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/samples/*.Sample/*.Sample.csproj') {
11-
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
12-
$relativePath = $relativePath.TrimStart('.\');
13-
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);
45+
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
46+
$relativePath = $relativePath.TrimStart('.\');
47+
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);
1448

15-
Write-Host "Adding $projectName to project references";
49+
Write-Host "Adding $projectName to project references";
1650

17-
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
51+
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
1852

19-
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
53+
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
2054
" + $projectReferenceDefinition);
2155
}
2256

2357
# Add library projects
2458
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/src/*.csproj') {
25-
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
26-
$relativePath = $relativePath.TrimStart('.\');
27-
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);
59+
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
60+
$relativePath = $relativePath.TrimStart('.\');
61+
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);
2862

29-
Write-Host "Adding $projectName to project references";
63+
Write-Host "Adding $projectName to project references";
3064

31-
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
65+
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
3266

33-
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
67+
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
3468
" + $projectReferenceDefinition);
3569
}
3670

3771
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), "";
3872

3973
# Save
4074
Set-Content -Path $generatedSampleRefsPropsPath -Value $sampleRefsPropsTemplate;
41-
Write-Output "Sample project references generated at $generatedSampleRefsPropsPath";
75+
Write-Output "Sample project references generated at $generatedSampleRefsPropsPath";
76+
77+
$launchConfigJson = Get-Content -Path "./.vscode/launch.json";
78+
$launchConfig = $launchConfigJson | ConvertFrom-Json;
79+
80+
# Remove all non-generated configurations
81+
$originalConfigurations = $launchConfig.configurations;
82+
$launchConfig.configurations = @();
83+
$launchConfig.configurations += $originalConfigurations[0];
84+
$launchConfig.configurations += $originalConfigurations[1];
85+
86+
foreach ($wasmProjectPath in Get-ChildItem -Recurse -Path 'labs/*/samples/*.Wasm/*.Wasm.csproj') {
87+
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($wasmProjectPath) -Replace ".Wasm", "";
88+
Write-Host "Generating VSCode launch config for $projectName";
89+
90+
$configJson = CreateVsCodeLaunchConfigJson $projectName;
91+
$config = $configJson | ConvertFrom-Json;
92+
93+
$launchConfig.configurations += $config;
94+
}
95+
96+
if ($allowGitChanges.IsPresent) {
97+
Write-Warning "Changes to the default launch.json in Labs can now be committed. Run this command again without the -allowGitChanges flag to disable committing further changes.";
98+
git update-index --no-assume-unchanged ./.vscode/launch.json
99+
}
100+
else {
101+
Write-Output "Changes to the default launch.json in Labs are now suppressed. To switch branches, run git reset --hard with a clean working tree. Include the -allowGitChanges flag to enable committing changes.";
102+
git update-index --assume-unchanged ./.vscode/launch.json
103+
}
104+
105+
# Save
106+
Set-Content -Path "./.vscode/launch.json" -Value ($launchConfig | ConvertTo-Json -Depth 9);
107+
Write-Output "Saved VSCode launch configs to ./.vscode/launch.json";

0 commit comments

Comments
 (0)