-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add source package for file-based programs support #51373
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
base: release/10.0.2xx
Are you sure you want to change the base?
Add source package for file-based programs support #51373
Conversation
| } | ||
|
|
||
| // TODO: getting the following error, which is not suppressible with pragma. | ||
| // error SYSLIB1225: The type 'Encoding' includes the ref like property, field or constructor parameter 'Preamble'. No source code will be generated for the property, field or constructor. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1225) |
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.
It looks like it is complaining about System.Text.Encoding.Preamble. But AFAIK, I only changed where some of the types involved are declared, not what their members are.
I managed to "debug" this by commenting out some of the attributes and then members on various types.
It looks like this is ultimately coming through via:
[JsonSerializable(typeof(RunApiOutput))]toclass Project : RunApiOutputtoImmutableArray<SimpleDiagnostic> DiagnosticstoPosition SimpleDiagnostic.LocationtoSourceFile SimpleDiagnostic.SourceFiletoSourceText SourceFile.TexttoEncoding SourceText.Encoding
... and, it looks like the release/10.0.1xx branch version of SimpleDiagnostic does not have SourceFile on it. So, I think moving to that "version" of the declaration would probably make the generator error go away.
It looks like I copied the implementation from the wrong branch here. @jjonescz is release/10.0.1xx the correct branch to be using as a starting point for changes here? I assume we can't get this source package work into there as it is taking servicing fixes only. Is there some step we neglected to take in order to make sure the changes going into the release branch make their way into main?
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.
release/10.0.2xx should be open to normal changes and up to date. I'm using that one for run-file development now. main haven't received updates from release/10.0.1xx since September 20.
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.
This is the correct mindset for navigating the SDK repo 👍
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! I will plan on updating this based on release/10.0.2xx branch, and changing target to the same. Before I open for “full” review, I will try to set up the history so that the first commit is a pure move.
| internal static class AppDirectiveHelpers | ||
| { | ||
|
|
||
| #pragma warning disable RSEXPERIMENTAL003 // 'SyntaxTokenParser' is experimental |
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.
This suppression shouldn't be needed. I'm removing it in #51410
|
|
||
| namespace Microsoft.DotNet.FileBasedPrograms; | ||
|
|
||
| internal static class AppDirectiveHelpers |
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 the official term might be "file-level directives", not "app directives" as the latter seems too generic, although in the context of namespace "FileBasedPrograms" it's fine
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.
Yes I think changing term to match the spec will be best here. I can make the same change on the editor features side. https://github.com/dotnet/sdk/blob/main/documentation/general/dotnet-run-file.md#directives-for-project-metadata
| namespace Microsoft.DotNet.FileBasedPrograms; | ||
|
|
||
| /// <summary> | ||
| /// When targeting netstandard2.0, the user of the source package must "implement" certain methods by declaring members in this type. |
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.
Missing </summary> closing tag
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'm not sure why copying this file is needed. Does adding <Compile> to the package project not work? I see you are saying "It seems like a .cs file which is "out of tree" doesn't make it into the package." but I've recently created a source package where all the files come from a different directory and it works fine:
Although I wasn't using shproj and projitems, perhaps that's the problem?
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.
In my case I tried adding a Compile item to the .projitems. I'll take a look at the build for the source project you linked and try to work out what the difference is.
| { | ||
| } | ||
|
|
||
| public GracefulException(string? message, string? todo2) : base(message) |
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 todo2 parameter is unused. Can we just remove this overload?
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.
This overload is being called in the implementation. Perhaps when compiling against the proper version, the GracefulException(string, params string[]) overload is used. But I think it would be necessary to do more work to get rid of the usages, in order to delete this overload.
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 the work to drop usage of this type in the source package might be worthwhile, I am just trying to push it out until after I can get the end-to-end working. I would also be interested in your thoughts on that.
| } | ||
|
|
||
| #if FILE_BASED_PROGRAMS_SOURCE_PACKAGE_GRACEFUL_EXCEPTION | ||
| internal class GracefulException : Exception |
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.
Can we remove all the exception throwing? We already report diagnostics, right?
The calling code can convert diagnostics to an exception if needed.
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 it will be best to remove usage of this type from the source package. But, it will involve a decent chunk of refactoring.
| // Also normalize blackslashes to forward slashes to ensure the directive works on all platforms. | ||
| var sourceDirectory = Path.GetDirectoryName(context.SourceFile.Path) ?? "."; | ||
| var resolvedProjectPath = Path.Combine(sourceDirectory, directiveText.Replace('\\', '/')); | ||
| if (Directory.Exists(resolvedProjectPath)) |
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.
Seems like this may depend on the process current directory. Should we abstract that? Depending on process state makes it hard to test and reuse the code in different environments
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.
Are you suggesting adding some way to pass in a base directory for resolution here? Perhaps using the compilation’s SourceReferenceResolver if it exists?
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.
Perhaps pass additional defaultDirectory parameter or something similar.
17b3342 to
28adee2
Compare
|
When attempting to use the package in Roslyn, I get the following exception in the analyzer. It looks like the
|
|
I am unsure whether it is better to include the outputs of compiling the I didn't see any examples of a source-only package which includes resource files. Do we have any examples of that in our org? Tagging @tmat @baronfel in case you happen to know (or know where to look.) |
Resources in source packages are PITA. Is it possible to avoid? |
|
The resources are basically the error messages for bad This is the content that would be copied (and possibly translations performed again, unless, perhaps with comments we give the translators a heads up that there is another copy elsewhere to use as a reference.) sdk/src/Cli/Microsoft.DotNet.FileBasedPrograms/FileBasedProgramsResources.resx Lines 120 to 171 in 839754f
|
This package will be used to support dotnet/roslyn#80575.
Some things I haven't figured out yet:
GracefulException probably won't work in the source package.Failing to include MSBuildUtilities.cs in the source package. SeeIt seems like a .cs file which is "out of tree" doesn't make it into the package. I'm unsure if that is expected. @tmat may have some suggestion for how to address this part.Microsoft.DotNet.FileBasedPrograms.projitems.@jjonescz would be interested to know any thoughts you have on the above bullets or the TODOs in source.