|
14 | 14 | <StartupFile Condition="'$(StartupFile)' == ''">$(S)</StartupFile> |
15 | 15 | <StartupFile Condition="'$(StartupFile)' == ''">$(ActiveDebugProfile)</StartupFile> |
16 | 16 | <FindStartupFile Condition="'$(StartupFile)' == '' or !Exists('$(StartupFile)')">true</FindStartupFile> |
17 | | - <StartupFileDependsOn>EnsureProperties;CollectStartupFile;SelectStartupFile;SelectTopLevelCompile;UpdateLaunchSettings;EmitTargets</StartupFileDependsOn> |
| 17 | + <StartupFileDependsOn>EnsureProperties;CollectStartupFile;ResolveStartupFile;SelectStartupFile;SelectTopLevelCompile;UpdateLaunchSettings;EmitTargets</StartupFileDependsOn> |
18 | 18 |
|
19 | 19 | <!-- For CLI dotnet run, users must set ImportProjectExtensionProps/ImportProjectExtensionTargets=true --> |
20 | 20 | <SmallSharpPackagesProps>$(MSBuildProjectExtensionsPath)$(MSBuildProjectFile).smallsharp.props</SmallSharpPackagesProps> |
|
25 | 25 | <!-- Ensures all top-level files show up in the IDE --> |
26 | 26 | <None Include="*.cs" Exclude="$(ActiveDebugProfile);$(ActiveFile)" /> |
27 | 27 | <Compile Remove="*.cs" /> |
| 28 | + |
28 | 29 | <!-- Ensure changes we make to this file trigger a new DTB --> |
29 | 30 | <UpToDateCheckBuilt Include="Properties\launchSettings.json" /> |
30 | 31 | <UpToDateCheckBuilt Include="$(SmallSharpPackagesProps);$(SmallSharpPackagesTargets)" /> |
31 | 32 | <Compile Update="@(Compile -> WithMetadataValue('NuGetPackageId', 'SmallSharp'))" Visible="false" /> |
| 33 | + |
| 34 | + <!-- Include linked compile files too --> |
| 35 | + <_LinkedCompile Include="@(Compile -> HasMetadata('Link'))" /> |
| 36 | + <_NuGetLinked Include="@(_LinkedCompile -> HasMetadata('NuGetPackageId'))" /> |
| 37 | + <_NoNuGetLinked Include="@(_LinkedCompile)" Exclude="@(_NuGetLinked)" /> |
| 38 | + <LinkedCompile Include="@(_NoNuGetLinked -> WithoutMetadataValue('Visible', 'false'))" /> |
| 39 | + <Compile Remove="@(LinkedCompile -> WithoutMetadataValue('Link', '$(ActiveDebugProfile)'))" /> |
| 40 | + <None Include="@(LinkedCompile -> WithoutMetadataValue('Link', '$(ActiveFile)'))" /> |
32 | 41 | </ItemGroup> |
33 | 42 |
|
34 | 43 | <!-- When restoring, if we include the source files, we'd get duplicate references. --> |
|
51 | 60 | <Target Name="CollectStartupFile"> |
52 | 61 | <ItemGroup> |
53 | 62 | <StartupFile Include="*.cs" /> |
| 63 | + <StartupFile Include="@(LinkedCompile)" /> |
| 64 | + </ItemGroup> |
| 65 | + </Target> |
| 66 | + |
| 67 | + <Target Name="ResolveStartupFile" Condition="'$(FindStartupFile)' == 'true'"> |
| 68 | + <ItemGroup> |
| 69 | + <!-- Find if the specified StartupFile is a filename that matches an available StartupFile item --> |
| 70 | + <_MatchingStartupFile Include="@(StartupFile)" Condition="'$(StartupFile)' != '' and '%(Filename)%(Extension)' == '$(StartupFile)'" /> |
54 | 71 | </ItemGroup> |
| 72 | + <PropertyGroup Condition="'@(_MatchingStartupFile)' != ''"> |
| 73 | + <StartupFile>@(_MatchingStartupFile -> '%(Identity)')</StartupFile> |
| 74 | + <FindStartupFile>false</FindStartupFile> |
| 75 | + </PropertyGroup> |
55 | 76 | </Target> |
56 | 77 |
|
57 | 78 | <!-- Defaults the startup file to the first Compile, if none previously selected. --> |
|
146 | 167 | <!-- We remove all top-level from Compile because copy/pasting startup files may end up |
147 | 168 | causing those items to be hardcoded in the .csproj --> |
148 | 169 | <Compile Remove="@(Compile -> WithMetadataValue('RelativeDir', ''))" /> |
| 170 | + <!-- Remove linked compile files too --> |
| 171 | + <Compile Remove="@(Compile -> HasMetadata('Link'))" /> |
149 | 172 | <Compile Include="$(StartupFile)" Condition="'$(StartupFile)' != '' and Exists('$(StartupFile)')" /> |
150 | 173 | <UpToDateCheckInput Include="$(StartupFile)" Condition="'$(StartupFile)' != '' and Exists('$(StartupFile)')" /> |
151 | 174 | </ItemGroup> |
|
202 | 225 | </Task> |
203 | 226 | </UsingTask> |
204 | 227 |
|
| 228 | + <UsingTask TaskName="DumpItems" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 229 | + <ParameterGroup> |
| 230 | + <Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> |
| 231 | + <ItemName /> |
| 232 | + </ParameterGroup> |
| 233 | + <Task> |
| 234 | + <Using Namespace="Microsoft.Build.Framework" /> |
| 235 | + <Using Namespace="Microsoft.Build.Utilities" /> |
| 236 | + <Using Namespace="System" /> |
| 237 | + <Using Namespace="System.Linq" /> |
| 238 | + <Code Type="Fragment" Language="cs"> |
| 239 | + <![CDATA[ |
| 240 | + var itemName = ItemName ?? "Item"; |
| 241 | + if (Items.Length == 0) |
| 242 | + Log.LogMessage(MessageImportance.High, "No {0} items received to dump.", ItemName ?? ""); |
| 243 | + else |
| 244 | + Log.LogMessage(MessageImportance.High, "Dumping {0} {1} items.", Items.Length, ItemName ?? ""); |
| 245 | +
|
| 246 | + foreach (var item in Items.OrderBy(i => i.ItemSpec)) |
| 247 | + { |
| 248 | + Log.LogMessage(MessageImportance.High, "{0}: {1}", itemName, item.ItemSpec); |
| 249 | + foreach (var name in item.MetadataNames.OfType<string>().OrderBy(_ => _)) |
| 250 | + { |
| 251 | + try |
| 252 | + { |
| 253 | + Log.LogMessage(MessageImportance.High, "\t{0}={1}", name, item.GetMetadata(name)); |
| 254 | + } |
| 255 | + catch { } |
| 256 | + } |
| 257 | + } |
| 258 | + ]]> |
| 259 | + </Code> |
| 260 | + </Task> |
| 261 | + </UsingTask> |
| 262 | + |
205 | 263 | </Project> |
0 commit comments