Skip to content

Commit fbaa35f

Browse files
committed
move targets into individual .targets files
1 parent e26dfe8 commit fbaa35f

File tree

4 files changed

+136
-117
lines changed

4 files changed

+136
-117
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2021 smdn <smdn@smdn.jp>
3+
SPDX-License-Identifier: MIT
4+
-->
5+
<Project>
6+
<Target
7+
Name="GenerateMSBuildTargetsFile"
8+
DependsOnTargets="GenerateTaskFiles"
9+
>
10+
<ItemGroup>
11+
<TaskTargetFrameworks Include="$(TargetFrameworks.Split(';'))" />
12+
<TaskFiles
13+
Include="@(ExportTaskNames)"
14+
TargetFramework="%(TaskTargetFrameworks.Identity)"
15+
/>
16+
<TaskFiles
17+
ImportLine="&lt;Import Project=&quot;..\$(BuildOutputTargetFolder)\%(TargetFramework)\%(Identity).task&quot; /&gt;"
18+
/>
19+
</ItemGroup>
20+
21+
<PropertyGroup>
22+
<GenerateMSBuildTargetsFileOutputPath>$(OutputPath)\$(AssemblyName).targets</GenerateMSBuildTargetsFileOutputPath>
23+
<!-- TODO: MSBuildRuntimeType == Full, Mono and otherwise -->
24+
<GenerateMSBuildTargetsFileLines><![CDATA[
25+
<Project>
26+
<ImportGroup Condition=" '%24(MSBuildRuntimeType)' == 'Core' and %24([System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription.StartsWith('.NET Core 3.')) ">
27+
<!-- .NET Core 3.x -->
28+
@(TaskFiles->WithMetadataValue('TargetFramework', 'netcoreapp3.1')->'%(ImportLine)', '%0D%0A ')
29+
</ImportGroup>
30+
<ImportGroup Condition=" '%24(MSBuildRuntimeType)' == 'Core' and %24([System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription.StartsWith('.NET 5.')) ">
31+
<!-- .NET 5.x -->
32+
@(TaskFiles->WithMetadataValue('TargetFramework', 'net5.0')->'%(ImportLine)', '%0D%0A ')
33+
</ImportGroup>
34+
<ImportGroup Condition=" '%24(MSBuildRuntimeType)' == 'Core' and %24([System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription.StartsWith('.NET 6.')) ">
35+
<!-- .NET 6.x -->
36+
@(TaskFiles->WithMetadataValue('TargetFramework', 'net6.0')->'%(ImportLine)', '%0D%0A ')
37+
</ImportGroup>
38+
</Project>
39+
]]></GenerateMSBuildTargetsFileLines>
40+
</PropertyGroup>
41+
42+
<WriteLinesToFile
43+
File="$(GenerateMSBuildTargetsFileOutputPath)"
44+
Lines="$(GenerateMSBuildTargetsFileLines)"
45+
Overwrite="true"
46+
Encoding="UTF-8"
47+
/>
48+
49+
<ItemGroup>
50+
<None Pack="true" Include="$(GenerateMSBuildTargetsFileOutputPath)" PackagePath="buildMultitargeting" />
51+
</ItemGroup>
52+
</Target>
53+
</Project>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2021 smdn <smdn@smdn.jp>
3+
SPDX-License-Identifier: MIT
4+
-->
5+
<Project>
6+
<Target Name="GenerateTaskFiles" Condition=" '$(TargetFramework)' != '' ">
7+
<GenerateTaskFile
8+
TaskName="%(ExportTaskNames.Identity)"
9+
TaskNamespace="%(ExportTaskNames.Namespace)"
10+
TaskAssemblyFile="$(AssemblyName).dll"
11+
OutputDirectory="$(OutputPath)"
12+
>
13+
<Output PropertyName="GeneratedTaskFile" TaskParameter="GeneratedFile" />
14+
</GenerateTaskFile>
15+
16+
<ItemGroup>
17+
<TfmSpecificPackageFile Include="$(GeneratedTaskFile)" PackagePath="$(BuildOutputTargetFolder)\$(TargetFramework)" />
18+
</ItemGroup>
19+
</Target>
20+
21+
<UsingTask
22+
TaskName="GenerateTaskFile"
23+
TaskFactory="RoslynCodeTaskFactory"
24+
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"
25+
>
26+
<ParameterGroup>
27+
<TaskName ParameterType="System.String" Required="true" />
28+
<TaskNamespace ParameterType="System.String" />
29+
<TaskAssemblyFile ParameterType="System.String" Required="true" />
30+
<OutputDirectory ParameterType="System.String" Required="true" />
31+
<GeneratedFile ParameterType="System.String" Output="true" />
32+
</ParameterGroup>
33+
<Task>
34+
<Using Namespace="System" />
35+
<Using Namespace="System.IO" />
36+
<Code Type="Fragment" Language="cs"><![CDATA[
37+
const string PropertyMSBuildThisFileDirectory = "\x24(MSBuildThisFileDirectory)";
38+
var path = Path.Combine(OutputDirectory, $"{TaskName}.task");
39+
var taskFullName = string.IsNullOrEmpty(TaskNamespace)
40+
? TaskName
41+
: $"{TaskNamespace}.{TaskName}";
42+
var contents =
43+
@$"<Project>
44+
<UsingTask
45+
TaskName=""{taskFullName}""
46+
AssemblyFile=""{PropertyMSBuildThisFileDirectory}{TaskAssemblyFile}""
47+
/>
48+
</Project>
49+
";
50+
51+
File.WriteAllText(path, contents);
52+
53+
GeneratedFile = path;
54+
]]></Code>
55+
</Task>
56+
</UsingTask>
57+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2021 smdn <smdn@smdn.jp>
3+
SPDX-License-Identifier: MIT
4+
-->
5+
<Project>
6+
<!--
7+
alternative of nuget.exe's -IncludeReferencedProjects option
8+
https://github.com/NuGet/Home/issues/3891
9+
10+
other workarounds:
11+
https://github.com/NuGet/Home/issues/3891#issuecomment-569491001
12+
https://github.com/NuGet/Home/issues/3891#issuecomment-377319939
13+
-->
14+
<Target Name="PopulateDependingAssembliesToPackage">
15+
<ItemGroup>
16+
<TfmSpecificPackageFile
17+
Include="$(OutputPath)\*.dll"
18+
Exclude="$(OutputPath)\$(AssemblyName).dll"
19+
PackagePath="$(BuildOutputTargetFolder)\$(TargetFramework)\"
20+
/>
21+
</ItemGroup>
22+
</Target>
23+
</Project>

src/Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks/Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks.csproj

Lines changed: 3 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -51,121 +51,7 @@ SPDX-License-Identifier: MIT
5151
</ExportTaskNames>
5252
</ItemGroup>
5353

54-
<Target Name="GenerateTaskFiles" Condition=" '$(TargetFramework)' != '' ">
55-
<GenerateTaskFile
56-
TaskName="%(ExportTaskNames.Identity)"
57-
TaskNamespace="%(ExportTaskNames.Namespace)"
58-
TaskAssemblyFile="$(AssemblyName).dll"
59-
OutputDirectory="$(OutputPath)"
60-
>
61-
<Output PropertyName="GeneratedTaskFile" TaskParameter="GeneratedFile" />
62-
</GenerateTaskFile>
63-
64-
<ItemGroup>
65-
<TfmSpecificPackageFile Include="$(GeneratedTaskFile)" PackagePath="$(BuildOutputTargetFolder)\$(TargetFramework)" />
66-
</ItemGroup>
67-
</Target>
68-
69-
<UsingTask
70-
TaskName="GenerateTaskFile"
71-
TaskFactory="RoslynCodeTaskFactory"
72-
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"
73-
>
74-
<ParameterGroup>
75-
<TaskName ParameterType="System.String" Required="true" />
76-
<TaskNamespace ParameterType="System.String" />
77-
<TaskAssemblyFile ParameterType="System.String" Required="true" />
78-
<OutputDirectory ParameterType="System.String" Required="true" />
79-
<GeneratedFile ParameterType="System.String" Output="true" />
80-
</ParameterGroup>
81-
<Task>
82-
<Using Namespace="System" />
83-
<Using Namespace="System.IO" />
84-
<Code Type="Fragment" Language="cs"><![CDATA[
85-
const string PropertyMSBuildThisFileDirectory = "\x24(MSBuildThisFileDirectory)";
86-
var path = Path.Combine(OutputDirectory, $"{TaskName}.task");
87-
var taskFullName = string.IsNullOrEmpty(TaskNamespace)
88-
? TaskName
89-
: $"{TaskNamespace}.{TaskName}";
90-
var contents =
91-
@$"<Project>
92-
<UsingTask
93-
TaskName=""{taskFullName}""
94-
AssemblyFile=""{PropertyMSBuildThisFileDirectory}{TaskAssemblyFile}""
95-
/>
96-
</Project>
97-
";
98-
99-
File.WriteAllText(path, contents);
100-
101-
GeneratedFile = path;
102-
]]></Code>
103-
</Task>
104-
</UsingTask>
105-
106-
<!--
107-
alternative of nuget.exe's -IncludeReferencedProjects option
108-
https://github.com/NuGet/Home/issues/3891
109-
110-
other workarounds:
111-
https://github.com/NuGet/Home/issues/3891#issuecomment-569491001
112-
https://github.com/NuGet/Home/issues/3891#issuecomment-377319939
113-
-->
114-
<Target Name="PopulateDependingAssembliesToPackage">
115-
<ItemGroup>
116-
<TfmSpecificPackageFile
117-
Include="$(OutputPath)\*.dll"
118-
Exclude="$(OutputPath)\$(AssemblyName).dll"
119-
PackagePath="$(BuildOutputTargetFolder)\$(TargetFramework)\"
120-
/>
121-
</ItemGroup>
122-
</Target>
123-
124-
<Target
125-
Name="GenerateMSBuildTargetsFile"
126-
DependsOnTargets="GenerateTaskFiles"
127-
>
128-
<ItemGroup>
129-
<TaskTargetFrameworks Include="$(TargetFrameworks.Split(';'))" />
130-
<TaskFiles
131-
Include="@(ExportTaskNames)"
132-
TargetFramework="%(TaskTargetFrameworks.Identity)"
133-
/>
134-
<TaskFiles
135-
ImportLine="&lt;Import Project=&quot;..\$(BuildOutputTargetFolder)\%(TargetFramework)\%(Identity).task&quot; /&gt;"
136-
/>
137-
</ItemGroup>
138-
139-
<PropertyGroup>
140-
<GenerateMSBuildTargetsFileOutputPath>$(OutputPath)\$(AssemblyName).targets</GenerateMSBuildTargetsFileOutputPath>
141-
<!-- TODO: MSBuildRuntimeType == Full, Mono and otherwise -->
142-
<GenerateMSBuildTargetsFileLines><![CDATA[
143-
<Project>
144-
<ImportGroup Condition=" '%24(MSBuildRuntimeType)' == 'Core' and %24([System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription.StartsWith('.NET Core 3.')) ">
145-
<!-- .NET Core 3.x -->
146-
@(TaskFiles->WithMetadataValue('TargetFramework', 'netcoreapp3.1')->'%(ImportLine)', '%0D%0A ')
147-
</ImportGroup>
148-
<ImportGroup Condition=" '%24(MSBuildRuntimeType)' == 'Core' and %24([System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription.StartsWith('.NET 5.')) ">
149-
<!-- .NET 5.x -->
150-
@(TaskFiles->WithMetadataValue('TargetFramework', 'net5.0')->'%(ImportLine)', '%0D%0A ')
151-
</ImportGroup>
152-
<ImportGroup Condition=" '%24(MSBuildRuntimeType)' == 'Core' and %24([System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription.StartsWith('.NET 6.')) ">
153-
<!-- .NET 6.x -->
154-
@(TaskFiles->WithMetadataValue('TargetFramework', 'net6.0')->'%(ImportLine)', '%0D%0A ')
155-
</ImportGroup>
156-
</Project>
157-
]]></GenerateMSBuildTargetsFileLines>
158-
</PropertyGroup>
159-
160-
<WriteLinesToFile
161-
File="$(GenerateMSBuildTargetsFileOutputPath)"
162-
Lines="$(GenerateMSBuildTargetsFileLines)"
163-
Overwrite="true"
164-
Encoding="UTF-8"
165-
/>
166-
167-
<ItemGroup>
168-
<None Pack="true" Include="$(GenerateMSBuildTargetsFileOutputPath)" PackagePath="buildMultitargeting" />
169-
</ItemGroup>
170-
</Target>
54+
<Import Project="GenerateTaskFiles.targets" />
55+
<Import Project="GenerateMSBuildTargetsFile.targets" />
56+
<Import Project="PopulateDependingAssembliesToPackage.targets" />
17157
</Project>

0 commit comments

Comments
 (0)