-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Microsoft.NET.GenerateImplicitNamespaceImports.targets
57 lines (48 loc) · 2.92 KB
/
Microsoft.NET.GenerateImplicitNamespaceImports.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!--
***********************************************************************************************
Microsoft.NET.GenerateImplicitNamespaceImports.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
============================================================
GenerateImplicitNamespaceImports
Generates implicit namespace imports source to intermediate directory for C# projects
============================================================
-->
<PropertyGroup>
<GeneratedImplicitNamespaceImportFile Condition="'$(GeneratedImplicitNamespaceImportFile)' ==''">$(IntermediateOutputPath)$(MSBuildProjectName).ImplicitNamespaceImports$(DefaultLanguageSourceExtension)</GeneratedImplicitNamespaceImportFile>
<DisableImplicitNamespaceImports_DotNet Condition="'$(DisableImplicitNamespaceImports_DotNet)' == '' and '$(DisableImplicitNamespaceImports)' != 'true'">false</DisableImplicitNamespaceImports_DotNet>
</PropertyGroup>
<!--
Note that this must run before every invocation of CoreCompile to ensure that all compiler
runs see the generated assembly info. There is at least one scenario involving Xaml
where CoreCompile is invoked without other potential hooks such as Compile or CoreBuild,
etc., so we hook directly on to CoreCompile. Furthermore, we must run *after*
PrepareForBuild to ensure that the intermediate directory has been created.
Targets that generate Compile items are also expected to run before
BeforeCompile targets (common targets convention).
-->
<Target Name="GenerateImplicitNamespaceImports"
BeforeTargets="BeforeCompile;CoreCompile"
DependsOnTargets="PrepareForBuild;CoreGenerateImplicitNamespaceImports"
Condition="'$(DisableImplicitNamespaceImports)' != 'true'" />
<Target Name="CoreGenerateImplicitNamespaceImports"
Outputs="$(GeneratedImplicitNamespaceImportFile)"
Condition="'@(Import)' != ''">
<ItemGroup>
<_UniqueImport Include="@(Import->Distinct())" />
<_ImportFileLine Include="// %3Cautogenerated />"/>
<_ImportFileLine Include="global using global::%(_UniqueImport.Identity)%3B"/>
</ItemGroup>
<WriteLinesToFile Lines="@(_ImportFileLine)" File="$(GeneratedImplicitNamespaceImportFile)" Overwrite="true" WriteOnlyWhenDifferent="true" />
<ItemGroup>
<Compile Include="$(GeneratedImplicitNamespaceImportFile)" />
<FileWrites Include="$(GeneratedImplicitNamespaceImportFile)" />
</ItemGroup>
</Target>
</Project>