Skip to content

Commit 3d243b2

Browse files
committed
Make sure file names are sorted alphabetically
For the launchSettings.
1 parent e3fbbb5 commit 3d243b2

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/SmallSharp/SmallSharp.targets

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,33 @@
146146
<WriteLinesToFile File="$(MSBuildProjectDirectory)\Properties\launchSettings.json"
147147
Lines="{ }"
148148
Condition="!Exists('$(MSBuildProjectDirectory)\Properties\launchSettings.json')" />
149+
<SortItems Items="@(StartupFile)">
150+
<Output TaskParameter="SortedItems" ItemName="SortedStartupFile" />
151+
</SortItems>
149152
<JsonPoke ContentPath="$(MSBuildProjectDirectory)\Properties\launchSettings.json"
150-
Query="$.profiles['%(StartupFile.Filename)%(StartupFile.Extension)'].commandName"
151-
Value="Project" />
153+
Query="$.profiles['%(SortedStartupFile.Filename)%(SortedStartupFile.Extension)'].commandName"
154+
Value="Project" />
152155
</Target>
153156

154157
<ItemGroup>
155158
<!-- Ensure changes we make to this file trigger a new DTB -->
156159
<UpToDateCheckBuilt Include="Properties\launchSettings.json" />
157160
</ItemGroup>
158161

162+
<UsingTask TaskName="SortItems" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
163+
<ParameterGroup>
164+
<!-- ITaskItem[] input and sorted output -->
165+
<Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
166+
<SortedItems ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" />
167+
</ParameterGroup>
168+
<Task>
169+
<Using Namespace="System" />
170+
<Code Type="Fragment" Language="cs">
171+
<![CDATA[
172+
SortedItems = Items.OrderBy(i => i.ItemSpec).ToArray();
173+
]]>
174+
</Code>
175+
</Task>
176+
</UsingTask>
177+
159178
</Project>

0 commit comments

Comments
 (0)