-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add global usings for .NET projects (.NET SDK, Web and Worker) (#18459)
- Loading branch information
John Luo
authored
Jul 8, 2021
1 parent
aaa6580
commit 8594395
Showing
29 changed files
with
686 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../Microsoft.NET.Build.Tasks/targets/Microsoft.NET.GenerateImplicitNamespaceImports.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.