-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update implicit global usings feature #19599
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
Conversation
|
Can we get the schema files updated as part of this too please? |
Is it in this repo? |
|
@pranavkm ah I think you're right and that it's over at https://github.com/dotnet/msbuild/blob/main/src/MSBuild/MSBuild/Microsoft.Build.CommonTypes.xsd |
|
@pranavkm logged dotnet/msbuild#6745 to track the schema updates |
|
In this case cant all projects generate usings for There might be a few others as well that even my projects use commonly as well too (exposed in Elskom/Sdk#248). In which case I can change some of them to the new |
src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_BlazorWasm.cs
Show resolved
Hide resolved
| var existing = File.ReadAllText(outputFilePath); | ||
|
|
||
| if (string.Equals(existing, contentToWrite, StringComparison.Ordinal)) | ||
| { | ||
| Log.LogMessage(MessageImportance.Low, Strings.SkippingUnchangedFile, OutputFile.ItemSpec); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The WriteLinesToFile task has a WriteOnlyWhenDifferent which handles this. Rather than duplicate the logic here (and have to add an additional string), I think we should change it so that the GenerateGlobalUsings task outputs the generated file contents to a property, and then we use the WriteLinesToFile task to write it with WriteOnlyWhenDifferent set to true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that before on my failed PR and it would result in test failures, I also tried consuming that task directly in a task like this and it would pass when ran on it's own on the specific test assembly for this dll, but then fail on other tests or at least the same tests in CI vs when ran locally.
| if (@using.Static) | ||
| { | ||
| builder.Append("static "); | ||
| } | ||
|
|
||
| if (!string.IsNullOrEmpty(@using.Alias)) | ||
| { | ||
| builder.Append(@using.Alias) | ||
| .Append(" = "); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if a Using item has both Static and Alias metadata. This will generate C# code that won't compile, right? Should we error here in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we should error as global using static Foo = global::My.Namespace.Value isn't valid AFAIK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My plan was to let the compiler complain (it produces an error saying that you cannot alias a static using). It felt less complicated to do this in case a newer langversion started supporting this in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Letting the compiler generate the error seems less diagnosable to me. It will take you to the generated source file, but not indicate that the issue is with Import items.
I don't mind either way, it's just something to consider.
src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_DotNet.cs
Outdated
Show resolved
Hide resolved
src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_WebApp.cs
Outdated
Show resolved
Hide resolved
src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_WebApp.cs
Show resolved
Hide resolved
src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_Worker.cs
Outdated
Show resolved
Hide resolved
src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_Worker.cs
Show resolved
Hide resolved
src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_DotNet.cs
Outdated
Show resolved
Hide resolved
src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_WebApp.cs
Show resolved
Hide resolved
* Undo changes to VB projects * For C#, projects use the `Using` itemgroup to generate global usings. Support aliasing and static imports with attributes. * Use ImplicitUsings to determine if SDK-specific namespaces are imported by default.
e64e990 to
08db8d7
Compare
RussKie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
Thanks. |
Relates to dotnet/sdk#19521 Relates to dotnet/sdk#19599
Relates to dotnet/sdk#19521 Relates to dotnet/sdk#19599
Relates to dotnet/sdk#19521 Relates to dotnet/sdk#19599
Relates to dotnet/sdk#19521 Relates to dotnet/sdk#19599
Relates to dotnet/sdk#19521 Relates to dotnet/sdk#19599
| *********************************************************************************************** | ||
| --> | ||
| <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <ItemGroup Condition=" '$(DisableImplicitNamespaceImports)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETFramework'"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I please get a clarification why VB's implicit imports are now hidden behind DisableImplicitNamespaceImports, which is on by default? VB always had implicit imports on by default AFAIK.
This has broken dotnet/winforms#5437
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may be the culprit, which needs to be undone:

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this might have been missed. @pranavkm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the screen shot show "net6.0-windows" if this is a " .NET 5.0 VB app"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue that @RussKie is running in to is because of an Arcade change - dotnet/arcade#7745. That said, I missed undoing one of the VB changes that is covered as part of #19840



Usingitemgroup to generate global usings. Support aliasing and static imports with attributes.Contributes to #19521