-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add global usings for .NET projects (.NET SDK, Web and Worker) #18459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
647a8fb
Add global usings for WebSdk projects
8275dad
add global::
fe5b195
Include global using as compile item group
61a436d
Update
0b1ed10
Add Ifdef
fc63e92
Update src/WebSdk/ProjectSystem/Targets/Microsoft.NET.Sdk.Web.Project…
84ab2ca
Refactor <App>.GlobalUsings.cs generation to M.NET.Sdk
7710bc2
Fix spacing
d7f073b
Feedback
7158dce
Add global usings for workers
3fe53fe
Remove preview condition and remove M.A.Mvc
b906bbc
Renames based on recommendations
924611a
Fix typo and make top level option controll enabling of entire feature
705bc3e
Update namespaces added by .NET SDK
dd5b588
Renames to align with VB
1cae46f
More renaming for consistency
0669c8e
Unblock test writing
9efe496
Try rebasing
1bf8274
Update conditions
0785147
Add unit tests
274b8ab
Add license headers
2ad8321
Add test for duplicated namespaces
eb47f12
Move imports to props
26aad08
Update list of usings
466b134
Remove preview requirements
c1330c5
Update conditions
0c015bb
Refactor tests and fix blazor wasm
b1bcd7a
Fix build tests
10b123a
Restrict LangVersion
0373165
Update
4cb205d
Fix type conflict
01b1571
Explicitly set LangVersion in tests
2ecfe2b
Limit subset of tests to core msbuild only
fa0418e
Test changes
c8880ad
Remove LangVersion checks
e14b34f
Require MSBuild > 17.0.0.32901 for subset of build/publish tests
302f5f5
Fix build
34e37e1
More full framework MSBuild version requirements
ebd9260
Last batch of MSBuild version requirements
c35715c
Fix typo in attribute
3d94c7d
Skip wpf template test
de65e92
Fix merge conflict with main
f7940de
Rebase fixes
a6b38f0
Merge branch 'main' into johluo/global-usings
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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"/> | ||
JunTaoLuo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</ItemGroup> | ||
|
||
<WriteLinesToFile Lines="@(_ImportFileLine)" File="$(GeneratedImplicitNamespaceImportFile)" Overwrite="true" WriteOnlyWhenDifferent="true" /> | ||
|
||
<ItemGroup> | ||
<Compile Include="$(GeneratedImplicitNamespaceImportFile)" /> | ||
<FileWrites Include="$(GeneratedImplicitNamespaceImportFile)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
</Project> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.