Skip to content

Commit a5f1922

Browse files
authored
Split sample project reference building into DiscoverSamples.ps1
1 parent b60c3aa commit a5f1922

File tree

2 files changed

+43
-41
lines changed

2 files changed

+43
-41
lines changed

DiscoverSamples.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
$templatedSampleProjectReferencesDefinitionMarker = "[TemplatedSampleProjectReferences]"
2+
$sampleRefsPropsTemplatePath = 'common/Labs.SampleRefs.props.template';
3+
$generatedSampleRefsPropsPath = 'common/Labs.SampleRefs.props';
4+
5+
# Execute ProjectReference generation for all heads
6+
$sampleRefsPropsTemplate = Get-Content -Path $sampleRefsPropsTemplatePath;
7+
Write-Output "Loaded sample ProjectReference template from $sampleRefsPropsTemplatePath";
8+
9+
# Add sample projects
10+
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);
14+
15+
Write-Host "Adding $projectName to project references";
16+
17+
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
18+
19+
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
20+
" + $projectReferenceDefinition);
21+
}
22+
23+
# Add library projects
24+
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);
28+
29+
Write-Host "Adding $projectName to project references";
30+
31+
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
32+
33+
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
34+
" + $projectReferenceDefinition);
35+
}
36+
37+
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), "";
38+
39+
# Save
40+
Set-Content -Path $generatedSampleRefsPropsPath -Value $sampleRefsPropsTemplate;
41+
Write-Output "Sample project references generated at $generatedSampleRefsPropsPath";

GenerateAllSolution.ps1

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ $templatedProjectDefinitionsMarker = "[TemplatedProjectDefinitions]";
1919
$templatedSharedTestProjectSelfDefinitionsMarker = "[TemplatedSharedTestProjectDefinitions]";
2020
$templatedSharedTestUwpProjectSelfDefinitionsMarker = "[TemplatedSharedTestUwpProjectDefinitions]";
2121
$templatedSharedTestWinAppSdkProjectSelfDefinitionsMarker = "[TemplatedSharedTestWinAppSdkProjectDefinitions]";
22-
$templatedSampleProjectReferencesDefinitionMarker = "[TemplatedSampleProjectReferences]"
2322

2423
$sampleProjectTypeGuid = "9A19103F-16F7-4668-BE54-9A1E7A4F7556";
2524
$sharedProjectTypeGuid = "D954291E-2A0B-460D-934E-DC6B0785DB48";
@@ -28,9 +27,6 @@ $libProjectTypeGuid = $sampleProjectTypeGuid;
2827
$solutionTemplatePath = 'common/Toolkit.Labs.All.sln.template';
2928
$generatedSolutionFilePath = 'Toolkit.Labs.All.sln'
3029

31-
$sampleRefsPropsTemplatePath = 'common/Labs.SampleRefs.props.template';
32-
$generatedSampleRefsPropsPath = 'common/Labs.SampleRefs.props';
33-
3430
function CreateProjectConfiguration {
3531
param (
3632
[string]$projectGuid
@@ -248,40 +244,5 @@ $solutionTemplate = $solutionTemplate -replace "(?m)^\s*`r`n", "";
248244
Set-Content -Path $generatedSolutionFilePath -Value $solutionTemplate;
249245
Write-Output "Solution generated at $generatedSolutionFilePath";
250246

251-
# Execute ProjectReference generation for all heads
252-
$sampleRefsPropsTemplate = Get-Content -Path $sampleRefsPropsTemplatePath;
253-
Write-Output "Loaded sample ProjectReference template from $sampleRefsPropsTemplatePath";
254-
255-
# Add sample projects
256-
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/samples/*.Sample/*.Sample.csproj') {
257-
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
258-
$relativePath = $relativePath.TrimStart('.\');
259-
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);
260-
261-
Write-Host "Adding $projectName to project references";
262-
263-
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
264-
265-
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
266-
" + $projectReferenceDefinition);
267-
}
268-
269-
# Add library projects
270-
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/src/*.csproj') {
271-
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
272-
$relativePath = $relativePath.TrimStart('.\');
273-
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);
274-
275-
Write-Host "Adding $projectName to project references";
276-
277-
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
278-
279-
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
280-
" + $projectReferenceDefinition);
281-
}
282-
283-
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), "";
284-
285-
# Save
286-
Set-Content -Path $generatedSampleRefsPropsPath -Value $sampleRefsPropsTemplate;
287-
Write-Output "Sample project references generated at $generatedSampleRefsPropsPath";
247+
# Run sample discovery
248+
& ./DiscoverSamples.ps1

0 commit comments

Comments
 (0)