Skip to content

Conversation

@jjonescz
Copy link
Member

@jjonescz jjonescz commented Jan 7, 2026

Resolves #48174.
Fixes #50912.

@jjonescz jjonescz marked this pull request as ready for review January 8, 2026 17:59
@jjonescz jjonescz requested a review from a team as a code owner January 8, 2026 17:59
VirtualProjectBuilder.WriteProjectFile(
csprojWriter,
directives,
evaluatedDirectives,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed the run-api doesn't evaluate directives, so I've fixed that, and added tests for it.

<value>Unrecognized directive '{0}'.</value>
<comment>{0} is the directive name like 'package' or 'sdk'.</comment>
</data>
<data name="EmptyTempPath" xml:space="preserve">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used in the package, so moved out.


public readonly struct ParseInfo
{
public required SourceFile SourceFile { get; init; }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to know source file that directives come from to evaluate relative paths in #:include/#:exclude directives, so moved this from ParseContext to ParseInfo.

}

internal delegate void ErrorReporter(SourceFile sourceFile, TextSpan textSpan, string message);
internal delegate void ErrorReporter(SourceFile sourceFile, TextSpan textSpan, string message, Exception? innerException = null);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inner exception used to be passed but got lost in this refactoring: #51995, so I've restored it.

}

public static void RemoveDirectivesFromFile(ImmutableArray<CSharpDirective> directives, SourceText text, string filePath)
public static void RemoveDirectivesFromFile(ImmutableArray<CSharpDirective> directives, SourceFile sourceFile, string targetFilePath)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function did not used to save the file if not modified - I don't think that was intentional but it worked thanks to the project convert command copying all Compile items anyway. It all works differently (better) now.


private static void Convert(string inputCSharp, out string actualProject, out string? actualCSharp, bool force, string? filePath,
bool collectDiagnostics, out ImmutableArray<SimpleDiagnostic>.Builder? actualDiagnostics)
private static void Convert(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unified the helpers here.

@jjonescz jjonescz requested a review from a team January 8, 2026 17:59
(".cs", "Compile"),
(".resx", "EmbeddedResource"),
(".json", "Content"),
(".razor", "Content"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interested in thoughts RE other default file types to support here. I think definitely *.cshtml to go along with *.razor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could easily add extensibility for this. Someone (user/sdk/etc) could define a property like <FileBasedProgramsItemMapping>.protobuf=Protobuf;.cshtml=Content</>). We have access to a ProjectInstance when resolving these, so it should be simple to implement:

// NOTE: In the future, instead of using only hard-coded item types here,
// we could read some user/sdk-defined MSBuild property from `project` for additional mapping.
includeOrExcludeDirective = includeOrExcludeDirective.WithDeterminedItemType(reportError);

Just needs some design I guess.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my intent was that this would be extensible, and be called something like "implicit item types". Not required to ship first version of support IMO but if we have time then great. If you think it's easy enough to do though happy for us to aim on implementing it that way and moving the declarations into the respective SDKs/packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-run-file Items related to the "dotnet run <file>" effort

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants